ROSE 0.11.145.192
Public Types | Public Member Functions | List of all members
Sawyer::Tree::Vertex< B >::Edge< T > Class Template Reference

Description

template<class B>
template<class T>
class Sawyer::Tree::Vertex< B >::Edge< T >

A parent-to-child edge in a tree.

A parent-to-child edge is a pointer-like object that points from an parent vertex to a child vertex or nullptr. It is also responsible for adjusting the child's parent pointer. The term "edge" is used instead of "pointer" because the relationship between the parent and child is bidirectional. The full term is "forward edge", but since this is the only kind of edge that users will work with, we've shortened the name to just "edge". A "reverse edge" is the pointer from child to parent.

An forward edge is always a data member of a vertex and never instantiated in other circumstances. Thus users don't normally instanticate these directly, but they do interact with them to obtain pointers to children from a parent.

This type is used to define a data member in the parent that points to a child. For instance, the following binary expression vertex has left-hand-side and right-hand-side children that are part of the tree. If lhs and rhs were not intended to be part of the tree data structure, then their types would be pointers (ExpressionPtr) instead of edges.

class BinaryExpression: public Expression {
public:
using Ptr = std::shared_ptr<BinaryExpression>;
public:
protected:
BinaryExpression()
: lhs(*this), rhs(*this) {}
static Ptr instance() {
return Ptr(new BinaryExpression);
}
};
A parent-to-child edge in a tree.
Definition Tree.h:358

Definition at line 358 of file Tree.h.

#include <Sawyer/Tree.h>

Inheritance diagram for Sawyer::Tree::Vertex< B >::Edge< T >:
Inheritance graph
[legend]
Collaboration diagram for Sawyer::Tree::Vertex< B >::Edge< T >:
Collaboration graph
[legend]

Public Types

using Child = T
 Type of child being pointed to.
 
using ChildPtr = std::shared_ptr< Child >
 Type of pointer to the child.
 

Public Member Functions

 ~Edge ()
 Destructor clears child's parent.
 
 operator bool () const
 True if child is not null.
 
boost::signals2::connection beforeChange (const typename ChangeSignal::slot_type &slot)
 Functors to call before the child pointer is changed.
 
boost::signals2::connection afterChange (const typename ChangeSignal::slot_type &slot)
 Functors to call after the child pointer is changed.
 
 Edge (UserBase &parent)
 Construct a child edge that belongs to the specified parent.
 
 Edge (UserBase &parent, const ChildPtr &child)
 Construct a child edge that belongs to the specified parent.
 
const ChildPtroperator-> () const
 Return the child if there is one, else null.
 
const ChildPtroperator() () const
 Return the child if there is one, else null.
 
bool operator== (const UserBasePtr &) const
 Compare the child pointer to another pointer.
 
bool operator!= (const UserBasePtr &) const
 Compare the child pointer to another pointer.
 
bool operator== (const ReverseEdge &) const
 Compare the child pointer to another pointer.
 
bool operator!= (const ReverseEdge &) const
 Compare the child pointer to another pointer.
 
template<class U >
bool operator== (const Edge< U > &) const
 Compare the child pointer to another pointer.
 
template<class U >
bool operator!= (const Edge< U > &) const
 Compare the child pointer to another pointer.
 
Edgeoperator= (const ChildPtr &newChild)
 Assign a pointer to a child.
 
Edgeoperator= (const ReverseEdge &parent)
 Assign a pointer to a child.
 

Member Typedef Documentation

◆ Child

template<class B >
template<class T >
using Sawyer::Tree::Vertex< B >::Edge< T >::Child = T

Type of child being pointed to.

Definition at line 361 of file Tree.h.

◆ ChildPtr

template<class B >
template<class T >
using Sawyer::Tree::Vertex< B >::Edge< T >::ChildPtr = std::shared_ptr<Child>

Type of pointer to the child.

Definition at line 364 of file Tree.h.

Constructor & Destructor Documentation

◆ ~Edge()

template<class B >
template<class T >
Sawyer::Tree::Vertex< B >::Edge< T >::~Edge ( )

Destructor clears child's parent.

Definition at line 1201 of file Tree.h.

References Sawyer::Tree::Vertex< B >::parent.

◆ Edge() [1/2]

template<class B >
template<class T >
Sawyer::Tree::Vertex< B >::Edge< T >::Edge ( UserBase parent)
explicit

Construct a child edge that belongs to the specified parent.

When constructing a class containing a data member of this type (i.e., a tree edge that points to a child of this vertex), the data member must be initialized by passing *this as the argument. See the example in this class documentation.

An optional second argument initializes the child pointer for the edge. The initialization is the same as if the child had been assigned with operator= later. I.e., the child must not already have a parent.

Definition at line 1208 of file Tree.h.

◆ Edge() [2/2]

template<class B >
template<class T >
Sawyer::Tree::Vertex< B >::Edge< T >::Edge ( UserBase parent,
const ChildPtr child 
)

Construct a child edge that belongs to the specified parent.

When constructing a class containing a data member of this type (i.e., a tree edge that points to a child of this vertex), the data member must be initialized by passing *this as the argument. See the example in this class documentation.

An optional second argument initializes the child pointer for the edge. The initialization is the same as if the child had been assigned with operator= later. I.e., the child must not already have a parent.

Member Function Documentation

◆ operator->()

template<class B >
template<class T >
const std::shared_ptr< T > & Sawyer::Tree::Vertex< B >::Edge< T >::operator-> ( ) const

Return the child if there is one, else null.

Definition at line 1257 of file Tree.h.

◆ operator()()

template<class B >
template<class T >
const std::shared_ptr< T > & Sawyer::Tree::Vertex< B >::Edge< T >::operator() ( ) const

Return the child if there is one, else null.

Definition at line 1265 of file Tree.h.

◆ operator==() [1/3]

template<class B >
template<class T >
bool Sawyer::Tree::Vertex< B >::Edge< T >::operator== ( const UserBasePtr ptr) const

Compare the child pointer to another pointer.

Definition at line 1272 of file Tree.h.

◆ operator!=() [1/3]

template<class B >
template<class T >
bool Sawyer::Tree::Vertex< B >::Edge< T >::operator!= ( const UserBasePtr ptr) const

Compare the child pointer to another pointer.

Definition at line 1279 of file Tree.h.

◆ operator==() [2/3]

template<class B >
template<class T >
bool Sawyer::Tree::Vertex< B >::Edge< T >::operator== ( const ReverseEdge< T > &  other) const

Compare the child pointer to another pointer.

Definition at line 1286 of file Tree.h.

◆ operator!=() [2/3]

template<class B >
template<class T >
bool Sawyer::Tree::Vertex< B >::Edge< T >::operator!= ( const ReverseEdge< T > &  other) const

Compare the child pointer to another pointer.

Definition at line 1293 of file Tree.h.

◆ operator==() [3/3]

template<class B >
template<class T >
template<class U >
bool Sawyer::Tree::Vertex< B >::Edge< T >::operator== ( const Edge< U > &  other) const

Compare the child pointer to another pointer.

Definition at line 1301 of file Tree.h.

◆ operator!=() [3/3]

template<class B >
template<class T >
template<class U >
bool Sawyer::Tree::Vertex< B >::Edge< T >::operator!= ( const Edge< U > &  other) const

Compare the child pointer to another pointer.

Definition at line 1309 of file Tree.h.

◆ operator=() [1/2]

template<class B >
template<class T >
Edge & Sawyer::Tree::Vertex< B >::Edge< T >::operator= ( const ChildPtr newChild)
inline

Assign a pointer to a child.

If this edge points to an old child then that child is removed and its parent is reset. If the specified new child is non-null, then it is inserted and its parent pointer set to the parent of this edge.

However, if the new child already has a non-null parent, then no changes are made and an InsertionError is thrown with the error's vertex pointing to the intended child. Otherwise, if the new child is non-null and is the parent or any more distant ancestor of this edge's vertex, then a CycleError is thrown. Cycle errors are only thrown if debugging is enabled (i.e., the CPP macro NDEBUG is undefined).

Attempting to assign one child edge object to another is a compile-time error (its operator= is not declared) because every non-null child edge points to a child whose parent is non-null, which would trigger an InsertionError. Therefore only null child edges could be assigned. But since only null child edges can be assigned, its more concise and clear to assign the null pointer directly.

Definition at line 452 of file Tree.h.

◆ operator=() [2/2]

template<class B >
template<class T >
Edge & Sawyer::Tree::Vertex< B >::Edge< T >::operator= ( const ReverseEdge< T > &  parent)
inline

Assign a pointer to a child.

If this edge points to an old child then that child is removed and its parent is reset. If the specified new child is non-null, then it is inserted and its parent pointer set to the parent of this edge.

However, if the new child already has a non-null parent, then no changes are made and an InsertionError is thrown with the error's vertex pointing to the intended child. Otherwise, if the new child is non-null and is the parent or any more distant ancestor of this edge's vertex, then a CycleError is thrown. Cycle errors are only thrown if debugging is enabled (i.e., the CPP macro NDEBUG is undefined).

Attempting to assign one child edge object to another is a compile-time error (its operator= is not declared) because every non-null child edge points to a child whose parent is non-null, which would trigger an InsertionError. Therefore only null child edges could be assigned. But since only null child edges can be assigned, its more concise and clear to assign the null pointer directly.

Definition at line 476 of file Tree.h.

References Sawyer::Tree::Vertex< B >::parent.

◆ operator bool()

template<class B >
template<class T >
Sawyer::Tree::Vertex< B >::Edge< T >::operator bool ( ) const
inlineexplicit

True if child is not null.

Definition at line 482 of file Tree.h.

◆ beforeChange()

template<class B >
template<class T >
boost::signals2::connection Sawyer::Tree::Vertex< B >::Edge< T >::beforeChange ( const typename ChangeSignal::slot_type &  slot)
inline

Functors to call before the child pointer is changed.

The functor is called before the child pointer is changed and may throw an exception to indicate that the change should not occur. The two arguments are the old and new child pointers, either of which might be null. The callbacks are not invoked during edge constructor or destructor calls.

Definition at line 491 of file Tree.h.

◆ afterChange()

template<class B >
template<class T >
boost::signals2::connection Sawyer::Tree::Vertex< B >::Edge< T >::afterChange ( const typename ChangeSignal::slot_type &  slot)
inline

Functors to call after the child pointer is changed.

The functor is called after the edge child pointer is changed. The two arguments are the old and new child pointers, either of which might be null. The callbacks are not invoked during edge constructor or destructor calls.

Definition at line 499 of file Tree.h.


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