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 <limits>
12 
21 {
22 public:
24  ConfigSettings(const ConfigSettings &src) { m_keyValues = src.m_keyValues; }
25  ~ConfigSettings();
26 
27  ConfigSettings &operator=(const ConfigSettings &src) { m_keyValues = src.m_keyValues; return *this; }
28 
30  bool load(const std::string &fileName);
31 
33  void clear();
34 
36  void getKeys(std::vector<std::string> &keys) const;
37 
40  bool getKeyValue(const std::string &key, std::string &value, const std::vector<std::string> &allowedValues = std::vector<std::string>() );
41 
44  // std::numeric_limits<double>::min() is the smallest in absolute value, can't use that here!
45  bool getKeyValue(const std::string &key, double &value, double minValue = -std::numeric_limits<double>::max(),
46  double maxValue = std::numeric_limits<double>::max());
47 
50  bool getKeyValue(const std::string &key, int &value, int minValue = std::numeric_limits<int>::min(),
51  int maxValue = std::numeric_limits<int>::max());
52 
53  bool getStringKeyValue(const std::string &key, std::string &value, bool &used) const;
54 
57  void getUnusedKeys(std::vector<std::string> &keys) const;
58 
60  void clearUsageFlags();
61 
63  void merge(const ConfigSettings &src);
64 private:
65  std::map<std::string, std::pair<std::string, bool> > m_keyValues;
66 };
67 
68 #endif // CONFIGSETTINGS_H
69 
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:114
Base class which allows an error message to be set.
Definition: errorbase.h:49
void clear()
Clears the loaded key/value pairs.
Definition: configsettings.cpp:46
Helper class to read configuration settings, more advanced than ConfigReader.
Definition: configsettings.h:20
void getKeys(std::vector< std::string > &keys) const
Returns a list of all the keys in the read config file.
Definition: configsettings.cpp:51
void clearUsageFlags()
Resets the markers that keep track of wether or not a key has been read.
Definition: configsettings.cpp:177
bool load(const std::string &fileName)
Loads the key/value pairs from the config file specified by fileName.
Definition: configsettings.cpp:15
void merge(const ConfigSettings &src)
Merges the specified config settings object into the current one.
Definition: configsettings.cpp:188
bool 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...