1
0
Fork 0
mirror of https://github.com/juce-framework/JUCE.git synced 2026-02-05 03:50:07 +00:00

Added NamedValueSet::indexOf()

This commit is contained in:
jules 2014-02-10 12:45:12 +00:00
parent 90b573cf42
commit dcbde7b118
2 changed files with 34 additions and 16 deletions

View file

@ -141,7 +141,7 @@ int NamedValueSet::size() const noexcept
return values.size();
}
const var& NamedValueSet::operator[] (const Identifier name) const
const var& NamedValueSet::operator[] (Identifier name) const
{
for (NamedValue* i = values; i != nullptr; i = i->nextListItem)
if (i->name == name)
@ -150,7 +150,7 @@ const var& NamedValueSet::operator[] (const Identifier name) const
return var::null;
}
var NamedValueSet::getWithDefault (const Identifier name, const var& defaultReturnValue) const
var NamedValueSet::getWithDefault (Identifier name, const var& defaultReturnValue) const
{
if (const var* const v = getVarPointer (name))
return *v;
@ -158,7 +158,7 @@ var NamedValueSet::getWithDefault (const Identifier name, const var& defaultRetu
return defaultReturnValue;
}
var* NamedValueSet::getVarPointer (const Identifier name) const noexcept
var* NamedValueSet::getVarPointer (Identifier name) const noexcept
{
for (NamedValue* i = values; i != nullptr; i = i->nextListItem)
if (i->name == name)
@ -168,7 +168,7 @@ var* NamedValueSet::getVarPointer (const Identifier name) const noexcept
}
#if JUCE_COMPILER_SUPPORTS_MOVE_SEMANTICS
bool NamedValueSet::set (const Identifier name, var&& newValue)
bool NamedValueSet::set (Identifier name, var&& newValue)
{
LinkedListPointer<NamedValue>* i = &values;
@ -193,7 +193,7 @@ bool NamedValueSet::set (const Identifier name, var&& newValue)
}
#endif
bool NamedValueSet::set (const Identifier name, const var& newValue)
bool NamedValueSet::set (Identifier name, const var& newValue)
{
LinkedListPointer<NamedValue>* i = &values;
@ -217,12 +217,27 @@ bool NamedValueSet::set (const Identifier name, const var& newValue)
return true;
}
bool NamedValueSet::contains (const Identifier name) const
bool NamedValueSet::contains (Identifier name) const
{
return getVarPointer (name) != nullptr;
}
bool NamedValueSet::remove (const Identifier name)
int NamedValueSet::indexOf (Identifier name) const noexcept
{
int index = 0;
for (NamedValue* i = values; i != nullptr; i = i->nextListItem)
{
if (i->name == name)
return index;
++index;
}
return -1;
}
bool NamedValueSet::remove (Identifier name)
{
LinkedListPointer<NamedValue>* i = &values;
@ -245,7 +260,7 @@ bool NamedValueSet::remove (const Identifier name)
return false;
}
const Identifier NamedValueSet::getName (const int index) const
Identifier NamedValueSet::getName (const int index) const
{
const NamedValue* const v = values[index];
jassert (v != nullptr);

View file

@ -67,46 +67,49 @@ public:
If the name isn't found, this will return a void variant.
@see getProperty
*/
const var& operator[] (const Identifier name) const;
const var& operator[] (Identifier name) const;
/** Tries to return the named value, but if no such value is found, this will
instead return the supplied default value.
*/
var getWithDefault (const Identifier name, const var& defaultReturnValue) const;
var getWithDefault (Identifier name, const var& defaultReturnValue) const;
/** Changes or adds a named value.
@returns true if a value was changed or added; false if the
value was already set the the value passed-in.
*/
bool set (const Identifier name, const var& newValue);
bool set (Identifier name, const var& newValue);
#if JUCE_COMPILER_SUPPORTS_MOVE_SEMANTICS
/** Changes or adds a named value.
@returns true if a value was changed or added; false if the
value was already set the the value passed-in.
*/
bool set (const Identifier name, var&& newValue);
bool set (Identifier name, var&& newValue);
#endif
/** Returns true if the set contains an item with the specified name. */
bool contains (const Identifier name) const;
bool contains (Identifier name) const;
/** Removes a value from the set.
@returns true if a value was removed; false if there was no value
with the name that was given.
*/
bool remove (const Identifier name);
bool remove (Identifier name);
/** Returns the name of the value at a given index.
The index must be between 0 and size() - 1.
*/
const Identifier getName (int index) const;
Identifier getName (int index) const;
/** Returns the value of the item at a given index.
The index must be between 0 and size() - 1.
*/
const var& getValueAt (int index) const;
/** Returns the index of the given name, or -1 if it's not found. */
int indexOf (Identifier name) const noexcept;
/** Removes all values. */
void clear();
@ -117,7 +120,7 @@ public:
Do not use this method unless you really need access to the internal var object
for some reason - for normal reading and writing always prefer operator[]() and set().
*/
var* getVarPointer (const Identifier name) const noexcept;
var* getVarPointer (Identifier name) const noexcept;
//==============================================================================
/** Sets properties to the values of all of an XML element's attributes. */