Parent abstract class aimed to provide an interface for class children to manage the configuration file of a service. This class implements a singleton pattern that makes use of RapidJSON libraries
and, by doing so, it facilitates methods for: More...

#include <configuration.h>

Inheritance diagram for Configuration:

Protected Member Functions

virtual bool init (boost::system::error_code &ec, std::string path)
 Inits configuration reading from file in path. More...
 
virtual bool getMember (const rapidjson::Value &conf, boost::system::error_code &ec, std::string member, int &value)
 Gets a INT member in rapidjson value. More...
 
virtual bool getMember (const rapidjson::Value &conf, boost::system::error_code &ec, std::string member, std::string &value)
 Gets a STRING member in rapidjson value. More...
 
virtual bool getMember (const rapidjson::Value &conf, boost::system::error_code &ec, std::string member, bool &value)
 Gets a BOOL in rapidjson value. More...
 
virtual bool readConfiguration (boost::system::error_code &ec, std::string path)=0
 Reads the service configuration. More...
 
virtual bool writeConfiguration (boost::system::error_code &ec, std::string path)=0
 Writes the service configuration. More...
 
virtual bool writeDefaultConfiguration (boost::system::error_code &ec, std::string path)=0
 Writes default configuration to file. More...
 
virtual bool writeConfigurationToFile (boost::system::error_code &ec, const rapidjson::Document &doc, std::string path)
 Writes the configuration stored in doc to the path file. More...
 
virtual bool writeConfigurationToFile (boost::system::error_code &ec, const std::string &doc, std::string path)
 Writes the configuration stored in data to the path file. More...
 
virtual bool getDocfromPath (boost::system::error_code &ec, rapidjson::Document &doc, std::string path)
 Parse the data from the file existing in the path and introduce it into a rapidjson document object. More...
 

Detailed Description

  • Creating JSON fields.
  • Reading JSON fields.
    • Create a JSON Configuration file and write it to a specific configuration path.
    • Reading a JSON Configuration file from a specific configuration path and create a default one in case it does not exist.

Member Function Documentation

virtual bool getDocfromPath ( boost::system::error_code &  ec,
rapidjson::Document &  doc,
std::string  path 
)
protectedvirtual
Parameters
ecerror code
docparent document in which all information from file will be stored
pathconfiguration file path
Returns
true if read is performed correctly, false otherwise
Todo:
FIX [Unused]: Seems to read the file but it is not really working, as it does not throw error when file does not exist.
virtual bool getMember ( const rapidjson::Value &  conf,
boost::system::error_code &  ec,
std::string  member,
int &  value 
)
protectedvirtual
Parameters
confrapidjson value
ecerror code
memberidentifier
valuevalue as a result
Returns
true if value is read, false otherwise
virtual bool getMember ( const rapidjson::Value &  conf,
boost::system::error_code &  ec,
std::string  member,
std::string &  value 
)
protectedvirtual
Parameters
confrapidjson value
ecerror code
memberidentifier
valuevalue as a result
Returns
true if value is read, false otherwise
virtual bool getMember ( const rapidjson::Value &  conf,
boost::system::error_code &  ec,
std::string  member,
bool &  value 
)
protectedvirtual
Parameters
confrapidjson value
ecerror code
memberidentifier
valuevalue as a result
Returns
true if value is read, false otherwise
virtual bool init ( boost::system::error_code &  ec,
std::string  path 
)
protectedvirtual
Parameters
ecerror code
pathconfiguration path
Returns
true if configuration is initialized, false otherwise
virtual bool readConfiguration ( boost::system::error_code &  ec,
std::string  path 
)
protectedpure virtual
Parameters
ecerror code
pathconfiguration file path
Returns
true if configuration is read, false otherwise

Implemented in SmsListConfiguration.

virtual bool writeConfiguration ( boost::system::error_code &  ec,
std::string  path 
)
protectedpure virtual
Parameters
ecerror code
pathconfiguration file path
Returns
true if configuration is written, false otherwise

Implemented in SmsListConfiguration.

virtual bool writeConfigurationToFile ( boost::system::error_code &  ec,
const rapidjson::Document &  doc,
std::string  path 
)
protectedvirtual
Parameters
ecerror code
docparent document type with all information
pathconfiguration file path
Returns
true if write is performed correctly, false otherwise
virtual bool writeConfigurationToFile ( boost::system::error_code &  ec,
const std::string &  doc,
std::string  path 
)
protectedvirtual
Parameters
ecerror code
docstring with all information
pathconfiguration file path
Returns
true if write is performed correctly, false otherwise
virtual bool writeDefaultConfiguration ( boost::system::error_code &  ec,
std::string  path 
)
protectedpure virtual
Parameters
ecerror code
pathconfiguration file path
Returns
true if configuration is written, false otherwise

Implemented in SmsListConfiguration.