Bridges-C++  3.4.2
Bridges(C++ API)
Public Member Functions | List of all members
bridges::datastructure::TreeElement< E > Class Template Reference

#include <TreeElement.h>

Inheritance diagram for bridges::datastructure::TreeElement< E >:
bridges::datastructure::Element< E > bridges::datastructure::DataStructure bridges::datastructure::BinTreeElement< E > bridges::datastructure::BSTElement< K, E > bridges::datastructure::AVLTreeElement< K, E > bridges::datastructure::KdTreeElement< K, E >

Detailed Description

template<typename E>
class bridges::datastructure::TreeElement< E >

This class can be used to create tree elements, derived from Element.

This class can be used to create tree elements, with subtrees

Generic Parameters: E the application data type

Author
Kalpathi Subramanian, Dakota Carmer
Date
6/12/15, 7/12/19, 12/28/20

There is a tutorial about Trees : https://bridgesuncc.github.io/tutorials/Tree.html

Public Member Functions

 TreeElement (const E &e=E(), const string &lab=string())
 Construct a TreeElement from given values. More...
 
virtual const string getDStype () const override
 Get the data structure name. More...
 
vector< TreeElement * > & getChildren ()
 Get the children of this node. More...
 
const vector< TreeElement * > & getChildren () const
 Get the children of this node. More...
 
TreeElementgetChild (const int &n)
 Gets the nth child of this node. More...
 
const TreeElementgetChild (const int &n) const
 Gets the nth child of this node - constant version. More...
 
void addChild (TreeElement *child)
 Adds a child to children. More...
 
void setChild (const size_t &index, TreeElement *kid)
 Sets child at index to "kid". More...
 
- Public Member Functions inherited from bridges::datastructure::Element< E >
 Element (const E &val=E(), const string &lab=string())
 
 Element (const Element &e)
 
Elementoperator= (const Element &e)
 
E & operator= (E const &e)
 
virtual ~Element ()
 
ElementVisualizergetVisualizer ()
 Get the element visualizer object. More...
 
const ElementVisualizergetVisualizer () const
 Get the element visualizer object - constant version. More...
 
LinkVisualizergetLinkVisualizer (const Element *el)
 Returns the LinkVisualizer of element. More...
 
LinkVisualizergetLinkVisualizer (const Element *el) const
 Returns the LinkVisualizer of element. More...
 
string const & getLabel () const
 Gets the label of this element. More...
 
void setLabel (const string &lab)
 Sets label of this element. More...
 
E const & getValue () const
 Gets the object held in the generic object E. More...
 
E & getValue ()
 Gets the object held in the generic object E. More...
 
void setValue (const E &val)
 Sets generic object to "val". More...
 
void setSize (const double &sz)
 Sets size of the element. More...
 
double getSize () const
 Get element size. More...
 
void setColor (const Color &col)
 Set the color of the Element. More...
 
void setColor (const string col)
 Set the color by name. More...
 
Color getColor () const
 Get the current color of the element. More...
 
void setOpacity (double opacity)
 Set opacity of element - use the 4th color component. More...
 
double getOpacity ()
 
void setShape (const Shape &shp)
 Set the shape of the element. More...
 
Shape getShape () const
 Returns the shape of the element. More...
 
void setLocation (const double &locX, const double &locY)
 Sets the location attributes of an element. More...
 
double getLocationX () const
 Gets the X coordinate of the location. More...
 
double getLocationY () const
 Gets the Y coordinate of the location. More...
 
- Public Member Functions inherited from bridges::datastructure::DataStructure
virtual ~DataStructure ()=default
 

Additional Inherited Members

- Protected Member Functions inherited from bridges::datastructure::Element< E >
virtual const string getElementRepresentation () const
 Gets the JSON string of the element representation. More...
 
- Static Protected Member Functions inherited from bridges::datastructure::Element< E >
static const string getLinkRepresentation (const LinkVisualizer &lv, const string &src, const string &dest)
 
- Protected Attributes inherited from bridges::datastructure::Element< E >
unordered_map< Element *, LinkVisualizerlinks
 

Constructor & Destructor Documentation

◆ TreeElement()

template<typename E >
bridges::datastructure::TreeElement< E >::TreeElement ( const E &  e = E(),
const string &  lab = string() 
)
inline

Construct a TreeElement from given values.

Constructs a TreeElement with the provided value and label, setting the left and right TreeElements to NULL. The defaults will be used if not provided.

Parameters
eThe data to hold
labThe label to show

Member Function Documentation

◆ addChild()

template<typename E >
void bridges::datastructure::TreeElement< E >::addChild ( TreeElement< E > *  child)
inline

Adds a child to children.

Parameters
childThe child TreeElement

◆ getChild() [1/2]

template<typename E >
TreeElement* bridges::datastructure::TreeElement< E >::getChild ( const int &  n)
inline

Gets the nth child of this node.

Gets the nth child of this TreeElement, returns null if non-existent

Parameters
nThe index of the child
Returns
The child TreeElement

◆ getChild() [2/2]

template<typename E >
const TreeElement* bridges::datastructure::TreeElement< E >::getChild ( const int &  n) const
inline

Gets the nth child of this node - constant version.

Gets the nth child of this TreeElement, returns null if non-existent

Parameters
nThe index of the child
Returns
The child TreeElement

◆ getChildren() [1/2]

template<typename E >
vector<TreeElement*>& bridges::datastructure::TreeElement< E >::getChildren ( )
inline

Get the children of this node.

Returns
The children TreeElements

◆ getChildren() [2/2]

template<typename E >
const vector<TreeElement*>& bridges::datastructure::TreeElement< E >::getChildren ( ) const
inline

Get the children of this node.

Constant version

Returns
The children TreeElements

◆ getDStype()

template<typename E >
virtual const string bridges::datastructure::TreeElement< E >::getDStype ( ) const
inlineoverridevirtual

◆ setChild()

template<typename E >
void bridges::datastructure::TreeElement< E >::setChild ( const size_t &  index,
TreeElement< E > *  kid 
)
inline

Sets child at index to "kid".

Will do nothing given invalid index.

Parameters
indexof child to replace
kidThe child TreeElement

This simply replaces the element at position index and the old element is lost(actually can create memory leak if it came from dynamic memory Since we cannot distinguish from allocated or static memory from pointers, it is the user's responsibility to keep track of allocated memory its linkage. For new elements, if not null, create linkage


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