2

Disclamer: I'm using C++11.

In this question I was asking how I could create objects from command line. A good solution was proposed here. Since then, I developed my system and multiple classes and arguments are created from command line. Just as an example:

./myprogram param1 1 param2 "hello" class1 3 8.8 "string_option" class2 1

What this execution does is:

  1. set the optional variable/parameter int param1=1
  2. set the optional variable/parameter std::string param2=hello
  3. create an object of class1 with the constructor class1(int first, float second)
  4. create an ojbect of class2 with the constuctor class2(int first)

Creating objects from class1 and class2 are mandatory, while setting param1 and/or param2 is optional.

So this calling is legal too (missing param1):

./myprogram param2 "hello" class1 3 8.8 "string_option" class2 1

While this is not (missing class1):

./myprogram param1 1 param2 "hello" class2 1

I'm doing this because I need to test several different configurations (i.e. tuning) and find the best one.

Finally, I need to write each configuration to a file/table with the correspondent result, so I can easily compare the results from different configurations.

My question is: is there any already implemented or better solutioin? Like using some configuration file (for exmample a .yml file) or for example some cool library (boost I'm looking at you :) ).

Community
  • 1
  • 1
justHelloWorld
  • 6,478
  • 8
  • 58
  • 138
  • This is one of the reason why there are argument parsers that handle named options. So you can write something like `./myprogram --param1=value1 --param2=value2` etc. You might want to look into e.g. [Boost program options](http://www.boost.org/doc/libs/1_63_0/doc/html/program_options.html). – Some programmer dude Jan 26 '17 at 13:34
  • @Someprogrammerdude Thanks for your comment. I thought about program obtions by boost, but I wonder how I could use it with `class1` where it's not a `(key,value)` as you can see from the question. – justHelloWorld Jan 26 '17 at 14:47
  • @Someprogrammerdude And btw how could I write them to file? – justHelloWorld Jan 26 '17 at 16:40

0 Answers0