ROSE  0.11.125.0
Public Types | Public Member Functions | List of all members
Rose::Tree::Edge< T > Class Template Reference

Description

template<class T>
class Rose::Tree::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 node 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);
}
};

Definition at line 129 of file Tree/Base.h.

#include <Rose/Tree/Base.h>

Inheritance diagram for Rose::Tree::Edge< T >:
Inheritance graph
[legend]
Collaboration diagram for Rose::Tree::Edge< T >:
Collaboration graph
[legend]

Public Types

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

Public Member Functions

 Edge (const Edge &)=delete
 
Edgeoperator= (const Edge &)=delete
 
 operator bool () const
 True if child is not null. More...
 
template<class T >
bool operator== (const BasePtr &ptr) const
 
template<class T >
bool operator!= (const BasePtr &ptr) const
 
 Edge (Base &parent)
 Construct a child edge that belongs to the specified parent. More...
 
 Edge (Base &parent, const ChildPtr &child)
 Construct a child edge that belongs to the specified parent. More...
 
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 std::shared_ptr< Base > &) const
 Compare the child pointer to another pointer.
 
bool operator!= (const std::shared_ptr< Base > &) 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 &child)
 Assign a pointer to a child. More...
 
Edgeoperator= (const ReverseEdge &)
 Assign a pointer to a child. More...
 

Additional Inherited Members

- Protected Member Functions inherited from Rose::Tree::ReverseEdgeAccess
void resetParent (ReverseEdge &)
 
void setParent (ReverseEdge &, Base &)
 

Member Typedef Documentation

template<class T>
using Rose::Tree::Edge< T >::Child = T

Type of child being pointed to.

Definition at line 132 of file Tree/Base.h.

template<class T>
using Rose::Tree::Edge< T >::ChildPtr = std::shared_ptr<T>

Type of pointer to the child.

Definition at line 135 of file Tree/Base.h.

Constructor & Destructor Documentation

template<class T >
Edge::Edge ( Base 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 364 of file Tree/Base.h.

template<class T >
Edge::Edge ( Base 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.

Definition at line 368 of file Tree/Base.h.

Member Function Documentation

template<class T >
Edge< T > & Edge::operator= ( const ChildPtr child)

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 430 of file Tree/Base.h.

template<class T >
Edge< T > & Edge::operator= ( const ReverseEdge< T > &  parent)

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 464 of file Tree/Base.h.

template<class T>
Rose::Tree::Edge< T >::operator bool ( ) const
inlineexplicit

True if child is not null.

Definition at line 202 of file Tree/Base.h.


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