SeComLib
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Macros Pages
config.h
Go to the documentation of this file.
1 /*
2 SeComLib
3 Copyright 2012-2013 TU Delft, Information Security & Privacy Lab (http://isplab.tudelft.nl/)
4 
5 Contributors:
6 Inald Lagendijk (R.L.Lagendijk@TUDelft.nl)
7 Mihai Todor (todormihai@gmail.com)
8 Thijs Veugen (P.J.M.Veugen@tudelft.nl)
9 Zekeriya Erkin (z.erkin@tudelft.nl)
10 
11 Licensed under the Apache License, Version 2.0 (the "License");
12 you may not use this file except in compliance with the License.
13 You may obtain a copy of the License at
14 
15 http://www.apache.org/licenses/LICENSE-2.0
16 
17 Unless required by applicable law or agreed to in writing, software
18 distributed under the License is distributed on an "AS IS" BASIS,
19 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
20 See the License for the specific language governing permissions and
21 limitations under the License.
22 */
29 #ifndef CONFIG_HEADER_GUARD
30 #define CONFIG_HEADER_GUARD
31 
32 //include C++ headers
33 #include <iostream>
34 #include <fstream>
35 #include <string>
36 #include <stdexcept>
37 
38 //include boost library headers
39 #include <boost/property_tree/ptree.hpp>
40 #include <boost/property_tree/xml_parser.hpp>
41 
42 namespace SeComLib {
43 namespace Utils {
49  class Config {
50  public:
52  static Config &GetInstance ();
53 
55  template<typename T>
56  T GetParameter (const std::string &parameter) const;
57 
59  template<typename T>
60  T GetParameter (const std::string &parameter, const T &defaultValue) const;
61 
63  static void SetConfigFile(const std::string &configFile);
64 
65  private:
67  boost::property_tree::ptree propertyTree;
68 
70  static std::string configFile;
71 
73  static const std::string xmlRootElementName;
74 
77  Config ();
78 
80  ~Config () {}
81 
83  Config (Config const &);
84 
86  Config operator= (Config const &);
87  };
88 
89 }//namespace Utils
90 }//namespace SeComLib
91 
92 //Separate the implementation from the declaration of template methods
93 #include "config.hpp"
94 
95 #endif//CONFIG_HEADER_GUARD
boost::property_tree::ptree propertyTree
The internal mapping of the XML configuration file.
Definition: config.h:67
~Config()
Destructor - void implementation.
Definition: config.h:80
static Config & GetInstance()
Returns a reference to the singleton.
Definition: config.cpp:48
static const std::string xmlRootElementName
The name of the root node in the configuration XML file.
Definition: config.h:73
Implementation of template members from class Config.
static std::string configFile
The location of the configuration file.
Definition: config.h:70
Config operator=(Config const &)
Copy assignment operator - not implemented.
Utilitary class for parsing the configuration file.
Definition: config.h:49
T GetParameter(const std::string &parameter) const
Template method which returns the value of the specified configuration parameter. ...
Definition: config.hpp:41
static void SetConfigFile(const std::string &configFile)
Sets the location and name of the configuration file.
Definition: config.cpp:56