Class sdm::Tree

template <typename T>

Class List > sdm > Tree

Generic Tree class.More...

  • #include <tree.hpp>

Inherits the following classes: std::inheritable_enable_shared_from_this

Public Types

Type Name
typedef T value_type

Public Functions

Type Name
Tree ()
Default constructor object.
Tree (number max_depth)
Construct a new Tree object (the origin)
Tree (std::shared_ptr< Tree< T >> parent, const T & data)
Construct a new Tree object.
void addChild (const T & child_item)
void addChildren (const std::vector< T > & child_items)
std::shared_ptr< Tree< T > > getChild (const T & child_item) const
std::vector< std::shared_ptr< Tree< T > > > getChildren () const
const T & getData () const
number getDepth () const
number getMaxDepth () const
number getNumChildren () const
std::shared_ptr< Tree< T > > getOrigin ()
std::shared_ptr< Tree< T > > getParent () const
std::shared_ptr< Tree< T > > getptr ()
bool isOrigin () const
void serialize (Archive & archive, const unsigned int)
void setMaxDepth (number) const
std::string str () const
virtual ~Tree ()
Destructor of Tree (that's bad).

Public Functions inherited from std::inheritable_enable_shared_from_this

See std::inheritable_enable_shared_from_this

Type Name
std::shared_ptr< Down > downcasted_shared_from_this ()
std::shared_ptr< T > shared_from_this ()

Public Functions inherited from std::MultipleInheritableEnableSharedFromThis

See std::MultipleInheritableEnableSharedFromThis

Type Name
virtual ~MultipleInheritableEnableSharedFromThis ()

Protected Attributes

Type Name
std::map< T, std::shared_ptr< Tree< T > > > children_
mapping of items to successor trees
T data_
data of the current node
number depth_ = = 0
depth of the tree
bool is_origin = = false
number max_depth_ = = std::numeric_limits<number>::max()
maximum length of the tree
std::weak_ptr< Tree< T > > origin_
the root of the tree
std::weak_ptr< Tree< T > > parent_
the parent node

Detailed Description

Template parameters:

  • T the type of the data contains in each node

Basic Usage

std::shared_ptr<Tree<int>> tree = std::make_shared<Tree<int>>(4);
tree->addChildren({3, 4, 5});
tree->getChild(3)->addChildren({9, 8, 7, 6});
tree->getChild(5)->addChildren({1, 3});

Public Types Documentation

typedef value_type

using sdm::Tree< T >::value_type =  T;

Public Functions Documentation

function Tree [1/3]

sdm::Tree::Tree () 

function Tree [2/3]

sdm::Tree::Tree (
    number max_depth
) 

Parameters:

  • data the value of the origin

function Tree [3/3]

sdm::Tree::Tree (
    std::shared_ptr< Tree < T >> parent,
    const T & data
) 

Parameters:

  • parent the parent
  • data the value of the node
  • backup if true, save the new tree as a child for its parent

function addChild

void sdm::Tree::addChild (
    const T & child_item
) 

function addChildren

void sdm::Tree::addChildren (
    const std::vector< T > & child_items
) 

function getChild

std::shared_ptr< Tree < T > > sdm::Tree::getChild (
    const T & child_item
) const

function getChildren

std::vector< std::shared_ptr< Tree < T > > > sdm::Tree::getChildren () const

function getData

const T & sdm::Tree::getData () const

function getDepth

number sdm::Tree::getDepth () const

function getMaxDepth

number sdm::Tree::getMaxDepth () const

function getNumChildren

number sdm::Tree::getNumChildren () const

function getOrigin

std::shared_ptr< Tree < T > > sdm::Tree::getOrigin () 

function getParent

std::shared_ptr< Tree < T > > sdm::Tree::getParent () const

function getptr

std::shared_ptr< Tree < T > > sdm::Tree::getptr () 

function isOrigin

bool sdm::Tree::isOrigin () const

function serialize

template<class Archive class Archive>
void sdm::Tree::serialize (
    Archive & archive,
    const unsigned int
) 

function setMaxDepth

void sdm::Tree::setMaxDepth (
    number
) const

function str

std::string sdm::Tree::str () const

function ~Tree

virtual sdm::Tree::~Tree () 

This destructor recursively all, children and the item from the tree, bottom up.

Protected Attributes Documentation

variable children_

std::map<T, std::shared_ptr<Tree<T> > > sdm::Tree< T >::children_;

variable data_

T sdm::Tree< T >::data_;

variable depth_

number sdm::Tree< T >::depth_;

variable is_origin

bool sdm::Tree< T >::is_origin;

variable max_depth_

number sdm::Tree< T >::max_depth_;

variable origin_

std::weak_ptr<Tree<T> > sdm::Tree< T >::origin_;

variable parent_

std::weak_ptr<Tree<T> > sdm::Tree< T >::parent_;

Friends Documentation

friend operator<<

inline friend std::ostream & sdm::Tree::operator<< (
    std::ostream & os,
    Tree < T > & tree
) 

The documentation for this class was generated from the following file src/sdm/utils/struct/tree.hpp