27 : properties (ignoreCaseOfKeyNames),
28 fallbackProperties (nullptr),
29 ignoreCaseOfKeys (ignoreCaseOfKeyNames)
34 : properties (other.properties),
35 fallbackProperties (other.fallbackProperties),
36 ignoreCaseOfKeys (other.ignoreCaseOfKeys)
42 properties = other.properties;
43 fallbackProperties = other.fallbackProperties;
44 ignoreCaseOfKeys = other.ignoreCaseOfKeys;
58 if (properties.
size() > 0)
68 auto index = properties.getAllKeys().indexOf (keyName, ignoreCaseOfKeys);
71 return properties.getAllValues() [index];
73 return fallbackProperties !=
nullptr ? fallbackProperties->getValue (keyName, defaultValue)
80 auto index = properties.getAllKeys().indexOf (keyName, ignoreCaseOfKeys);
83 return properties.getAllValues() [index].getIntValue();
85 return fallbackProperties !=
nullptr ? fallbackProperties->getIntValue (keyName, defaultValue)
92 auto index = properties.getAllKeys().indexOf (keyName, ignoreCaseOfKeys);
95 return properties.getAllValues()[index].getDoubleValue();
97 return fallbackProperties !=
nullptr ? fallbackProperties->getDoubleValue (keyName, defaultValue)
104 auto index = properties.getAllKeys().indexOf (keyName, ignoreCaseOfKeys);
107 return properties.getAllValues() [index].getIntValue() != 0;
109 return fallbackProperties !=
nullptr ? fallbackProperties->getBoolValue (keyName, defaultValue)
115 return parseXML (
getValue (keyName));
124 auto value = v.toString();
128 if (index < 0 || properties.
getAllValues() [index] != value)
130 properties.
set (keyName, value);
145 properties.
remove (keyName);
160 return properties.getAllKeys().contains (keyName, ignoreCaseOfKeys);
167 for (
int i = 0; i < source.properties.
size(); ++i)
175 fallbackProperties = fallbackProperties_;
180 auto xml = std::make_unique<XmlElement> (nodeName);
184 for (
int i = 0; i < properties.
getAllKeys().size(); ++i)
186 auto e = xml->createNewChildElement (
"VALUE");
187 e->setAttribute (
"name", properties.
getAllKeys()[i]);
199 forEachXmlChildElementWithTagName (xml, e,
"VALUE")
201 if (e->hasAttribute (
"name")
202 && e->hasAttribute (
"val"))
204 properties.
set (e->getStringAttribute (
"name"),
205 e->getStringAttribute (
"val"));
209 if (properties.
size() > 0)
Automatically locks and unlocks a mutex object.
A set of named property values, which can be strings, integers, floating point, etc.
const CriticalSection & getLock() const noexcept
Returns the lock used when reading or writing to this set.
virtual void propertyChanged()
Subclasses can override this to be told when one of the properties has been changed.
void setFallbackPropertySet(PropertySet *fallbackProperties) noexcept
Sets up a second PopertySet that will be used to look up any values that aren't set in this one.
void clear()
Removes all values.
virtual ~PropertySet()
Destructor.
void addAllPropertiesFrom(const PropertySet &source)
This copies all the values from a source PropertySet to this one.
PropertySet(bool ignoreCaseOfKeyNames=false)
Creates an empty PropertySet.
String getValue(StringRef keyName, const String &defaultReturnValue=String()) const noexcept
Returns one of the properties as a string.
double getDoubleValue(StringRef keyName, double defaultReturnValue=0.0) const noexcept
Returns one of the properties as an double.
bool containsKey(StringRef keyName) const noexcept
Returns true if the properties include the given key.
void removeValue(StringRef keyName)
Deletes a property.
int getIntValue(StringRef keyName, int defaultReturnValue=0) const noexcept
Returns one of the properties as an integer.
void setValue(const String &keyName, const var &value)
Sets a named property.
bool getBoolValue(StringRef keyName, bool defaultReturnValue=false) const noexcept
Returns one of the properties as an boolean.
void restoreFromXml(const XmlElement &xml)
Reloads a set of properties that were previously stored as XML.
std::unique_ptr< XmlElement > createXml(const String &nodeName) const
Returns an XML element which encapsulates all the items in this property set.
std::unique_ptr< XmlElement > getXmlValue(StringRef keyName) const
Returns one of the properties as an XML element.
PropertySet & operator=(const PropertySet &other)
Copies another PropertySet over this one.
int indexOf(StringRef stringToLookFor, bool ignoreCase=false, int startIndex=0) const
Searches for a string in the array.
void set(const String &key, const String &value)
Adds or amends a key/value pair.
void clear()
Removes all elements from the array.
void remove(StringRef key)
Removes a string from the array based on its key.
const StringArray & getAllKeys() const noexcept
Returns a list of all keys in the array.
const StringArray & getAllValues() const noexcept
Returns a list of all values in the array.
int size() const noexcept
Returns the number of strings in the array.
A simple class for holding temporary references to a string literal or String.
bool isNotEmpty() const noexcept
Returns true if the string is not empty.
bool isNotEmpty() const noexcept
Returns true if the string contains at least one character.
Used to build a tree of elements representing an XML document.
String toString(const TextFormat &format={}) const
Returns a text version of this XML element.
A variant class, that can be used to hold a range of primitive values.
A struct containing options for formatting the text when representing an XML element as a string.
TextFormat withoutHeader() const
returns a copy of this format with the addDefaultHeader flag set to false.
TextFormat singleLine() const
returns a copy of this format with newLineChars set to nullptr.