boost-program-options

How to parse comma separated values with boost::program_options?

泪湿孤枕 提交于 2019-12-01 21:23:15
I need to parse cmd like -value=str1,str2,str3 using boost::program_options . I've found exactly the same question but it's not working anymore (with boost 1.55 and 1.56). I've tried to define my own class and mapper but no luck: namespace po = boost::program_options; desc.add_options() ("mattr", po::value<lli::CommaSeparatedVector>(&MAttrs), "Target specific attributes (-mattr=help for details)"); namespace lli { class CommaSeparatedVector { public: // comma separated values list std::vector<std::string> values; }; } void tokenize(const std::string& str, std::vector<std::string>& tokens,

using hashmark in program options value (ini file)

蹲街弑〆低调 提交于 2019-12-01 13:11:39
I have some trouble reading from an ini file using boost program options. The problem is a key which contains hashmarks (simplyfied example): [section] key="xxx#yyy" Retrieving the key, returns "xxx", which is because the hashmark seems to be interpreted as start of a comment and therefore the rest of the line is skipped. Unfortunately I cannot substitute the '#' by some other character because the value is a regular expression. I didn't find a way to quote the hashmark and would prefer not to do it, because it would alter my regex and make it even more unreadable. Is there a way to deal with

Boost Program Options Syntax

北城以北 提交于 2019-11-30 05:06:55
I'm using boost::program_options to read the users' input from the command line argument. It works very nicely and allows me to output helpful usage messages and validate input properly. However, by default long option names must come after a double-dash for example --my_long_option and short options come after a single dash and must be a single character, example; -m . Is there a way to either... Allow long options after a single - ? Allow short options to have more than one character? Thus allowing me to have command lines which looks like ./a.out -myopt1 foo -myopt2 bar The two

How to solve “boost::bad_any_cast: failed conversion using boost::any_cast” when using boost program options?

梦想与她 提交于 2019-11-29 16:59:36
问题 //Using boost program options to read command line and config file data #include <boost/program_options.hpp> using namespace std; using namespace boost; namespace po = boost::program_options; int main (int argc, char *argv[]) { po::options_description config("Configuration"); config.add_options() ("IPAddress,i","IP Address") ("Port,p","Port") ; po::variables_map vm; po::store(po::parse_command_line(argc, argv, config),vm); po::notify(vm); cout << "Values\n"; string address = (vm["IPAddress"]

Boost Program Options Add Options Syntax

我怕爱的太早我们不能终老 提交于 2019-11-29 09:07:34
I am writing a program that uses Boost's Program Options library and I noticed the following syntax that has haunted me since I saw it: desc.add_options() ("help","produce help message") ( /* other flag, value, description pairs here */) ; I see that in the header, operator() is overridden, but I'm not sure how that allows this to be syntactically correct. Secondly, is there any advantage to this syntax, compared with just calling add_options() multiple times (besides showing off the fact that you can manipulate syntax like this)? The add_options member function returns an object of type

Boost program options - get all entries in section

喜夏-厌秋 提交于 2019-11-29 04:47:47
问题 According to documentation I can parse config files in style : [main section] string = hello world. [foo] message = Hi ! But I need to parse list of plugins : [plugins] somePlugin. HelloWorldPlugin AnotherPlugin [settings] type = hello world How can I get vector of strings which are in plugins section ? 回答1: For boost program options config files, if the line is not declaring a section, such as [settings] , then it needs to be in a name=value format. For your example, write it as the

Boost Program Options Syntax

与世无争的帅哥 提交于 2019-11-29 02:30:21
问题 I'm using boost::program_options to read the users' input from the command line argument. It works very nicely and allows me to output helpful usage messages and validate input properly. However, by default long option names must come after a double-dash for example --my_long_option and short options come after a single dash and must be a single character, example; -m . Is there a way to either... Allow long options after a single - ? Allow short options to have more than one character? Thus

Boost program options allowed set of input values

巧了我就是萌 提交于 2019-11-29 01:22:31
Is there a way to set an allowed set of input variables for parameters? For example parameter "arg" can have only string values like "cat" and "dog". You can use the custom validator feature. Define a distinct type for your option, and then overload the validate function on that type. struct catdog { catdog(std::string const& val): value(val) { } std::string value; }; void validate(boost::any& v, std::vector<std::string> const& values, catdog* /* target_type */, int) { using namespace boost::program_options; // Make sure no previous assignment to 'v' was made. validators::check_first

Required and Optional Arguments Using Boost Library Program Options

。_饼干妹妹 提交于 2019-11-28 16:09:29
I'm using Boost Program Options Library to parse the command line arguments. I have the following requirements: Once "help" is provided, all the other options are optional; Once "help" is not provided, all the other options are required. How I can deal with this? Here is the my code handling this, and I found it's very redundant, and I think there must be an easy to do, right? #include <boost/program_options.hpp> #include <iostream> #include <sstream> namespace po = boost::program_options; bool process_command_line(int argc, char** argv, std::string& host, std::string& port, std::string&

Building boost::options from a string/boost::any map

喜你入骨 提交于 2019-11-28 06:36:40
I have a map which represents a configuration. It's a map of std::string and boost::any . This map is initialized at the start and I'd like the user to be able to override these options on the command line. What I'd love to do is build the program options from this map using the options_description::add_option() method. However, it takes a template argument po::value<> whereas all I have is boost::any . So far, I just have the shell of the code. m_Config represents my configuration class, and getTuples() returns a std::map<std::string, Tuple> . TuplePair is a typedef of std::pair<std::string,