mirror of
https://github.com/juce-framework/JUCE.git
synced 2026-01-10 23:44:24 +00:00
Added begin/end iterator methods for ValueTree, for handy range-based-for loops over its children
This commit is contained in:
parent
ea7677970c
commit
1942e3d0c1
2 changed files with 42 additions and 0 deletions
|
|
@ -858,6 +858,29 @@ ValueTree ValueTree::getChild (int index) const
|
|||
: static_cast<SharedObject*> (nullptr));
|
||||
}
|
||||
|
||||
ValueTree::Iterator::Iterator (const ValueTree& v, bool isEnd) noexcept
|
||||
: internal (v.object != nullptr ? (isEnd ? v.object->children.end() : v.object->children.begin()) : nullptr)
|
||||
{}
|
||||
|
||||
ValueTree::Iterator& ValueTree::Iterator::operator++() noexcept
|
||||
{
|
||||
internal = static_cast<SharedObject**> (internal) + 1;
|
||||
return *this;
|
||||
}
|
||||
|
||||
bool ValueTree::Iterator::operator!= (const Iterator& other) const noexcept
|
||||
{
|
||||
return internal != other.internal;
|
||||
}
|
||||
|
||||
ValueTree ValueTree::Iterator::operator*() const
|
||||
{
|
||||
return ValueTree (*static_cast<SharedObject**> (internal));
|
||||
}
|
||||
|
||||
ValueTree::Iterator ValueTree::begin() const noexcept { return Iterator (*this, false); }
|
||||
ValueTree::Iterator ValueTree::end() const noexcept { return Iterator (*this, true); }
|
||||
|
||||
ValueTree ValueTree::getChildWithName (const Identifier& type) const
|
||||
{
|
||||
return object != nullptr ? object->getChildWithName (type) : ValueTree();
|
||||
|
|
|
|||
|
|
@ -328,6 +328,25 @@ public:
|
|||
*/
|
||||
ValueTree getSibling (int delta) const noexcept;
|
||||
|
||||
//==============================================================================
|
||||
struct Iterator
|
||||
{
|
||||
Iterator (const ValueTree&, bool isEnd) noexcept;
|
||||
Iterator& operator++() noexcept;
|
||||
|
||||
bool operator!= (const Iterator&) const noexcept;
|
||||
ValueTree operator*() const;
|
||||
|
||||
private:
|
||||
void* internal;
|
||||
};
|
||||
|
||||
/** Returns a start iterator for the children in this tree. */
|
||||
Iterator begin() const noexcept;
|
||||
|
||||
/** Returns an end iterator for the children in this tree. */
|
||||
Iterator end() const noexcept;
|
||||
|
||||
//==============================================================================
|
||||
/** Creates an XmlElement that holds a complete image of this node and all its children.
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue