basic_parsed_options<charT> parse_config_file(std::basic_istream<charT>& is, const options_description& desc, bool allow_unregistered) { set<string> allowed_options; const vector<shared_ptr<option_description> >& options = desc.options(); for (unsigned i = 0; i < options.size(); ++i) { const option_description& d = *options[i]; if (d.long_name().empty()) pdalboost::throw_exception( error("long name required for config file")); allowed_options.insert(d.long_name()); } // Parser return char strings parsed_options result(&desc); copy(detail::basic_config_file_iterator<charT>( is, allowed_options, allow_unregistered), detail::basic_config_file_iterator<charT>(), back_inserter(result.options)); // Convert char strings into desired type. return basic_parsed_options<charT>(result); }
options_description get_section_options(const string section_name, const string group_caption, const options_description &original_options_descriptions) { const std::vector< shared_ptr<option_description> >&original_options = original_options_descriptions.options(); options_description new_options(group_caption.c_str()); std::vector< shared_ptr<option_description> >::const_iterator options_it; for(options_it = original_options.begin(); options_it != original_options.end(); ++options_it) { const option_description &t_option = *(*options_it); string new_name(section_name + "."); new_name += t_option.long_name(); // IMPORTANT: in order for this line not to crash the original_options_descriptions needs to be a static declaration // otherwise t_option.semantic().get() will point to an invalid memory direction and // the application will raise a segmentation fault new_options.add_options() (new_name.c_str(), t_option.semantic().get(), t_option.description().c_str()); } return new_options; }
basic_parsed_options<charT> parse_xml(const options_description& desc) { using boost::shared_ptr; set<string> allowed_options; const vector<shared_ptr<option_description> >& options = desc.options(); for (unsigned i = 0; i < options.size(); ++i) { const option_description& d = *options[i]; if (d.long_name().empty()) boost::throw_exception( error("long name required for config file")); allowed_options.insert(d.long_name()); } // Parser return char strings parsed_options result(&desc); result.options.push_back(basic_option<charT>("my_double", vector<string>(1, "10.1214"))); //result.options.push_back(basic_option<charT>("my_string", vector<string>(1, "hello world"))); return basic_parsed_options<charT>(result); }