MinitScript  0.9.31 PRE-BETA
Properties.h
Go to the documentation of this file.
1 #pragma once
2 
3 #include <string>
4 #include <unordered_map>
5 
8 
9 using std::string;
10 using std::unordered_map;
11 
12 /**
13  * Properties class, which helps out with storeing or loading key value pairs from/to property files
14  * @author Andreas Drewke
15  */
17 {
18 private:
19  unordered_map<string, string> properties;
20 
21 public:
22  /**
23  * Public constructor
24  */
26 
27  /**
28  * Clear
29  */
30  inline void clear() {
31  properties.clear();
32  }
33 
34  /**
35  * Get property value by key
36  * @param key key
37  * @param defaultValue default value
38  * @return value if found or default value
39  */
40  inline const string& get(const string& key, const string& defaultValue) const {
41  auto it = properties.find(key);
42  if (it == properties.end()) return defaultValue;
43  return it->second;
44  }
45 
46  /**
47  * Add property
48  * @param key key
49  * @param value value
50  *
51  */
52  inline void put(const string& key, const string& value) {
53  properties[key] = value;
54  }
55 
56  /**
57  * Load property file
58  * @param pathName path name
59  * @param fileName file name
60  * @throws tdme::os::filesystem::FileSystemException
61  */
62  void load(const string& pathName, const string& fileName);
63 
64  /**
65  * Store property file
66  * @param pathName path name
67  * @param fileName file name
68  * @throws tdme::os::filesystem::FileSystemException
69  */
70  void store(const string& pathName, const string& fileName) const;
71 
72  /**
73  * @return properties map
74  */
75  inline const unordered_map<string, string>& getProperties() {
76  return properties;
77  }
78 
79 };
Properties class, which helps out with storeing or loading key value pairs from/to property files.
Definition: Properties.h:17
void put(const string &key, const string &value)
Add property.
Definition: Properties.h:52
const string & get(const string &key, const string &defaultValue) const
Get property value by key.
Definition: Properties.h:40
void store(const string &pathName, const string &fileName) const
Store property file.
Definition: Properties.cpp:38
const unordered_map< string, string > & getProperties()
Definition: Properties.h:75
void load(const string &pathName, const string &fileName)
Load property file.
Definition: Properties.cpp:22
unordered_map< string, string > properties
Definition: Properties.h:19
Properties()
Public constructor.
Definition: Properties.h:25