ROSE  0.11.125.0
Classes | Public Types | Public Member Functions | Public Attributes | Protected Member Functions | List of all members
Rose::Tree::Base Class Reference

Description

Base class for tree vertices.

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

#include <Rose/Tree/Base.h>

Inheritance diagram for Rose::Tree::Base:
Inheritance graph
[legend]
Collaboration diagram for Rose::Tree::Base:
Collaboration graph
[legend]

Classes

struct  ChildDescriptor
 Information about a child. More...
 

Public Types

enum  Traversal {
  Traversal::ENTER,
  Traversal::LEAVE
}
 Traversal direction. More...
 
using Ptr = BasePtr
 Shared-ownership pointer to a Base. More...
 

Public Member Functions

Ptr pointer ()
 Returns a shared pointer to this vertex. More...
 
template<class Visitor >
auto traverseReverse (const Visitor &visitor)
 Traverse in reverse direction from children to parents. More...
 
template<class Visitor >
auto traverse (const Visitor &visitor)
 Traverse in forward direction from parents to children. More...
 
template<class T >
std::shared_ptr< T > findAncestor ()
 Traversal that finds an ancestor of a particular type. More...
 
template<class T >
std::vector< std::shared_ptr< T > > findDescendants ()
 Traversal that finds all the descendants of a particular type. More...
 
std::string childName (size_t i)
 Returns the property name for a child. More...
 
Ptr child (size_t i)
 Returns the pointer for a child. More...
 
size_t nChildren (size_t i)
 Returns the number of children. More...
 

Public Attributes

ReverseEdge parent
 Pointer to the parent in the tree. More...
 

Protected Member Functions

virtual void destructorHelper ()
 
virtual ChildDescriptor findChild (size_t i) const
 Finds information about an indexed child. More...
 

Member Typedef Documentation

Shared-ownership pointer to a Base.

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

Member Enumeration Documentation

Traversal direction.

Enumerator
ENTER 

Pre-order visitation.

LEAVE 

Post-order visitation.

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

Member Function Documentation

Ptr Rose::Tree::Base::pointer ( )

Returns a shared pointer to this vertex.

Referenced by traverse(), and traverseReverse().

template<class Visitor >
auto Rose::Tree::Base::traverseReverse ( const Visitor &  visitor)
inline

Traverse in reverse direction from children to parents.

The visitor is called for each vertex from the current vertex until the root of the tree is reached unless the visitor indicates that the traversal should end. It does so by returning a value that is true in a Boolean context, and this value becomes the return value for the entire traversal.

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

References pointer().

template<class Visitor >
auto Rose::Tree::Base::traverse ( const Visitor &  visitor)
inline

Traverse in forward direction from parents to children.

Perform a depth-first traversal of the tree starting with this vertex. The visitor functor is called twice for each vertex, first in the forward direction from the parent, then in the reverse direction from the children. The functor takes two arguments: the vertex being visited and an enum indicating whether the visit is the first (Traverse::ENTER) or the second (Traverse::LEAVE) visitation. The traversal has the same return type as the functor. If the functor returns a value which evaluates to true in Boolean context, then the traversal immediately returns that value, otherwise it continues until the entire subtree is visited and returns a default-constructed value.

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

References child(), ENTER, findChild(), Rose::Tree::Base::ChildDescriptor::i, LEAVE, pointer(), and Rose::Tree::Base::ChildDescriptor::value.

Referenced by findDescendants().

template<class T >
std::shared_ptr<T> Rose::Tree::Base::findAncestor ( )
inline

Traversal that finds an ancestor of a particular type.

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

template<class T >
std::vector<std::shared_ptr<T> > Rose::Tree::Base::findDescendants ( )
inline

Traversal that finds all the descendants of a particular type.

Note that this is probably not the way you want to do this because it's expensive to create the list of all matching pointers. Instead, you probably want to call traverse and handle each matching vertex inside the functor.

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

References ENTER, and traverse().

std::string Rose::Tree::Base::childName ( size_t  i)

Returns the property name for a child.

Returns the property name for the child at index i. If i is out of range, then an empty string is returned.

Ptr Rose::Tree::Base::child ( size_t  i)

Returns the pointer for a child.

Returns the pointer for the child at index i. If i is out of range, then a null pointer is returned, which is indistinguishable from the case when a valid index is specified but that child is a null pointer.

Referenced by traverse().

size_t Rose::Tree::Base::nChildren ( size_t  i)

Returns the number of children.

This is the number of children for this class and the base class, recursively. Some children may be null pointers.

virtual ChildDescriptor Rose::Tree::Base::findChild ( size_t  i) const
protectedvirtual

Finds information about an indexed child.

The index, i, specifies the child about which information is returned. Children are numbered recursively in base classes followed by the current class. This function is re-implemented in every derived class that has children.

A ChildDescriptor is returned for every query. If the index is out of range for the class, then the return value is for a child one past the end. I.e., the index is equal to the number of children, the name is empty, and the value is a null pointer.

Reimplemented in Rose::Tree::List< T >.

Referenced by traverse().

Member Data Documentation

ReverseEdge Rose::Tree::Base::parent

Pointer to the parent in the tree.

A vertex's parent pointer is adjusted automatically when the vertex is inserted or removed as a child of another vertex. An invariant of this design is that whenever vertex A is a child of vertex B, then vertex B is a parent of vertex A.

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


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