26NamedValueSet::NamedValue::NamedValue() noexcept {}
27NamedValueSet::NamedValue::~NamedValue() noexcept {}
29NamedValueSet::NamedValue::NamedValue (
const Identifier& n,
const var& v) : name (n), value (v) {}
30NamedValueSet::NamedValue::NamedValue (
const NamedValue& other) : NamedValue (other.name, other.value) {}
32NamedValueSet::NamedValue::NamedValue (NamedValue&& other) noexcept
33 : NamedValue (std::move (other.name),
34 std::move (other.value))
37NamedValueSet::NamedValue::NamedValue (
const Identifier& n, var&& v) noexcept
38 : name (n), value (std::move (v))
42NamedValueSet::NamedValue::NamedValue (Identifier&& n, var&& v) noexcept
43 : name (std::move (n)),
47NamedValueSet::NamedValue& NamedValueSet::NamedValue::operator= (NamedValue&& other)
noexcept
49 name = std::move (other.name);
50 value = std::move (other.value);
54bool NamedValueSet::NamedValue::operator== (
const NamedValue& other)
const noexcept {
return name == other.name && value == other.value; }
55bool NamedValueSet::NamedValue::operator!= (
const NamedValue& other)
const noexcept {
return ! operator== (other); }
58NamedValueSet::NamedValueSet() noexcept {}
59NamedValueSet::~NamedValueSet() noexcept {}
61NamedValueSet::NamedValueSet (
const NamedValueSet& other) : values (other.values) {}
64 : values (std::move (other.values)) {}
67 : values (std::move (list))
74 values = other.values;
78NamedValueSet& NamedValueSet::operator= (NamedValueSet&& other)
noexcept
80 other.values.swapWith (values);
91 auto num = values.size();
93 if (num != other.values.size())
96 for (
int i = 0; i < num; ++i)
99 if (values.getReference(i).name == other.values.getReference(i).name)
101 if (values.getReference(i).value != other.values.getReference(i).value)
107 for (
int j = i; j < num; ++j)
109 if (
auto* otherVal = other.getVarPointer (values.getReference(j).name))
110 if (values.getReference(j).value == *otherVal)
123bool NamedValueSet::operator!= (
const NamedValueSet& other)
const noexcept {
return ! operator== (other); }
128static const var& getNullVarRef() noexcept
136 if (
auto* v = getVarPointer (name))
139 return getNullVarRef();
147 return defaultReturnValue;
152 for (
auto& i : values)
161 for (
auto& i : values)
172 if (v->equalsWithSameType (newValue))
175 *v = std::move (newValue);
179 values.add ({ name, std::move (newValue) });
187 if (v->equalsWithSameType (newValue))
194 values.add ({ name, newValue });
200 return getVarPointer (name) !=
nullptr;
205 auto numValues = values.size();
207 for (
int i = 0; i < numValues; ++i)
208 if (values.getReference(i).name == name)
216 auto numValues = values.size();
218 for (
int i = 0; i < numValues; ++i)
220 if (values.getReference(i).name == name)
232 if (isPositiveAndBelow (index, values.size()))
233 return values.getReference (index).name;
241 if (isPositiveAndBelow (index, values.size()))
242 return values.getReference (index).value;
245 return getNullVarRef();
250 if (isPositiveAndBelow (index, values.size()))
251 return &(values.getReference (index).value);
258 if (isPositiveAndBelow (index, values.size()))
259 return &(values.getReference (index).value);
268 for (
auto* att = xml.attributes.
get(); att !=
nullptr; att = att->nextListItem)
270 if (att->name.toString().startsWith (
"base64:"))
276 values.add ({ att->name.toString().substring (7),
var (mb) });
281 values.add ({ att->name,
var (att->value) });
287 for (
auto& i : values)
289 if (
auto* mb = i.value.getBinaryData())
291 xml.
setAttribute (
"base64:" + i.name.toString(), mb->toBase64Encoding());
296 jassert (! i.value.isObject());
297 jassert (! i.value.isMethod());
298 jassert (! i.value.isArray());
Represents a string identifier, designed for accessing properties by name.
ObjectType * get() const noexcept
Returns the item which this pointer points to.
A class to hold a resizable block of raw data.
bool fromBase64Encoding(StringRef encodedString)
Takes a string created by MemoryBlock::toBase64Encoding() and extracts the original data.
Holds a set of named var objects.
var * getVarPointerAt(int index) noexcept
Returns the value of the item at a given index.
bool set(const Identifier &name, const var &newValue)
Changes or adds a named value.
bool contains(const Identifier &name) const noexcept
Returns true if the set contains an item with the specified name.
bool remove(const Identifier &name)
Removes a value from the set.
int indexOf(const Identifier &name) const noexcept
Returns the index of the given name, or -1 if it's not found.
const var & getValueAt(int index) const noexcept
Returns the value of the item at a given index.
void clear()
Removes all values.
bool isEmpty() const noexcept
Returns true if the set is empty.
bool operator==(const NamedValueSet &) const noexcept
Two NamedValueSets are considered equal if they contain all the same key/value pairs,...
NamedValueSet() noexcept
Creates an empty set.
Identifier getName(int index) const noexcept
Returns the name of the value at a given index.
var getWithDefault(const Identifier &name, const var &defaultReturnValue) const
Tries to return the named value, but if no such value is found, this will instead return the supplied...
int size() const noexcept
Returns the total number of values that the set contains.
const var & operator[](const Identifier &name) const noexcept
Returns the value of a named item.
var * getVarPointer(const Identifier &name) noexcept
Returns a pointer to the var that holds a named value, or null if there is no value with this name.
void copyToXmlAttributes(XmlElement &xml) const
Sets attributes in an XML element corresponding to each of this object's properties.
void setFromXmlAttributes(const XmlElement &xml)
Sets properties to the values of all of an XML element's attributes.
Used to build a tree of elements representing an XML document.
void setAttribute(const Identifier &attributeName, const String &newValue)
Adds a named attribute to the element.
A variant class, that can be used to hold a range of primitive values.