User Tools

Site Tools


tools:config

This is an old revision of the document!


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 {
public:
  TestConfig(const char *name) : 
    FileConfig(name),
    // set default values
    a(1),
    b(2.2),
    c{0.1, 0.2, 0.3},
    d("127.0.0.0") {
      add("id", a);
      add("offset", b);
      add("init values", 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 van 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
  configFile.load();
tools/config.1513235186.txt.gz · Last modified: 2017/12/14 08:06 by graf