added range loop based layout nodes traversal

This commit is contained in:
2017-01-27 19:26:45 +00:00
parent baaade6050
commit d413e49821
2 changed files with 38 additions and 33 deletions

View File

@@ -168,4 +168,37 @@ public:
void load(const char* path);
void load_internal(const tinyxml2::XMLElement* x_node);
void reload();
class iterator
{
std::stack<Node*> m_nodes;
Node* m_current;
public:
iterator(Node* root)
{
m_current = root;
if (root)
m_nodes.push(root);
}
iterator& operator++()
{
m_nodes.pop();
for (auto& c : m_current->children)
m_nodes.push(&c);
m_current = m_nodes.size() ? m_nodes.top() : nullptr;
return *this;
}
Node& operator*() { return *m_current; }
Node* operator->() { return m_current; }
bool operator==(const iterator& rhs) { return m_current == rhs.m_current; }
bool operator!=(const iterator& rhs) { return m_current != rhs.m_current; }
};
iterator begin()
{
return this;
}
iterator end()
{
return nullptr;
}
};