21 #include <unordered_map> 41 Property(std::string value) : stringValue(value), longValue(0), doubleValue(0), ptrValue(0) {}
43 Property(std::string&& value) : stringValue(value), longValue(0), doubleValue(0), ptrValue(0) {}
45 Property(
long value) : longValue(value), doubleValue(0), ptrValue(0) {}
47 Property(
double value) : longValue(0), doubleValue(value), ptrValue(0) {}
49 Property(
void* value) : longValue(0), doubleValue(0), ptrValue(value) {}
62 std::string stringValue;
83 std::shared_ptr<Property> res= entries[key];
84 return res ? res.get() :
nullptr;
91 std::shared_ptr<Property> res= entries[key];
92 return res ? res.get()->getObjectValue<T>() :
nullptr;
98 std::shared_ptr<Property> res= entries[key];
99 return res ? res.get()->getLongValue() : 0;
105 std::shared_ptr<Property> res= entries[key];
106 return res ? res.get()->getDoubleValue() : 0;
112 std::shared_ptr<Property> res= entries[key];
113 return res ? res.get()->getStringValue() : std::string();
117 void set(std::string key, std::string value) { entries[key]= std::make_shared<Property>(value); }
119 void set(std::string key, std::string&& value) { entries[key]= std::make_shared<Property>(value); }
121 void set(std::string key,
long value) { entries[key]= std::make_shared<Property>(value); }
123 void set(std::string key,
double value) { entries[key]= std::make_shared<Property>(value); }
125 void set(std::string key,
void* value) { entries[key]= std::make_shared<Property>(value); }
128 bool has(std::string key) {
return entries.count(key) > 0; }
131 size_t remove(std::string key) {
return entries.erase(key); }
135 std::unordered_map<std::string, std::shared_ptr<Property>> entries;
141 #endif // __PLIST_HPP_ Property(void *value)
Constructs a new property with a void* value.
Definition: plist.hpp:49
Property(std::string &&value)
Constructs a new property with a string value (moving the value)
Definition: plist.hpp:43
Property * getProperty(std::string key)
Retrieves the Property object of a given key.
Definition: plist.hpp:81
bool has(std::string key)
Checks if the list contains a given key.
Definition: plist.hpp:128
long getLong(std::string key)
Retrieves the long value of a given key.
Definition: plist.hpp:96
Describes a single property containing one or more typed values.
Definition: plist.hpp:36
long getLongValue()
Retrieves the long value of the property. If no long value was set, returns 0.
Definition: plist.hpp:54
std::string & getStringValue()
Retrieves the string value of the property. If no string value was set, returns an empty string objec...
Definition: plist.hpp:52
Property(std::string value)
Constructs a new property with a string value.
Definition: plist.hpp:41
std::string getString(std::string key)
Retrieves the string value of a given key.
Definition: plist.hpp:110
void set(std::string key, long value)
Sets the value of a key to a long value. Replaces previous values of a key.
Definition: plist.hpp:121
size_t remove(std::string key)
Removes a key from the list and returns the number of elements removed (0 or 1)
Definition: plist.hpp:131
void set(std::string key, std::string value)
Sets the value of a key to a string value. Replaces previous values of a key.
Definition: plist.hpp:117
T * getObject(std::string key)
Retrieves the value of a given key as a class-pointer value (of type T)
Definition: plist.hpp:89
double getDoubleValue()
Retrieves the double value of the property. If no double value was set, returns 0.
Definition: plist.hpp:56
void set(std::string key, double value)
Sets the value of a key to a double value. Replaces previous values of a key.
Definition: plist.hpp:123
void set(std::string key, void *value)
Sets the value of a key to a void* value. Replaces previous values of a key.
Definition: plist.hpp:125
Property(long value)
Constructs a new property with a long value.
Definition: plist.hpp:45
void set(std::string key, std::string &&value)
Sets the value of a key to a string value (moving the content). Replaces previous values of a key.
Definition: plist.hpp:119
A simple list of properties implemented using std::unordered_map
Definition: plist.hpp:76
T * getObjectValue()
Retrieves the void* value casted to the template type. If no void* was set, returns a null-pointer.
Definition: plist.hpp:58
Property(double value)
Constructs a new property with a double value.
Definition: plist.hpp:47
double getDouble(std::string key)
Retrieves the double value of a given key.
Definition: plist.hpp:103