User Tools

Site Tools


Configuration Files

There is often a need to load a configuration from a text file on the disk or write configuration into such a file. This could be calibration data, ip-numbers, etc. This can be achieved in EEROS by packing this configuration data into a class as follows:

TestConfig : public eeros::config::FileConfig {
  TestConfig(const char *name) : 
    // set default values
    c{0.1, 0.2, 0.3},
    d("") {
      add("id", a);
      add("offset", b);
      add("initValues", c);
      add("ip", d);
  int a;
  double b;
  std::array<double, 3> c;
  std::string d;

When such a configuration class object is created, its values are initialized with default values.

  TestConfig configFile("config.txt");	// choose an appropriate path

However, if a configuration file exists at the given location, you can load the values from there and overwrite these default values with the values given in the file.

  TestConfig configFile("config.txt");	// choose an appropriate path

WARNING Valid name for the identifiers of the values include numbers and letters only, no spaces, underlines or dots. 'myText10' is valid while 'my_text_10' is not!

You can manually create a suitable configuration file at the given location, e.g.

id = 1
offset = 2.200000
initValues = 0.1, 0.4, 0.3
ip =

or you could save the values of your configuration class object into the file (and possible change an existing content).;

It's also possible to save to or restore from another file by writing:"config2.txt");
tools/config.txt · Last modified: 2018/01/12 09:28 by graf