62 return !m_children.empty();
77 assert(i < m_children.size());
93 assert(childItem.get());
95 m_children.push_back(childItem);
97 childItem->m_parent =
this;
102 assert(i <= m_children.size());
107 childItem->m_parent =
this;
113 m_children.insert(it, childItem);
118 assert(i < m_children.size());
128 m_children.erase(it);
130 childItem.get()->m_parent = 0;
137 assert(i < m_children.size());
139 assert((i + count - 1) < m_children.size());
143 std::advance(firstIt, i);
147 std::advance(lastIt, count);
149 std::list<TreeItemPtr> removedItems;
151 for(
iterator it = firstIt; it != lastIt; ++it)
157 removedItems.push_back(childItem);
160 m_children.erase(firstIt, lastIt);
167 assert(i < m_children.size());
171 replacedItem->disconnect();
185 return m_children.size();
190 count += m_children.size();
195 item->getDescendantsCount(count);
204 int index = getIndex();
211 std::advance(it, index);
213 m_parent->m_children.erase(it);
223 const std::list<TreeItemPtr>& children = m_parent->m_children;
227 for(
const_iterator it = children.begin(); it != children.end(); ++it)
231 if(childItem.get() ==
this)
242 assert(firstChild->getParent() ==
this && secondChild->getParent() ==
this);
244 std::size_t fidx = firstChild->getIndex();
245 std::size_t sidx = secondChild->getIndex();
249 std::advance(firstIt, fidx);
253 std::advance(secondIt, sidx);
255 *firstIt = secondChild;
256 *secondIt = firstChild;
263 m_parent->swap(
this, sibling);
268 return m_children.begin();
273 return m_children.begin();
278 return m_children.end();
283 return m_children.end();
288 if(m_parent == parent)
const std::list< TreeItemPtr > & getChildren() const
It returns the children of this tree item.
const TreeItemPtr & getChild(std::size_t i) const
It returns the n-th child.
std::size_t getChildrenCount() const
It returns the number of children of this node.
void swap(const TreeItemPtr &firstChild, const TreeItemPtr &secondChild)
It swaps the position of the given children.
bool isSibling(const TreeItem *item) const
It checks if the given layer is sibling of this one.
This abstract class describes a basic item to be organized in a tree-oriented way.
const TreeItemPtr & operator[](std::size_t i) const
It returns the n-th child.
bool hasChildren() const
It returns true if the item has descendants.
TreeItem * m_parent
A pointer to the parent node.
virtual ~TreeItem()
Virtual destructor.
std::size_t getIndex() const
It returns the index of this item in the list of children of its parent item.
void add(const TreeItemPtr &childItem)
It adds (appends) the item to the end of the children's list.
TreeItemPtr replace(std::size_t i, const TreeItemPtr &childItem)
It replaces the child item at the given position by the new one. The replaced item will be disconnect...
TreeItem(TreeItem *parent=0)
It initializes a new item having a parent.
void setParent(TreeItem *parent)
It sets the parent of this item to the specified one. Don't use this method if you are not sure how t...
A base class for data organized as a tree.
std::list< TreeItemPtr >::iterator iterator
boost::intrusive_ptr< TreeItem > TreeItemPtr
mydialect insert("+", new te::da::BinaryOpEncoder("+"))
void disconnect()
It disconnects this item from its parent, if it has one.
TreeItemPtr remove(std::size_t i)
It removes the i-th child.
const_iterator begin() const
It returns the constant iterator associated to the first child of this item.
const_iterator end() const
It returns the constant iterator that refers to one past the end of the children of this item...
std::list< TreeItemPtr > m_children
Pointers to the items that are children.
TreeItem * getParent() const
It returns a pointer to the parent of this node.
static const std::size_t npos
A value to indicate no match.
void getDescendantsCount(std::size_t &count) const
It returns the number of nodes that descends from this node.
std::list< TreeItemPtr >::const_iterator const_iterator
void insert(std::size_t i, const TreeItemPtr &childItem)
It inserts an item in the informed position.