configuration.h
1 
7 #pragma once
8 
9 #include <stdio.h>
10 #include <stdlib.h>
11 #include <fstream>
12 #include <iostream>
13 #include <string>
14 #include <assert.h>
15 #include <sstream>
16 #include <vector>
17 #include <map>
18 #include <rapidjson/document.h>
19 #include <rapidjson/filereadstream.h>
20 #include <rapidjson/filewritestream.h>
21 #include <rapidjson/stringbuffer.h>
22 #include <rapidjson/writer.h>
23 #include <rapidjson/prettywriter.h>
24 #include <boost/system/error_code.hpp>
25 #include "systemConfiguration.h"
26 #ifdef TESTING
27 #include "gtest/gtest.h"
28 #endif
29 
30 
44 {
45 private:
46  bool tryMerge(std::string srcFile, std::string dstFile);
47  bool mergeObjects(const rapidjson::Value &dstObject, rapidjson::Value &srcObject, rapidjson::Document::AllocatorType &allocator);
48 
49 protected:
50 
51  Configuration();
52  virtual ~Configuration();
59  virtual bool init(boost::system::error_code &ec, std::string path);
68  virtual bool getMember(const rapidjson::Value& conf, boost::system::error_code &ec, std::string member, int& value);
77  virtual bool getMember(const rapidjson::Value& conf, boost::system::error_code &ec, std::string member, std::string& value);
86  virtual bool getMember(const rapidjson::Value& conf, boost::system::error_code &ec, std::string member, bool& value);
87 
94  virtual bool readConfiguration(boost::system::error_code &ec, std::string path) = 0;
95 
102  virtual bool writeConfiguration(boost::system::error_code &ec, std::string path) = 0;
103 
110  virtual bool writeDefaultConfiguration(boost::system::error_code &ec, std::string path) = 0;
111 
119  virtual bool writeConfigurationToFile(boost::system::error_code &ec, const rapidjson::Document &doc, std::string path);
120 
128  virtual bool writeConfigurationToFile(boost::system::error_code &ec, const std::string &doc, std::string path);
129 
138  virtual bool getDocfromPath(boost::system::error_code &ec, rapidjson::Document &doc, std::string path);
139 
140 public:
141 
146 #ifdef TESTING
147 public:
148  FRIEND_TEST(Config_Init_test, Merge1);
149  FRIEND_TEST(Config_Init_test, Merge2);
150  FRIEND_TEST(Config_Init_test, Merge3);
151  FRIEND_TEST(Config_Init_test, Merge4);
152 #endif
153 
154 };
virtual bool init(boost::system::error_code &ec, std::string path)
Inits configuration reading from file in path.
virtual bool readConfiguration(boost::system::error_code &ec, std::string path)=0
Reads the service configuration.
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...
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.
virtual bool getMember(const rapidjson::Value &conf, boost::system::error_code &ec, std::string member, int &value)
Gets a INT member in rapidjson value.
virtual bool writeDefaultConfiguration(boost::system::error_code &ec, std::string path)=0
Writes default configuration to file.
Parent abstract class aimed to provide an interface for class children to manage the configuration fi...
Definition: configuration.h:43
virtual bool writeConfiguration(boost::system::error_code &ec, std::string path)=0
Writes the service configuration.