ROSE 0.11.145.192
|
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.
#include <Sawyer/Tree.h>
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 ChildPtr & | operator-> () const |
Return the child if there is one, else null. | |
const ChildPtr & | operator() () 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. | |
Edge & | operator= (const ChildPtr &newChild) |
Assign a pointer to a child. | |
Edge & | operator= (const ReverseEdge &parent) |
Assign a pointer to a child. | |
using Sawyer::Tree::Vertex< B >::Edge< T >::ChildPtr = std::shared_ptr<Child> |
Destructor clears child's parent.
Definition at line 1201 of file Tree.h.
References Sawyer::Tree::Vertex< B >::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.
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.
const std::shared_ptr< T > & Sawyer::Tree::Vertex< B >::Edge< T >::operator-> | ( | ) | const |
const std::shared_ptr< T > & Sawyer::Tree::Vertex< B >::Edge< T >::operator() | ( | ) | const |
bool Sawyer::Tree::Vertex< B >::Edge< T >::operator== | ( | const UserBasePtr & | ptr | ) | const |
bool Sawyer::Tree::Vertex< B >::Edge< T >::operator!= | ( | const UserBasePtr & | ptr | ) | const |
bool Sawyer::Tree::Vertex< B >::Edge< T >::operator== | ( | const ReverseEdge< T > & | other | ) | const |
bool Sawyer::Tree::Vertex< B >::Edge< T >::operator!= | ( | const ReverseEdge< T > & | other | ) | const |
bool Sawyer::Tree::Vertex< B >::Edge< T >::operator== | ( | const Edge< U > & | other | ) | const |
bool Sawyer::Tree::Vertex< B >::Edge< T >::operator!= | ( | const Edge< U > & | other | ) | const |
|
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.
|
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.
|
inlineexplicit |
|
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.
|
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.