ROSE  0.11.125.0
Public Member Functions | List of all members
Sawyer::Tree::ChildEdge< T > Class Template Referencefinal

Description

template<class T>
class Sawyer::Tree::ChildEdge< T >

An edge from a parent to a child.

An edge is the inter-node link between a parent node and a child node. The ChildEdge type is only allowed for data members of a Node and is how the node defines which data members participate as edges in the tree.

To create a node and define that it points to two child nodes, one must declare the two child pointers using the ChildEdge type, and then initialize the parent end of the edges during construction, as follows:

class Parent: public Tree::Node {
public:
Tree::ChildEdge<ChildType1> first; // ChildType1 is userdefined, derived from Tree::Node
Tree::ChildEdge<ChildType2> second; // ditto for ChildType2
Parent()
: first(this), second(this) {}
};

It is also possible to give non-null values to the child ends of the edges during construction:

Parent::Parent(const std::shared_ptr<ChildType1> &c1)
: first(this, c1), second(this, std::make_shared<ChildType2>()) {}

The ChildEdge members are used as if they were pointers:

auto parent = std::make_shared<Parent>();
assert(parent->first == nullptr);
auto child = std::make_shared<ChildType1>();
parent->first = child;
assert(parent->first == child);
assert(child->parent == parent);

Definition at line 205 of file util/Sawyer/Tree.h.

#include <util/Sawyer/Tree.h>

Public Member Functions

 ChildEdge (Node *container)
 Points to no child. More...
 
 ChildEdge (Node *container, const std::shared_ptr< T > &child)
 Constructor that points to a child. More...
 
 ChildEdge (const ChildEdge &)=delete
 
ChildEdgeoperator= (const std::shared_ptr< T > &child)
 Point to a child node. More...
 
void reset ()
 Cause this edge to point to no child. More...
 
std::shared_ptr< T > operator-> () const
 Obtain shared pointer. More...
 
T & operator* () const
 Obtain pointed-to node. More...
 
 operator bool () const
 Conversion to bool. More...
 
std::shared_ptr< T > shared () const
 Pointer to the child. More...
 
 operator std::shared_ptr< T > () const
 Implicit conversion to shared pointer. More...
 

Constructor & Destructor Documentation

template<class T >
Sawyer::Tree::ChildEdge< T >::ChildEdge ( Node container)
explicit

Points to no child.

Definition at line 925 of file util/Sawyer/Tree.h.

template<class T >
Sawyer::Tree::ChildEdge< T >::ChildEdge ( Node container,
const std::shared_ptr< T > &  child 
)

Constructor that points to a child.

Definition at line 931 of file util/Sawyer/Tree.h.

Member Function Documentation

template<class T >
ChildEdge& Sawyer::Tree::ChildEdge< T >::operator= ( const std::shared_ptr< T > &  child)
inline

Point to a child node.

Definition at line 220 of file util/Sawyer/Tree.h.

template<class T >
void Sawyer::Tree::ChildEdge< T >::reset ( )
inline

Cause this edge to point to no child.

Definition at line 226 of file util/Sawyer/Tree.h.

template<class T >
std::shared_ptr<T> Sawyer::Tree::ChildEdge< T >::operator-> ( ) const
inline

Obtain shared pointer.

Definition at line 231 of file util/Sawyer/Tree.h.

References Sawyer::Tree::ChildEdge< T >::shared().

template<class T >
T& Sawyer::Tree::ChildEdge< T >::operator* ( ) const
inline

Obtain pointed-to node.

Definition at line 236 of file util/Sawyer/Tree.h.

References Sawyer::Tree::ChildEdge< T >::shared().

template<class T >
Sawyer::Tree::ChildEdge< T >::operator bool ( ) const
inlineexplicit

Conversion to bool.

Definition at line 242 of file util/Sawyer/Tree.h.

References Sawyer::Tree::ChildEdge< T >::shared().

template<class T >
std::shared_ptr< T > Sawyer::Tree::ChildEdge< T >::shared ( ) const
template<class T >
Sawyer::Tree::ChildEdge< T >::operator std::shared_ptr< T > ( ) const
inline

Implicit conversion to shared pointer.

Definition at line 250 of file util/Sawyer/Tree.h.

References Sawyer::Tree::ChildEdge< T >::shared().


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