|
solarpowerlog trunk
|
Solarpowerlog uses a configuration file to get the settings of the individual components. It even decided out of the config file which components are needed ans wich objects needs to work together.
For easier handling of the configuration, solarpowerlog provides methods to gather the settings.
First, every object gets a so-called configuaration path. This is a string, describing where the configuration of the object is located. (As currently libconfig is used, this is the "path" of libconfig. Every object should safe this path.
Second, a helper class, CConfigHelper exists. This class has some methods allowing to extract the configuration very conveniently:
Without many words, here are the some examples.
Example 1: Check for key type and existence.
CConfigHelper hlp(configurationpath); // Required Key: Will set fail=true if non-existent or wrong type fail |= !hlp.CheckConfig("datasource", Setting::TypeString); // Optional key: Will set fail=truel only if clearscreen is not boolean. fail |= !hlp.CheckConfig("clearscreen", Setting::TypeBoolean, true);
Example 2: Retrieve key
CConfigHelper cfghlp(configurationpath); float interval; // This sets the value to 5.0 if not in the configuration: cfghlp.GetConfig("queryinterval", interval, 5.0f); // This would just set the value. if not configured, the value is left // alone. cfghlp.GetConfig("queryinterval", interval);