当前位置: 首页>>代码示例>>C++>>正文


C++ variables_map::begin方法代码示例

本文整理汇总了C++中boost::program_options::variables_map::begin方法的典型用法代码示例。如果您正苦于以下问题:C++ variables_map::begin方法的具体用法?C++ variables_map::begin怎么用?C++ variables_map::begin使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在boost::program_options::variables_map的用法示例。


在下文中一共展示了variables_map::begin方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: commandLineError

void
gtBaseOpts::checkForIllegalOverrides (bpo::variables_map& res_vm,
                                      bpo::variables_map& final_vm)
{
   // Check if there are any variables in restrictedConfig that:
   // 1. Are in the final map (they all should be) -and-
   // 2. Have different values in the two maps
   // These values were overridden from the settings in the restricted
   // config file, which is not allowed

   for (bpo::variables_map::iterator it = res_vm.begin(); it != res_vm.end(); ++it)
   {
      vectOfStr restValues = gtBaseOpts::vmValueToStrings (it->second);

      // Get variable values from final var map
      bpo::variable_value finalVv = final_vm[it->first];
      vectOfStr finalValues = gtBaseOpts::vmValueToStrings (finalVv);

      // We don't care about order of vector elements
      std::sort(restValues.begin(), restValues.end());
      std::sort(finalValues.begin(), finalValues.end());

      if (restValues != finalValues)
         commandLineError ("Configuration file or CLI options may not"
                           " override the options present in "
                           + m_sys_restrict_cfg_file + ".  Please check "
                           "your settings for the program option \""
                           + it->first + "\".  You specified \""
                           + finalValues[0] + "\" " + "but the restricted "
                           "configuration value is \"" + restValues[0] + "\".");
   }
}
开发者ID:hammer,项目名称:genetorrent,代码行数:32,代码来源:gtBaseOpts.cpp

示例2: PrintVariableMap

void PrintVariableMap(po::variables_map vm) 
{
    cout << "#############################################################" << endl;
    cout << "Parameters Using Default Values: " << endl;
    cout << "-------------------------------------------------------------" << endl;
    for (po::variables_map::iterator it = vm.begin(); it != vm.end(); ++it) 
        if (vm[it->first].defaulted() || it->second.defaulted()) 
        {
            int isString, isInt, isDouble;
            cout << std::right << std::setw(15) << it->first << "  =  " << setw(30) << std::left;
            try { cout << vm[it->first].as<string>() << " (string)" << std::endl; } 
            catch (const boost::bad_any_cast &) { isString = false; }

            try { cout << vm[it->first].as<int>() << " (int)" << std::endl; } 
            catch (const boost::bad_any_cast &) { isInt = false; }

            try { cout << vm[it->first].as<double>() << " (double)" << std::endl; } 
            catch (const boost::bad_any_cast &) { isDouble = false; }
        }

    cout << "-------------------------------------------------------------" << endl;
    cout << "User Defined Parameters: " << endl;
    cout << "-------------------------------------------------------------" << endl;
    for (po::variables_map::iterator it = vm.begin(); it != vm.end(); ++it) 
        if (! vm[it->first].defaulted() && ! it->second.defaulted() ) 
        {
            int isString, isInt, isDouble;
            cout << std::right << setw(15) << it->first << "  =  " << setw(30) << std::left;
            try { cout << vm[it->first].as<string>() << " (string)" << std::endl; } 
            catch (const boost::bad_any_cast &) { isString = false; }

            try { cout << vm[it->first].as<int>() << " (int)" << std::endl; } 
            catch (const boost::bad_any_cast &) { isInt = false; }

            try { cout << vm[it->first].as<double>() << " (double)" << std::endl; } 
            catch (const boost::bad_any_cast &) { isDouble = false; }
        }

    cout << "#############################################################" << endl;
    cout << endl;
}
开发者ID:longing3000,项目名称:oops,代码行数:41,代码来源:print_program_options.cpp

示例3: serializeOptions

std::string serializeOptions(const po::variables_map &vm) 
{
    std::string s;

    for (po::variables_map::const_iterator it = vm.begin(); it != vm.end(); ++it) {
        if (it->second.value().type() == typeid(bool))
            s += it->first + '=' + boost::lexical_cast<std::string>(boost::any_cast<bool>(it->second.value()));
        else if (it->second.value().type() == typeid(unsigned))
            s += it->first + '=' + boost::lexical_cast<std::string>(boost::any_cast<unsigned>(it->second.value()));
        else if (it->second.value().type() == typeid(float))
            s += it->first + '=' + boost::lexical_cast<std::string>(boost::any_cast<float>(it->second.value()));
        else if (it->second.value().type() == typeid(double))
            s += it->first + '=' + boost::lexical_cast<std::string>(boost::any_cast<double>(it->second.value()));
        else if (it->second.value().type() == typeid(std::string))
            s += it->first + '=' + boost::any_cast<std::string>(it->second.value());

        s += ";;;";
    }

    return s;
}
开发者ID:ZhilunX,项目名称:lstm-rnn,代码行数:21,代码来源:Configuration.cpp

示例4: options_print

void options_print(boost::program_options::variables_map &vm) {
   /** Populate this map with actions that will correctly
    * print each type of program option */
   map<const type_info*,
       boost::function<void(const po::variable_value&)>,
       type_info_compare> action_map;
   action_map[&typeid(string)] = output_value<string>();
   action_map[&typeid(int)] = output_value<int>();
   action_map[&typeid(bool)] = output_value<bool>();
   action_map[&typeid(float)] = output_value<float>();

   po::variables_map::iterator it;
   cout << endl;
   for (it = vm.begin(); it != vm.end(); ++it) {
      // cout << setw(20) << left << it->first << ": ";
      const po::variable_value& v = it->second;
      if (!v.empty()) {
         cout << setw(20) << left << it->first << ": ";
         action_map[&v.value().type()](v);
      }
   }
}
开发者ID:FionaCLin,项目名称:rUNSWift-2015-release,代码行数:22,代码来源:options.cpp

示例5: store


//.........这里部分代码省略.........
                // error message printed in setUpPrivateKey
                ::_exit(EXIT_BADOPTIONS);
            }

            cmdLine.keyFile = true;
            noauth = false;
        }
        else {
            cmdLine.keyFile = false;
        }

#ifdef MONGO_SSL
        if (params.count("sslOnNormalPorts") ) {
            cmdLine.sslOnNormalPorts = true;

            if ( cmdLine.sslPEMKeyPassword.size() == 0 ) {
                log() << "need sslPEMKeyPassword" << endl;
                ::_exit(EXIT_BADOPTIONS);
            }
            
            if ( cmdLine.sslPEMKeyFile.size() == 0 ) {
                log() << "need sslPEMKeyFile" << endl;
                ::_exit(EXIT_BADOPTIONS);
            }
            
            cmdLine.sslServerManager = new SSLManager( false );
            if ( ! cmdLine.sslServerManager->setupPEM( cmdLine.sslPEMKeyFile , cmdLine.sslPEMKeyPassword ) ) {
                ::_exit(EXIT_BADOPTIONS);
            }
        }
        else if ( cmdLine.sslPEMKeyFile.size() || cmdLine.sslPEMKeyPassword.size() ) {
            log() << "need to enable sslOnNormalPorts" << endl;
            ::_exit(EXIT_BADOPTIONS);
        }
#endif
        
        {
            BSONObjBuilder b;
            for (po::variables_map::const_iterator it(params.begin()), end(params.end()); it != end; it++){
                if (!it->second.defaulted()){
                    const string& key = it->first;
                    const po::variable_value& value = it->second;
                    const type_info& type = value.value().type();

                    if (type == typeid(string)){
                        if (value.as<string>().empty())
                            b.appendBool(key, true); // boost po uses empty string for flags like --quiet
                        else {
                            if ( key == "servicePassword" || key == "sslPEMKeyPassword" ) {
                                b.append( key, "<password>" );
                            }
                            else {
                                b.append( key, value.as<string>() );
                            }
                        }
                    }
                    else if (type == typeid(int))
                        b.append(key, value.as<int>());
                    else if (type == typeid(double))
                        b.append(key, value.as<double>());
                    else if (type == typeid(bool))
                        b.appendBool(key, value.as<bool>());
                    else if (type == typeid(long))
                        b.appendNumber(key, (long long)value.as<long>());
                    else if (type == typeid(unsigned))
                        b.appendNumber(key, (long long)value.as<unsigned>());
                    else if (type == typeid(unsigned long long))
                        b.appendNumber(key, (long long)value.as<unsigned long long>());
                    else if (type == typeid(vector<string>))
                        b.append(key, value.as<vector<string> >());
                    else
                        b.append(key, "UNKNOWN TYPE: " + demangleName(type));
                }
            }
            parsedOpts = b.obj();
        }

        {
            BSONArrayBuilder b;
            for (int i=0; i < argc; i++) {
                b << argv[i];
                if ( mongoutils::str::equals(argv[i], "--sslPEMKeyPassword")
                     || mongoutils::str::equals(argv[i], "-sslPEMKeyPassword")
                     || mongoutils::str::equals(argv[i], "--servicePassword")
                     || mongoutils::str::equals(argv[i], "-servicePassword")) {
                    b << "<password>";
                    i++;

                    // hide password from ps output
                    char* arg = argv[i];
                    while (*arg) {
                        *arg++ = 'x';
                    }
                }
            }
            argvArray = b.arr();
        }

        return true;
    }
开发者ID:nosqldb,项目名称:mongo,代码行数:101,代码来源:cmdline.cpp

示例6: store

    bool CmdLine::store( const std::vector<std::string>& argv,
                         boost::program_options::options_description& visible,
                         boost::program_options::options_description& hidden,
                         boost::program_options::positional_options_description& positional,
                         boost::program_options::variables_map &params ) {


        if (argv.empty())
            return false;

        {
            // setup binary name
            cmdLine.binaryName = argv[0];
            size_t i = cmdLine.binaryName.rfind( '/' );
            if ( i != string::npos )
                cmdLine.binaryName = cmdLine.binaryName.substr( i + 1 );
            
            // setup cwd
            char buffer[1024];
#ifdef _WIN32
            verify( _getcwd( buffer , 1000 ) );
#else
            verify( getcwd( buffer , 1000 ) );
#endif
            cmdLine.cwd = buffer;
        }
        

        /* don't allow guessing - creates ambiguities when some options are
         * prefixes of others. allow long disguises and don't allow guessing
         * to get away with our vvvvvvv trick. */
        int style = (((po::command_line_style::unix_style ^
                       po::command_line_style::allow_guessing) |
                      po::command_line_style::allow_long_disguise) ^
                     po::command_line_style::allow_sticky);


        try {

            po::options_description all;
            all.add( visible );
            all.add( hidden );

            po::store( po::command_line_parser(std::vector<std::string>(argv.begin() + 1,
                                                                        argv.end()))
                       .options( all )
                       .positional( positional )
                       .style( style )
                       .run(),
                       params );

            if ( params.count("config") ) {
                ifstream f( params["config"].as<string>().c_str() );
                if ( ! f.is_open() ) {
                    cout << "ERROR: could not read from config file" << endl << endl;
                    cout << visible << endl;
                    return false;
                }

                stringstream ss;
                CmdLine::parseConfigFile( f, ss );
                po::store( po::parse_config_file( ss , all ) , params );
                f.close();
            }

            po::notify(params);
        }
        catch (po::error &e) {
            cout << "error command line: " << e.what() << endl;
            cout << "use --help for help" << endl;
            //cout << visible << endl;
            return false;
        }

        {
            BSONArrayBuilder b;
            std::vector<std::string> censoredArgv = argv;
            censor(&censoredArgv);
            for (size_t i=0; i < censoredArgv.size(); i++) {
                b << censoredArgv[i];
            }
            argvArray = b.arr();
        }

        {
            BSONObjBuilder b;
            for (po::variables_map::const_iterator it(params.begin()), end(params.end()); it != end; it++){
                if (!it->second.defaulted()){
                    const string& key = it->first;
                    const po::variable_value& value = it->second;
                    const type_info& type = value.value().type();

                    if (type == typeid(string)){
                        if (value.as<string>().empty())
                            b.appendBool(key, true); // boost po uses empty string for flags like --quiet
                        else {
                            if ( _isPasswordArgument(key.c_str()) ) {
                                b.append( key, "<password>" );
                            }
                            else {
//.........这里部分代码省略.........
开发者ID:2812140729,项目名称:robomongo,代码行数:101,代码来源:cmdline.cpp

示例7: if

void
WorldRouter::registerConfig( boost::program_options::variables_map& v )
{

	/*
	 * Primary Toggle
	 *
	 */
	if( v.count("primary") )
	{
        std::string s = v["primary"].as<std::string>();
        if ( boost::iequals(s,"true") )
        {
                m_Primary = true;
        }
        else if ( boost::iequals(s,"false") )
        {
                m_Primary = false;
        }
	}
	std::cout << "    m_Primary: " << m_Primary << std::endl;

	/*
	 * Broker URI
	 */
	if( v.count("global.broker") )
	{
        m_Broker = v["global.broker"].as<std::string>();
		std::cout << "globl.broker taken" << std::endl;

	}
	std::cout << "    m_Broker: " << m_Broker << std::endl;


	/*
	 * What's my name
	 */
	if ( v.count("name") )
	{
		m_Name = v["name"].as<std::string>();
	}
	std::cout << "    m_Name: " << m_Name << std::endl;

	/*
	 * Broker inqueue
	 */
	if( v.count( (m_Name+".master.q").c_str() ) )
	{
		m_MasterQueue = v[(m_Name+".master.q").c_str()].as<std::string>();
	}
	std::cout << "    m_MasterQueue: " << m_MasterQueue << std::endl;

	/*
	 * Internal queue
	 */
	if( v.count( (m_Name+".internal.wrq").c_str() ) )
	{
		m_InternalQueue = v[(m_Name+".internal.wrq").c_str()].as<std::string>();
	}

	/*
	 * Just dump the fully known config out
	 */
	for (boost::program_options::variables_map::iterator it=v.begin(); it!=v.end(); ++it )
	{
		if ( it->second.value().type() == typeid(int) )
		{
			std::cout << "  " << it->first.c_str() << " = " << it->second.as<int>() << std::endl;
		}
		else if (it->second.value().type() == typeid(std::string) )
		{
			std::cout << "  " << it->first.c_str() << " = " << it->second.as<std::string>().c_str() << std::endl;
		}
	}

}
开发者ID:sryan,项目名称:hecate,代码行数:76,代码来源:WorldRouter.cpp

示例8: if


//.........这里部分代码省略.........

	}

	if( vm.count("logging.client_sessions") )
	{
		std::string s = vm["logging.client_sessions"].as<std::string>();
		if ( boost::iequals(s,"true") )
		{
			m_logClientSessions = true;
		}
		else if ( boost::iequals(s,"false") )
		{
			m_logClientSessions = false;
		}

	}

	if ( vm.count("logging.packet_logging") )
	{
		std::string s = vm["logging.packet_logging"].as<std::string>();
		if ( boost::iequals(s,"true") )
		{
			m_logPackets = true;
		}
		else if ( boost::iequals(s,"false") )
		{
			m_logPackets = false;
		}

	}

	if( vm.count("logging.packet_logfile") )
	{
		m_PacketLogfile = vm["logging.packet_logfile"].as<std::string>();
std::cout << "logging.packet_logfile: " << m_PacketLogfile << std::endl;
		/*
		 *  Set a hard default if it's not specified
		 */
		if( m_PacketLogfile.length() == 0 )
		{
			m_PacketLogfile = "~/.metaserver-ng/packetdefault.bin";
		}

		if ( m_PacketLogfile.substr(0,1) == "~")
		{
			m_PacketLogfile.replace(0,1, std::getenv("HOME") );
		}

	}

	if ( vm.count("logging.packet_logging_flush_seconds"))
		m_packetLoggingFlushSeconds = vm["logging.packet_logging_flush_seconds"].as<unsigned int>();


	if( vm.count("server.logfile") )
	{
		m_Logfile = vm["server.logfile"].as<std::string>();

		/**
		 * I tried to use boost::filesystem here, but it is so very stupid
		 * that I have opted for the more brittle way, because at least it works.
		 *
		 * TODO: add ifdef WIN32 here if/when metserver needs to run on windows
		 */
		if ( m_Logfile.substr(0,1) == "~")
		{
			m_Logfile.replace(0,1, std::getenv("HOME") );
		}

	}

	/**
	 * Initialise the logger to appropriately
	 */
	initLogger();

	/**
	 * Initialise the packet logger
	 */
	if ( m_logPackets )
	{
		m_PacketLogger = new PacketLogger(m_PacketLogfile);
	}

	/**
	 * Print out the startup values
	 */
	m_Logger.info("WorldForge MetaServer Runtime Configuration");
	for (boost::program_options::variables_map::iterator it=vm.begin(); it!=vm.end(); ++it )
	{
		if ( it->second.value().type() == typeid(int) )
		{
			m_Logger.info( "%s = %u", it->first.c_str(), it->second.as<int>());
		}
		else if (it->second.value().type() == typeid(std::string) )
		{
			m_Logger.info( "%s = %s", it->first.c_str(), it->second.as<std::string>().c_str() );
		}
	}
}
开发者ID:sdavtaker,项目名称:metaserver-ng,代码行数:101,代码来源:MetaServer.cpp


注:本文中的boost::program_options::variables_map::begin方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。