All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
te::common::TreeItem Class Reference

This abstract class describes a basic item to be organized in a tree-oriented way. More...

#include <TreeItem.h>

Inheritance diagram for te::common::TreeItem:
te::common::Counted te::map::AbstractLayer te::edit::EditionLayer te::graph::Layer te::map::DataSetAdapterLayer te::map::DataSetLayer te::map::FolderLayer te::map::QueryLayer te::map::RasterLayer te::st::AbstractSTDataSetLayer te::wms::WMSLayer

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 TreeItemPtrgetChild (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...
 
TreeItemgetParent () 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 TreeItemPtroperator[] (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< TreeItemPtrremove (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< TreeItemPtrm_children
 Pointers to the items that are children. More...
 
TreeItemm_parent
 A pointer to the parent node. More...
 

Detailed Description

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.

See also
AbstractLayer

Definition at line 62 of file TreeItem.h.

Member Typedef Documentation

Definition at line 67 of file TreeItem.h.

Definition at line 66 of file TreeItem.h.

Constructor & Destructor Documentation

te::common::TreeItem::TreeItem ( TreeItem parent = 0)
explicit

It initializes a new item having a parent.

Its parent will have this new item attached as its child automatically.

Parameters
parentThe parent item of this new item.

Definition at line 35 of file TreeItem.cpp.

References m_children, and m_parent.

te::common::TreeItem::TreeItem ( const TreeItemPtr parent)
explicit

It initializes a new item having a parent.

Its parent will have this new item attached as its child automatically.

Parameters
parentThe parent item of this new item.

Definition at line 42 of file TreeItem.cpp.

te::common::TreeItem::~TreeItem ( )
virtual

Virtual destructor.

Definition at line 48 of file TreeItem.cpp.

Member Function Documentation

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.

Parameters
childItemThe item to be added as a child of this item.

The children's list will be increased with one element.

Definition at line 91 of file TreeItem.cpp.

void te::common::Counted::attach ( )
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().

te::common::TreeItem::const_iterator te::common::TreeItem::begin ( ) const

It returns the constant iterator associated to the first child of this item.

Returns
The constant iterator associated to the first child of this item.

Definition at line 266 of file TreeItem.cpp.

te::common::TreeItem::iterator te::common::TreeItem::begin ( )

It returns the iterator associated to the first child of this item.

Returns
The iterator associated to the first child of this item.

Definition at line 271 of file TreeItem.cpp.

void te::common::Counted::detach ( )
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.

Definition at line 199 of file TreeItem.cpp.

te::common::TreeItem::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.

Returns
The constant iterator that refers to one past the end of the children of this item.

Definition at line 276 of file TreeItem.cpp.

te::common::TreeItem::iterator te::common::TreeItem::end ( )

It returns the iterator that refers to one past the children of this item.

Returns
The iterator that refers to one past the children of this item.

Definition at line 281 of file TreeItem.cpp.

const te::common::TreeItemPtr & te::common::TreeItem::getChild ( std::size_t  i) const

It returns the n-th child.

Parameters
iThe child index.
Returns
It returns a pointer to the specified child node.

Definition at line 75 of file TreeItem.cpp.

Referenced by te::qt::widgets::MapDisplay::draw(), FolderLayerWriter(), and te::map::AbstractLayer::updateVisibilityOfAncestors().

const std::list< te::common::TreeItemPtr > & te::common::TreeItem::getChildren ( ) const

It returns the children of this tree item.

Returns
It returns the children list of this tree item.

Definition at line 70 of file TreeItem.cpp.

Referenced by te::qt::af::XMLFormatter::format().

std::size_t te::common::TreeItem::getChildrenCount ( ) const

It returns the number of children of this node.

Returns
The number of direct descendants of this node.

Definition at line 183 of file TreeItem.cpp.

Referenced by te::qt::widgets::MapDisplay::draw(), FolderLayerWriter(), and te::map::AbstractLayer::updateVisibilityOfAncestors().

void te::common::TreeItem::getDescendantsCount ( std::size_t &  count) const

It returns the number of nodes that descends from this node.

Parameters
countThe number of nodes that descends from this node.
Note
It will return the number of nodes in a sub-tree. So, if you want to count how many elements there are in a tree, just call this method for the root item.
The count parameter must be initialized with zero.

Definition at line 188 of file TreeItem.cpp.

std::size_t te::common::TreeItem::getIndex ( ) const

It returns the index of this item in the list of children of its parent item.

Returns
The index of this item in the list of children of its parent item. It returns npos, if it has no parent.

Definition at line 218 of file TreeItem.cpp.

te::common::TreeItem * te::common::TreeItem::getParent ( ) const

It returns a pointer to the parent of this node.

Returns
It returns a pointer to the parent node.
Note
You canīt free the memory pointed by the returned pointer; otherwise, the result will be unpredictable.

Definition at line 65 of file TreeItem.cpp.

Referenced by te::map::AbstractLayer::getAncestors(), isSibling(), and te::map::AbstractLayer::updateVisibilityOfAncestors().

bool te::common::TreeItem::hasChildren ( ) const

It returns true if the item has descendants.

Returns
True if the item has descendants.

Definition at line 60 of file TreeItem.cpp.

Referenced by te::map::AbstractLayer::getDescendants().

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.

Parameters
iThe position where the item will be inserted.
itemThe item to be inserted.

The children's list will be increased with one element.

Definition at line 100 of file TreeItem.cpp.

bool te::common::TreeItem::isSibling ( const TreeItem item) const

It checks if the given layer is sibling of this one.

Parameters
layerThe layer to be compared to.
Returns
It returns true if the layers are siblings.

Definition at line 178 of file TreeItem.cpp.

References getParent().

const te::common::TreeItemPtr & te::common::TreeItem::operator[] ( std::size_t  i) const

It returns the n-th child.

Parameters
iThe child index.
Returns
It returns a pointer to the specified child node.

Definition at line 86 of file TreeItem.cpp.

int te::common::Counted::refCount ( )
inlineinherited

Returns the number of references to this object.

Definition at line 99 of file Counted.h.

References te::common::Counted::m_refCount.

te::common::TreeItemPtr te::common::TreeItem::remove ( std::size_t  i)

It removes the i-th child.

Parameters
iThe position of the item to be removed.
Returns
The removed item.

The children's list will be decreased by one element.

Definition at line 116 of file TreeItem.cpp.

Referenced by te::qt::af::Project::remove(), and te::qt::widgets::LayerTreeModel::removeLayerFromParentChildrenList().

std::list< te::common::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.

Parameters
iThe position from where the items will be removed.
countThe number of items to be removed (> 0).
Returns
The list of removed items.

Definition at line 135 of file TreeItem.cpp.

te::common::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.

Parameters
iThe item position where the replace operation will be taken.
childItemThe new child item that will replace the item in the i-th position.
Returns
The item that was replaced.

Definition at line 165 of file TreeItem.cpp.

References insert().

void te::common::TreeItem::setParent ( TreeItem parent)
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.

Parameters
parentThe item to be set as parent of this item.
Note
Avoid calling this method; instead, use add or the constructors.

Definition at line 286 of file TreeItem.cpp.

References m_children.

void te::common::TreeItem::swap ( const TreeItemPtr firstChild,
const TreeItemPtr secondChild 
)

It swaps the position of the given children.

Parameters
firstChildOne of the children.
secondChildThe other child.

Definition at line 240 of file TreeItem.cpp.

void te::common::TreeItem::swap ( const TreeItemPtr sibling)

It swaps this item with its sibling in their parent node.

Parameters
siblingThe sibling to swap.

Definition at line 259 of file TreeItem.cpp.

Member Data Documentation

std::list<TreeItemPtr> te::common::TreeItem::m_children
protected

Pointers to the items that are children.

Definition at line 290 of file TreeItem.h.

Referenced by setParent(), and TreeItem().

TreeItem* te::common::TreeItem::m_parent
protected

A pointer to the parent node.

Definition at line 289 of file TreeItem.h.

Referenced by TreeItem().

const std::size_t te::common::TreeItem::npos
static

A value to indicate no match.

Definition at line 285 of file TreeItem.h.


The documentation for this class was generated from the following files: