This abstract class describes a basic item to be organized in a tree-oriented way. More...
#include <TreeItem.h>
Public Types | |
typedef std::list< TreeItemPtr >::const_iterator | const_iterator |
typedef std::list< TreeItemPtr >::iterator | iterator |
Public Member Functions | |
void | add (const TreeItemPtr &childItem) |
It adds (appends) the item to the end of the children's list. More... | |
void | attach () |
Increases the number of references to this object. More... | |
const_iterator | begin () const |
It returns the constant iterator associated to the first child of this item. More... | |
iterator | begin () |
It returns the iterator associated to the first child of this item. More... | |
void | detach () |
Decreases the number of references to this object. Destroy it if there are no more references to it. More... | |
void | disconnect () |
It disconnects this item from its parent, if it has one. More... | |
const_iterator | end () const |
It returns the constant iterator that refers to one past the end of the children of this item. More... | |
iterator | end () |
It returns the iterator that refers to one past the children of this item. More... | |
const TreeItemPtr & | getChild (std::size_t i) const |
It returns the n-th child. More... | |
const std::list< TreeItemPtr > & | getChildren () const |
It returns the children of this tree item. More... | |
std::size_t | getChildrenCount () const |
It returns the number of children of this node. More... | |
void | getDescendantsCount (std::size_t &count) const |
It returns the number of nodes that descends from this node. More... | |
std::size_t | getIndex () const |
It returns the index of this item in the list of children of its parent item. More... | |
TreeItem * | getParent () const |
It returns a pointer to the parent of this node. More... | |
bool | hasChildren () const |
It returns true if the item has descendants. More... | |
void | insert (std::size_t i, const TreeItemPtr &childItem) |
It inserts an item in the informed position. More... | |
bool | isSibling (const TreeItem *item) const |
It checks if the given layer is sibling of this one. More... | |
const TreeItemPtr & | operator[] (std::size_t i) const |
It returns the n-th child. More... | |
int | refCount () |
Returns the number of references to this object. More... | |
TreeItemPtr | remove (std::size_t i) |
It removes the i-th child. More... | |
std::list< TreeItemPtr > | remove (std::size_t i, std::size_t count) |
It removes from the given position a certain number of items as children of this item. The items to be removed will be disconnected from this item. More... | |
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 disconnected from this item. More... | |
void | swap (const TreeItemPtr &firstChild, const TreeItemPtr &secondChild) |
It swaps the position of the given children. More... | |
void | swap (const TreeItemPtr &sibling) |
It swaps this item with its sibling in their parent node. More... | |
TreeItem (TreeItem *parent=0) | |
It initializes a new item having a parent. More... | |
TreeItem (const TreeItemPtr &parent) | |
It initializes a new item having a parent. More... | |
virtual | ~TreeItem () |
Virtual destructor. More... | |
Static Public Attributes | |
static const std::size_t | npos |
A value to indicate no match. More... | |
Protected Member Functions | |
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 to handle all the pointers involved in this operation. More... | |
Protected Attributes | |
std::list< TreeItemPtr > | m_children |
Pointers to the items that are children. More... | |
TreeItem * | m_parent |
A pointer to the parent node. More... | |
This abstract class describes a basic item to be organized in a tree-oriented way.
A tree item can have several descendants (children) and only one parent. This data structure will clear all the memory used by the items.
This implementation is based in the counted pattern, allowing to share the ownership of the items.
Definition at line 62 of file TreeItem.h.
typedef std::list<TreeItemPtr>::const_iterator te::common::TreeItem::const_iterator |
Definition at line 67 of file TreeItem.h.
typedef std::list<TreeItemPtr>::iterator te::common::TreeItem::iterator |
Definition at line 66 of file TreeItem.h.
|
explicit |
It initializes a new item having a parent.
Its parent will have this new item attached as its child automatically.
parent | The parent item of this new item. |
|
explicit |
It initializes a new item having a parent.
Its parent will have this new item attached as its child automatically.
parent | The parent item of this new item. |
|
virtual |
Virtual destructor.
void te::common::TreeItem::add | ( | const TreeItemPtr & | childItem | ) |
It adds (appends) the item to the end of the children's list.
If the child item already has a parent, it will be disconnected from it and will be attached to this one.
childItem | The item to be added as a child of this item. |
The children's list will be increased with one element.
|
inlineinherited |
Increases the number of references to this object.
Definition at line 88 of file Counted.h.
References te::common::Counted::m_refCount.
Referenced by te::common::intrusive_ptr_add_ref().
const_iterator te::common::TreeItem::begin | ( | ) | const |
It returns the constant iterator associated to the first child of this item.
iterator te::common::TreeItem::begin | ( | ) |
It returns the iterator associated to the first child of this item.
|
inlineinherited |
Decreases the number of references to this object. Destroy it if there are no more references to it.
Definition at line 93 of file Counted.h.
References te::common::Counted::m_refCount.
Referenced by te::common::intrusive_ptr_release().
void te::common::TreeItem::disconnect | ( | ) |
It disconnects this item from its parent, if it has one.
const_iterator te::common::TreeItem::end | ( | ) | const |
It returns the constant iterator that refers to one past the end of the children of this item.
iterator te::common::TreeItem::end | ( | ) |
It returns the iterator that refers to one past the children of this item.
const TreeItemPtr& te::common::TreeItem::getChild | ( | std::size_t | i | ) | const |
It returns the n-th child.
i | The child index. |
const std::list<TreeItemPtr>& te::common::TreeItem::getChildren | ( | ) | const |
It returns the children of this tree item.
std::size_t te::common::TreeItem::getChildrenCount | ( | ) | const |
It returns the number of children of this node.
void te::common::TreeItem::getDescendantsCount | ( | std::size_t & | count | ) | const |
It returns the number of nodes that descends from this node.
count | The number of nodes that descends from this node. |
std::size_t te::common::TreeItem::getIndex | ( | ) | const |
It returns the index of this item in the list of children of its parent item.
TreeItem* te::common::TreeItem::getParent | ( | ) | const |
It returns a pointer to the parent of this node.
bool te::common::TreeItem::hasChildren | ( | ) | const |
It returns true if the item has descendants.
void te::common::TreeItem::insert | ( | std::size_t | i, |
const TreeItemPtr & | childItem | ||
) |
It inserts an item in the informed position.
If the item has a parent, it will be disconnected from it and will be attached to this one.
i | The position where the item will be inserted. |
item | The item to be inserted. |
The children's list will be increased with one element.
bool te::common::TreeItem::isSibling | ( | const TreeItem * | item | ) | const |
It checks if the given layer is sibling of this one.
layer | The layer to be compared to. |
const TreeItemPtr& te::common::TreeItem::operator[] | ( | std::size_t | i | ) | const |
It returns the n-th child.
i | The child index. |
|
inlineinherited |
Returns the number of references to this object.
Definition at line 99 of file Counted.h.
References te::common::Counted::m_refCount.
TreeItemPtr te::common::TreeItem::remove | ( | std::size_t | i | ) |
It removes the i-th child.
i | The position of the item to be removed. |
The children's list will be decreased by one element.
std::list<TreeItemPtr> te::common::TreeItem::remove | ( | std::size_t | i, |
std::size_t | count | ||
) |
It removes from the given position a certain number of items as children of this item. The items to be removed will be disconnected from this item.
i | The position from where the items will be removed. |
count | The number of items to be removed (> 0). |
TreeItemPtr te::common::TreeItem::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 disconnected from this item.
i | The item position where the replace operation will be taken. |
childItem | The new child item that will replace the item in the i-th position. |
|
protected |
It sets the parent of this item to the specified one. Don't use this method if you are not sure how to handle all the pointers involved in this operation.
parent | The item to be set as parent of this item. |
void te::common::TreeItem::swap | ( | const TreeItemPtr & | firstChild, |
const TreeItemPtr & | secondChild | ||
) |
It swaps the position of the given children.
firstChild | One of the children. |
secondChild | The other child. |
void te::common::TreeItem::swap | ( | const TreeItemPtr & | sibling | ) |
It swaps this item with its sibling in their parent node.
sibling | The sibling to swap. |
|
protected |
Pointers to the items that are children.
Definition at line 290 of file TreeItem.h.
|
protected |
A pointer to the parent node.
Definition at line 289 of file TreeItem.h.
|
static |
A value to indicate no match.
Definition at line 285 of file TreeItem.h.