ROSE  0.11.96.11
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 Tree.h.

#include <Tree.h>

Public Member Functions

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

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