Config Files - pronobis/rocs GitHub Wiki

THIS IS OLD AND SHOULD BE UPDATED FROM DOXYGEN

Supported types of config files

You can use the following formats in rocs :

All of these data formats give files which are structured as trees.

Reading and accessing a config file.

You need to create an InputMixer object, and then pass it the given file.
The InputMixer objects also allow to pass values through the command line arguments.

InputMixer inputMixer;
inputMixer.add_allowed_config_file("configfiles/debug_settings.xml");
inputMixer.add_commandline_args(argc, argv);
rocs::core::ConfigFileReader::print_tree(&inputMixer.tree);

How to access a single value :
bool was_found;
string query, result;
query = "debug.filename";
result = inputMixer.get_value<string> (query, "default_value", was_found);

How to get the sons of a given node :
vector<ptree> sons;
int nb_found;
inputMixer.get_children("listName", nb_found, &sons);
for (vector<ptree>::iterator it = sons.begin(); it < sons.end(); ++it)
ConfigFileReader::print_tree(&(*it));

XML files

The XML format has a particularity : it makes the distinction between an attribute and a child.
For instance, in
<car size="2">
<door color="red"/>
</car>
size is an attribute of car, while door is a son of car.

However, in our parser, during the file parsing phase we convert all attributes into sons.
Thus, the previous example would be equivalent to :
<car>
<size="2">
<door>
<color="red"/>
</door>
</car>

Special infos for lists

Conventions

To represent a list of items, there are a few conventions.

  • The items of a list do not contain values.
  • The item names are not taken into account.

So, here is a correct repesentation of a list. The values B and foo won’t be read, it is equivalent to put an empty node name.

A
|
|--B
| |
| |--key=3
|
|--foo
| |
| |--key2=3
|
|--
| |
| |--key=1
| |
| |--key2=5

Here is an incorrect representation. The key2 son has a value.

A
|
|--B
| |
| |--key=3
|
|--key2=5

Example

Here is an example of XML file
<?xml version="1.0"?>
<listName>
<item foo="bar" />
<item>
<prop>2</prop>
</item>
<item prop="3"/>
</listName>

inputMixer.get_value_list<string> ("listName", "prop", nb_found, &values);
will return [2, 3]. The first item, that doesn’t contain any foo field, won’t trigger an error.

⚠️ **GitHub.com Fallback** ⚠️