diff --git a/modules/juce_core/containers/juce_NamedValueSet.cpp b/modules/juce_core/containers/juce_NamedValueSet.cpp index 5a10cfe14f..e9f0338876 100644 --- a/modules/juce_core/containers/juce_NamedValueSet.cpp +++ b/modules/juce_core/containers/juce_NamedValueSet.cpp @@ -59,7 +59,14 @@ NamedValueSet::NamedValueSet() noexcept {} NamedValueSet::~NamedValueSet() noexcept {} NamedValueSet::NamedValueSet (const NamedValueSet& other) : values (other.values) {} -NamedValueSet::NamedValueSet (NamedValueSet&& other) noexcept : values (static_cast&&> (other.values)) {} + +NamedValueSet::NamedValueSet (NamedValueSet&& other) noexcept + : values (static_cast&&> (other.values)) {} + +NamedValueSet::NamedValueSet (std::initializer_list list) + : values (static_cast&&> (list)) +{ +} NamedValueSet& NamedValueSet::operator= (const NamedValueSet& other) { diff --git a/modules/juce_core/containers/juce_NamedValueSet.h b/modules/juce_core/containers/juce_NamedValueSet.h index 49089ec6b6..d76651d1cc 100644 --- a/modules/juce_core/containers/juce_NamedValueSet.h +++ b/modules/juce_core/containers/juce_NamedValueSet.h @@ -34,23 +34,6 @@ namespace juce class JUCE_API NamedValueSet { 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 */ struct JUCE_API NamedValue @@ -73,6 +56,27 @@ public: 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); + + /** 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* 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 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; @@ -135,6 +141,8 @@ public: /** 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 + 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; diff --git a/modules/juce_data_structures/values/juce_ValueTree.cpp b/modules/juce_data_structures/values/juce_ValueTree.cpp index 90602687eb..a331924ce5 100644 --- a/modules/juce_data_structures/values/juce_ValueTree.cpp +++ b/modules/juce_data_structures/values/juce_ValueTree.cpp @@ -587,12 +587,11 @@ ValueTree::ValueTree (const Identifier& type) : object (new ValueTree::SharedOb } ValueTree::ValueTree (const Identifier& type, - std::initializer_list> properties, + std::initializer_list properties, std::initializer_list subTrees) : ValueTree (type) { - for (auto& prop : properties) - setProperty (prop.first, prop.second, nullptr); + object->properties = NamedValueSet (std::move (properties)); for (auto& tree : subTrees) addChild (tree, -1, nullptr); diff --git a/modules/juce_data_structures/values/juce_ValueTree.h b/modules/juce_data_structures/values/juce_ValueTree.h index cf3533b93c..f389eb5569 100644 --- a/modules/juce_data_structures/values/juce_ValueTree.h +++ b/modules/juce_data_structures/values/juce_ValueTree.h @@ -128,7 +128,7 @@ public: @endverbatim */ ValueTree (const Identifier& type, - std::initializer_list> properties, + std::initializer_list properties, std::initializer_list subTrees = {}); /** Creates a reference to another ValueTree. */