Thanks for your reply. I am using boost::program_options to parse a config file like below --- sample.conf --- node.initiator=true tcp.port=8080 bootstrap.hints={ip{127.0.0.1},tcp(ip,{5002})} ---------------------------- Below I give the code that tries to read the config file sample.conf and tries to get all the options mentioned in file sample.conf - ------- Code ----- void main(){ std::string configFileName("sample.conf"); boost::program_options::options_description *optionsDescription; boost::program_options::variables_map *variablesMap; optionsDescription = new boost::program_options::options_description("Configuration"); variablesMap = new boost::program_options::variables_map(); optionsDescription->add_options() ("tcp.port", "TCP Port Number") ("bootstrap.hints", "Bootstrap Hints"); std::ifstream ifs(configFileName.c_str()); store(parse_config_file(ifs, *optionsDescription, true), *variablesMap); notify(*variablesMap); if (variablesMap->count("node.initiator"){ std::cout <<(*variablesMap)["node.initiator"].as<std::string>() << "\n"; } if (variablesMap->count("tcp.port")){ std::cout <<(*variablesMap)["tcp.port"].as<std::string>() << "\n"; } if (variablesMap->count("bootstrap.hints")){ std::cout <<(*variablesMap)["bootstrap.hints"].as<std::string>() << "\n"; } delete optionsDescription; delete variablesMap; return ; } ----------------- Now, the output is like below - --- output --- 8080 {ip{127.0.0.1},tcp(ip,{5002})} --------- But the value of the option node.initiator (i.e. "true") is not shown, also there is no exception. If I pass "false" in the 3rd parameter of parse_config_file() rather than "true", it throws exception, as it should do. But my question is, why "node.initiator" option is not in the variablesMap, as parse_config_file() should have parsed both registered and unregistered options. Surely if(variablesMap->count("node.initiator") does not pass. In the following link, it is mentioned that "allow_unregistered = false" is the default argument for parse_config_file() function, but I am surely passing "true" in my code. http://www.boost.org/doc/libs/1_38_0/doc/html/boost/program_options/parse_config_file.html In another post you mentioned that SVN HEAD supports unregistered options in config file. Just now I have build the program_option library from boost svn, but there is no difference in the result. Awaiting your response. Thank you. --- On Thu, 6/25/09, Hasanul Ferdaus <sunny_register@yahoo.com> wrote:
|