1
0
Fork 0
mirror of https://github.com/juce-framework/JUCE.git synced 2026-01-10 23:44:24 +00:00

Added an initialiser list based ValueTree constructor

This commit is contained in:
Tom Poole 2018-01-19 16:10:35 +00:00
parent e690350df3
commit 4c44d96fdf
2 changed files with 60 additions and 0 deletions

View file

@ -589,6 +589,20 @@ ValueTree::ValueTree (const Identifier& type) : object (new ValueTree::SharedOb
jassert (type.toString().isNotEmpty()); // All objects must be given a sensible type name!
}
#if JUCE_COMPILER_SUPPORTS_INITIALIZER_LISTS
ValueTree::ValueTree (const Identifier& type,
std::initializer_list<std::pair<Identifier, var>> properties,
std::initializer_list<ValueTree> subTrees)
: ValueTree (type)
{
for (auto& prop : properties)
setProperty (prop.first, prop.second, nullptr);
for (auto& tree : subTrees)
addChild (tree, -1, nullptr);
}
#endif
ValueTree::ValueTree (SharedObject* so) noexcept : object (so)
{
}

View file

@ -80,11 +80,57 @@ public:
ValueTree() noexcept;
/** Creates an empty ValueTree with the given type name.
Like an XmlElement, each ValueTree has a type, which you can access with
getType() and hasType().
*/
explicit ValueTree (const Identifier& type);
#if JUCE_COMPILER_SUPPORTS_INITIALIZER_LISTS
/** Creates a value tree from nested lists of properties and ValueTrees.
This code,
@code
ValueTree groups
{ "ParameterGroups", {},
{
{ "Group", {{ "name", "Tone Controls" }},
{
{ "Parameter", {{ "id", "distortion" }, { "value", 0.5 }}},
{ "Parameter", {{ "id", "reverb" }, { "value", 0.5 }}}
}
},
{ "Group", {{ "name", "Other Controls" }},
{
{ "Parameter", {{ "id", "drywet" }, { "value", 0.5 }}},
{ "Parameter", {{ "id", "gain" }, { "value", 0.5 }}}
}
}
}
};
@endcode
produces this tree:
@verbatim
<ParameterGroups>
<Group name="Tone Controls">
<Parameter id="distortion" value="0.5"/>
<Parameter id="reverb" value="0.5"/>
</Group>
<Group name="Other Controls">
<Parameter id="drywet" value="0.5"/>
<Parameter id="gain" value="0.5"/>
</Group>
</ParameterGroups>
@endverbatim
*/
ValueTree (const Identifier& type,
std::initializer_list<std::pair<Identifier, var>> properties,
std::initializer_list<ValueTree> subTrees = {});
#endif
/** Creates a reference to another ValueTree. */
ValueTree (const ValueTree&) noexcept;