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