I'm using boost::program_options to parse ini file. Simple ini file parsing is easy with program_options. I can add allowed options and it would automatically validate the options. Is there any way to validate the value? Suppose I want to allow only string value from allowed list. e.g For key "TransportType", allowed values are Socket or RPC.
TransportType = Socket ( Anything other than Socket or RPC should not allowed)
I'm using config_file_iterator to which I pass a list of options. But it validates only keys and not values.
Here is code snippet.
namespace pod = boost::program_options::detail;
std::ifstream config("settings.ini");
if(!config)
{
std::cerr<<"error"<<std::endl;
return 1;
}
//parameters
std::set<std::string> options;
std::map<std::string, std::string> parameters;
options.insert("TransportType");
options.insert("URL");
options.insert("Host");
options.insert("Port");
try
{
for (pod::config_file_iterator i(config, options), e ; i != e; ++i)
{
std::cout << i->string_key <<" "<<i->value[0] << std::endl;
parameters[i->string_key] = i->value[0];
}
}
catch(std::exception& e)
{
std::cerr<<"Exception: "<<e.what()<<std::endl;
}