Boost test code

// clientcontrol.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"

#include <fstream>
#include <iostream>

#include <boost/filesystem.hpp>
#include <boost/program_options.hpp>
#define BOOST_LOG_DONOT_USE_WCHAR_T
#include <boost/logging/format_fwd.hpp>
#include <boost/logging/format.hpp>

using namespace std;

using namespace boost::logging;
namespace po = boost::program_options;
using namespace boost::filesystem;


BOOST_LOG_FORMAT_MSG( optimize::cache_string_one_str<> )

typedef logger_format_write< > log_type;

// Step 4: declare which filters and loggers you'll use (usually in a header file)
BOOST_DECLARE_LOG_FILTER(g_log_filter, filter::no_ts ) 
BOOST_DECLARE_LOG(g_l, log_type) 

#define L_ BOOST_LOG_USE_LOG_IF_FILTER(g_l(), g_log_filter()->is_enabled() ) 

BOOST_DEFINE_LOG_FILTER(g_log_filter, filter::no_ts ) 
BOOST_DEFINE_LOG(g_l, log_type) 


int _tmain(int argc, _TCHAR* argv[])
{
	int opt;

	g_l()->writer().add_formatter( formatter::idx(), "[%] " );
	g_l()->writer().add_formatter( formatter::append_newline() );
	g_l()->writer().add_destination( destination::cout() );
	g_l()->writer().add_destination( destination::dbg_window() );
	g_l()->writer().add_destination( destination::file("server.log"));
	//g_l()->writer().add_destination( dest_out );
	g_l()->mark_as_initialized();

	L_ << "test" << 12;

	// Declare a group of options that will be 
	// allowed only on command line
	po::options_description generic("Generic options");
	generic.add_options()
		("version,v", "print version string")
		("help", "produce help message")    
		;

	// Declare a group of options that will be 
	// allowed both on command line and in
	// config file
	po::options_description config("Configuration");
	config.add_options()
		("optimization", po::value<int>(&opt)->default_value(10), 
		"optimization level")
		("include-path,I", 
		po::value< vector<string> >()->composing(), 
		"include path")
		;

	// Hidden options, will be allowed both on command line and
	// in config file, but will not be shown to the user.
	po::options_description hidden("Hidden options");
	hidden.add_options()
		("input-file", po::value< vector<string> >(), "input file")
		;      

	po::options_description cmdline_options;
	cmdline_options.add(generic).add(config).add(hidden);

	po::options_description config_file_options;
	config_file_options.add(config).add(hidden);

	po::options_description visible("Allowed options");
	visible.add(generic).add(config);

	po::variables_map vm;
	po::store(po::parse_command_line(argc, argv, cmdline_options), vm);
	ifstream ifs("test.cfg");
	po::store(po::parse_config_file(ifs, config_file_options), vm);
	po::notify(vm);   

	if (vm.count("help")) {
		cout << cmdline_options << "\n";
		return 1;
	}

	if (vm.count("optimization")) {
		cout << "optimization level was set to " 
			<< vm["optimization"].as<int>() << ".\n";
	} 
	
	
	if (vm.count("include-path")) {
		cout << "include-path level was set to " 
			<< vm["include-path"].as< vector<string> >()[0] << ".\n";
		cout << "include-path level was set to " 
			<< vm["include-path"].as< vector<string> >()[1] << ".\n";
	} 

	create_directories("test/okla/zzc");
	copy_file("c:\\windows\\system32\\drivers\\etc\\hosts", "test/okla/zzc/hosts");
	//copy_file("c:\\windows\\system32\\drivers\\etc\\", "test/okla/zzc/");
	

	/*
	// Declare the supported options.
	po::options_description desc("Allowed options");
	desc.add_options()
		("help", "produce help message")
		("compression", po::value<int>(), "set compression level")
		;

	po::variables_map vm;
	po::store(po::parse_command_line(argc, argv, desc), vm);
	po::notify(vm);    

	if (vm.count("help")) {
		cout << desc << "\n";
		return 1;
	}

	if (vm.count("compression")) {
		cout << "Compression level was set to " 
			<< vm["compression"].as<int>() << ".\n";
	} else {
		cout << "Compression level was not set.\n";
	}
	*/
	return 0;
}

你可能感兴趣的:(C++,c,windows,cache,C#)