User Tools

Site Tools


tools:config

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
tools:config [2017/12/14 08:06] graftools:config [2020/12/03 12:01] (current) ursgraf
Line 4: Line 4:
 TestConfig : public eeros::config::FileConfig { TestConfig : public eeros::config::FileConfig {
 public: public:
-  TestConfig(const char *name) :  +  TestConfig(const char *name) : FileConfig(name), b(2.2), d("127.0.0.0") {
-    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("id", a);
       add("offset", b);       add("offset", b);
-      add("init values", c);+      add("initValues", c);
       add("ip", d);       add("ip", d);
   }   }
Line 23: Line 17:
 </code> </code>
  
-When such a configuration class object is created, its values are initialized with default values. +The above example shows such a configuration class. When an object of this class is created, some of the values are initialized with default values and then added to the configuration 
 <code cpp> <code cpp>
   TestConfig configFile("config.txt"); // choose an appropriate path   TestConfig configFile("config.txt"); // choose an appropriate path
 </code> </code>
-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.+ 
 +If a configuration file exists at the given location, you can load the values from there and overwrite the default values with the values given in the file.
 <code cpp> <code cpp>
   TestConfig configFile("config.txt"); // choose an appropriate path   TestConfig configFile("config.txt"); // choose an appropriate path
   configFile.load();   configFile.load();
 +</code>
 +
 +WARNING Valid name for the identifiers of the values must not include spaces. 'myText10' is valid while 'my_text 10' is not! \\ \\
 +You can manually create a suitable configuration file at the given location, e.g.
 +<code>
 +id = 1
 +offset = 2.200000
 +initValues = 0.1, 0.4, 0.3
 +ip = 127.0.0.0
 +</code>
 +or you could save the values of your configuration class object into the file (and possible change an existing content).
 +<code cpp>
 +  configFile.save();
 +</code>
 +It's also possible to save to or restore from another file by writing:
 +<code cpp>
 +  configFile.save("config2.txt");
 +  configFile.load("config2.txt");
 +</code>
 +
 +There is a complete example in the example directory of EEROS. Open a shell in the build directory of your EEROS library and run 
 +<code>
 +$ ./examples/config/configExample
 </code> </code>
tools/config.1513235186.txt.gz · Last modified: 2017/12/14 08:06 by graf