Simpact Cyan
Population based event driven simulation using mNRM
configsettings.h
Go to the documentation of this file.
1 #ifndef CONFIGSETTINGS_H
2 
3 #define CONFIGSETTINGS_H
4 
9 #include "configreader.h"
10 #include "util.h"
11 #include <stdint.h>
12 #include <limits>
13 
22 {
23 public:
25  ConfigSettings(const ConfigSettings &src) { m_keyValues = src.m_keyValues; }
26  virtual ~ConfigSettings();
27 
28  ConfigSettings &operator=(const ConfigSettings &src) { m_keyValues = src.m_keyValues; return *this; }
29 
31  bool_t load(const std::string &fileName);
32 
34  void clear();
35 
37  void getKeys(std::vector<std::string> &keys) const;
38 
41  bool_t getKeyValue(const std::string &key, std::string &value, const std::vector<std::string> &allowedValues = std::vector<std::string>() );
42 
45  // std::numeric_limits<double>::min() is the smallest in absolute value, can't use that here!
46  bool_t getKeyValue(const std::string &key, double &value, double minValue = -std::numeric_limits<double>::infinity(),
47  double maxValue = std::numeric_limits<double>::infinity());
48 
51  // std::numeric_limits<double>::min() is the smallest in absolute value, can't use that here!
52  bool_t getKeyValue(const std::string &key, std::vector<double> &values,
53  double minValue = -std::numeric_limits<double>::infinity(),
54  double maxValue = std::numeric_limits<double>::infinity());
55 
58  bool_t getKeyValue(const std::string &key, int &value, int minValue = std::numeric_limits<int>::min(),
59  int maxValue = std::numeric_limits<int>::max());
60 
63  bool_t getKeyValue(const std::string &key, int64_t &value, int64_t minValue = std::numeric_limits<int64_t>::min(),
64  int64_t maxValue = std::numeric_limits<int64_t>::max());
65 
67  bool_t getKeyValue(const std::string &key, bool &value);
68 
71  bool_t getStringKeyValue(const std::string &key, std::string &value, bool &used) const;
72 
75  void getUnusedKeys(std::vector<std::string> &keys) const;
76 
78  void clearUsageFlags();
79 
81  void merge(const ConfigSettings &src);
82 private:
83  std::map<std::string, std::pair<std::string, bool> > m_keyValues;
84 };
85 
86 #endif // CONFIGSETTINGS_H
87 
void getUnusedKeys(std::vector< std::string > &keys) const
Stores a list of keys that have not been read by any of the getKeyValue functions into keys (allows y...
Definition: configsettings.cpp:103
bool_t load(const std::string &fileName)
Loads the key/value pairs from the config file specified by fileName.
Definition: configsettings.cpp:19
Type to return true/false with error description.
Definition: booltype.h:25
bool_t getKeyValue(const std::string &key, std::string &value, const std::vector< std::string > &allowedValues=std::vector< std::string >())
Stores the string value for key parameter key into argument value, checking if the value is one of th...
void clear()
Clears the loaded key/value pairs.
Definition: configsettings.cpp:45
Helper class to read configuration settings, more advanced than ConfigReader.
Definition: configsettings.h:21
void getKeys(std::vector< std::string > &keys) const
Returns a list of all the keys in the read config file.
Definition: configsettings.cpp:50
void clearUsageFlags()
Resets the markers that keep track of wether or not a key has been read.
Definition: configsettings.cpp:167
bool_t getStringKeyValue(const std::string &key, std::string &value, bool &used) const
Obtains the value for the specified key, not marking the key as used, but instead storing information...
Definition: configsettings.cpp:62
void merge(const ConfigSettings &src)
Merges the specified config settings object into the current one.
Definition: configsettings.cpp:178