Browse Source

Added a handy initialiser-list based constructor for NamedValueSet

tags/2021-05-28
jules 7 years ago
parent
commit
e2427065e0
4 changed files with 36 additions and 22 deletions
  1. +8
    -1
      modules/juce_core/containers/juce_NamedValueSet.cpp
  2. +25
    -17
      modules/juce_core/containers/juce_NamedValueSet.h
  3. +2
    -3
      modules/juce_data_structures/values/juce_ValueTree.cpp
  4. +1
    -1
      modules/juce_data_structures/values/juce_ValueTree.h

+ 8
- 1
modules/juce_core/containers/juce_NamedValueSet.cpp View File

@@ -59,7 +59,14 @@ NamedValueSet::NamedValueSet() noexcept {}
NamedValueSet::~NamedValueSet() noexcept {} NamedValueSet::~NamedValueSet() noexcept {}
NamedValueSet::NamedValueSet (const NamedValueSet& other) : values (other.values) {} NamedValueSet::NamedValueSet (const NamedValueSet& other) : values (other.values) {}
NamedValueSet::NamedValueSet (NamedValueSet&& other) noexcept : values (static_cast<Array<NamedValue>&&> (other.values)) {}
NamedValueSet::NamedValueSet (NamedValueSet&& other) noexcept
: values (static_cast<Array<NamedValue>&&> (other.values)) {}
NamedValueSet::NamedValueSet (std::initializer_list<NamedValue> list)
: values (static_cast<std::initializer_list<NamedValue>&&> (list))
{
}
NamedValueSet& NamedValueSet::operator= (const NamedValueSet& other) NamedValueSet& NamedValueSet::operator= (const NamedValueSet& other)
{ {


+ 25
- 17
modules/juce_core/containers/juce_NamedValueSet.h View File

@@ -34,23 +34,6 @@ namespace juce
class JUCE_API NamedValueSet class JUCE_API NamedValueSet
{ {
public: public:
/** Creates an empty set. */
NamedValueSet() noexcept;
NamedValueSet (const NamedValueSet&);
NamedValueSet (NamedValueSet&&) noexcept;
NamedValueSet& operator= (const NamedValueSet&);
NamedValueSet& operator= (NamedValueSet&&) noexcept;
/** Destructor. */
~NamedValueSet() noexcept;
/** Two NamedValueSets are considered equal if they contain all the same key/value
pairs, regardless of the order.
*/
bool operator== (const NamedValueSet&) const noexcept;
bool operator!= (const NamedValueSet&) const noexcept;
//============================================================================== //==============================================================================
/** Structure for a named var object */ /** Structure for a named var object */
struct JUCE_API NamedValue struct JUCE_API NamedValue
@@ -73,6 +56,27 @@ public:
var value; var value;
}; };
//==============================================================================
/** Creates an empty set. */
NamedValueSet() noexcept;
NamedValueSet (const NamedValueSet&);
NamedValueSet (NamedValueSet&&) noexcept;
NamedValueSet& operator= (const NamedValueSet&);
NamedValueSet& operator= (NamedValueSet&&) noexcept;
/** Creates a NamedValueSet from a list of names and properties. */
NamedValueSet (std::initializer_list<NamedValue>);
/** Destructor. */
~NamedValueSet() noexcept;
/** Two NamedValueSets are considered equal if they contain all the same key/value
pairs, regardless of the order.
*/
bool operator== (const NamedValueSet&) const noexcept;
bool operator!= (const NamedValueSet&) const noexcept;
const NamedValueSet::NamedValue* begin() const noexcept { return values.begin(); } const NamedValueSet::NamedValue* begin() const noexcept { return values.begin(); }
const NamedValueSet::NamedValue* end() const noexcept { return values.end(); } const NamedValueSet::NamedValue* end() const noexcept { return values.end(); }
@@ -125,6 +129,8 @@ public:
Do not use this method unless you really need access to the internal var object 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(). for some reason - for normal reading and writing always prefer operator[]() and set().
Also note that the pointer returned may become invalid as soon as any subsequent
methods are called on the NamedValueSet.
*/ */
var* getVarPointer (const Identifier& name) const noexcept; var* getVarPointer (const Identifier& name) const noexcept;
@@ -135,6 +141,8 @@ public:
/** Returns the value of the item at a given index. /** Returns the value of the item at a given index.
The index must be between 0 and size() - 1, or this will return a nullptr The index must be between 0 and size() - 1, or this will return a nullptr
Also note that the pointer returned may become invalid as soon as any subsequent
methods are called on the NamedValueSet.
*/ */
var* getVarPointerAt (int index) const noexcept; var* getVarPointerAt (int index) const noexcept;


+ 2
- 3
modules/juce_data_structures/values/juce_ValueTree.cpp View File

@@ -587,12 +587,11 @@ ValueTree::ValueTree (const Identifier& type) : object (new ValueTree::SharedOb
} }
ValueTree::ValueTree (const Identifier& type, ValueTree::ValueTree (const Identifier& type,
std::initializer_list<std::pair<Identifier, var>> properties,
std::initializer_list<NamedValueSet::NamedValue> properties,
std::initializer_list<ValueTree> subTrees) std::initializer_list<ValueTree> subTrees)
: ValueTree (type) : ValueTree (type)
{ {
for (auto& prop : properties)
setProperty (prop.first, prop.second, nullptr);
object->properties = NamedValueSet (std::move (properties));
for (auto& tree : subTrees) for (auto& tree : subTrees)
addChild (tree, -1, nullptr); addChild (tree, -1, nullptr);


+ 1
- 1
modules/juce_data_structures/values/juce_ValueTree.h View File

@@ -128,7 +128,7 @@ public:
@endverbatim @endverbatim
*/ */
ValueTree (const Identifier& type, ValueTree (const Identifier& type,
std::initializer_list<std::pair<Identifier, var>> properties,
std::initializer_list<NamedValueSet::NamedValue> properties,
std::initializer_list<ValueTree> subTrees = {}); std::initializer_list<ValueTree> subTrees = {});
/** Creates a reference to another ValueTree. */ /** Creates a reference to another ValueTree. */


Loading…
Cancel
Save