Classes | |
class | itpp::Parser |
Argument Parser Class. More... |
This class parses strings to variables. The syntax is compatible with Matlab and Octave. It can be used in several different ways. The following test program and test data file gives several examples:
The test program looks as follows:
The data file parser_test_data.txt
looks as follows:
Beside the type-specific get methods, like get_int(), there is a templated get method called get(), that can handle all variable types that have an istream operator defined, e.g. Arrays. The get() method takes the variable value as an input/output parameter. If the variable name cannot be found, the old value is kept. Here is an example:
// Declare and initialize a variable Array<ivec> var; set_array(var, "{[1] [2 3] [4 5 6]}"); // Let the Parser p get the variable named my_var_name bool my_var_name_was_found = p.get(var, "my_var_name");
In the above example, if my_var_name
was not found, var
keeps its old value {[1] [2 3] [4 5 6]}. In non-silent mode, the get() method echoes the variable values to the standard output in Matlab/Octave m-file style.