1
0
Fork 0
mirror of https://github.com/juce-framework/JUCE.git synced 2026-01-19 01:04:20 +00:00

Added begin/end iterator methods for ValueTree, for handy range-based-for loops over its children

This commit is contained in:
jules 2016-08-23 09:39:12 +01:00
parent ea7677970c
commit 1942e3d0c1
2 changed files with 42 additions and 0 deletions

View file

@ -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();