profiler  0.0
molpro::profiler::Node< Counter > Class Template Reference

A node in a parameter tree storing a Counter object aliased by a name. More...

#include <Node.h>

Collaboration diagram for molpro::profiler::Node< Counter >:

Public Member Functions

 ~Node ()=default
 
 Node (Node< Counter > &&) noexcept=default
 
Node< Counter > & operator= (Node< Counter > &&) noexcept=default
 
 Node (const Node< Counter > &)=delete
 
Node< Counter > & operator= (const Node< Counter > &)=delete
 
template<typename ForwardIt >
std::shared_ptr< Node< Counter > > walk (ForwardIt start_name, ForwardIt end_name)
 Recursively walks down a single branch described by node names. More...
 
std::shared_ptr< Node< Counter > > walk (const std::list< std::string > &path_to_node)
 
std::shared_ptr< Node< Counter > > child (const std::string &child_name)
 Returns a child node, same as calling walk with one element. More...
 
std::shared_ptr< Node< Counter > > find_parent (const std::string &parent_name)
 Searches from current parent up to the root returning a node with specified name. More...
 
std::shared_ptr< Node< Counter > > walk_up (int n)
 Walks up n levels by following the parent nodes. More...
 
size_t count_nodes () const
 Get total number of nodes in a tree. More...
 

Static Public Member Functions

static std::shared_ptr< Node< Counter > > make_root (const std::string &name, const Counter &counter)
 Builds the root tree whose parent is nullptr. More...
 
static std::shared_ptr< Node< Counter > > add_child (const std::string &child_name, const Counter &child_counter, const std::shared_ptr< Node< Counter >> &parent)
 Adds a child to the current node. Overwrites any children with child_name that already exist. More...
 
static std::shared_ptr< Node< Counter > > deep_copy (const std::shared_ptr< Node< Counter >> &subtree, std::shared_ptr< Node< Counter >> parent)
 Creates a deep copy of the subtree with copies of Counter objects. More...
 

Public Attributes

std::string name
 name of the node. This is a duplicate, same name is stored in parent's map of children. More...
 
Counter counter
 
std::shared_ptr< Node< Counter > > parent = nullptr
 resource counter More...
 
std::map< std::string, std::shared_ptr< Node< Counter > > > children
 child nodes More...
 

Detailed Description

template<class Counter>
class molpro::profiler::Node< Counter >

A node in a parameter tree storing a Counter object aliased by a name.

Constructor & Destructor Documentation

◆ ~Node()

template<class Counter >
molpro::profiler::Node< Counter >::~Node ( )
default

◆ Node() [1/2]

template<class Counter >
molpro::profiler::Node< Counter >::Node ( Node< Counter > &&  )
defaultnoexcept

◆ Node() [2/2]

template<class Counter >
molpro::profiler::Node< Counter >::Node ( const Node< Counter > &  )
delete

Member Function Documentation

◆ add_child()

template<class Counter >
static std::shared_ptr<Node<Counter> > molpro::profiler::Node< Counter >::add_child ( const std::string &  child_name,
const Counter child_counter,
const std::shared_ptr< Node< Counter >> &  parent 
)
inlinestatic

Adds a child to the current node. Overwrites any children with child_name that already exist.

◆ child()

template<class Counter >
std::shared_ptr<Node<Counter> > molpro::profiler::Node< Counter >::child ( const std::string &  child_name)
inline

Returns a child node, same as calling walk with one element.

Parameters
child_namename of the child node

◆ count_nodes()

template<class Counter >
size_t molpro::profiler::Node< Counter >::count_nodes ( ) const
inline

Get total number of nodes in a tree.

◆ deep_copy()

template<class Counter >
static std::shared_ptr<Node<Counter> > molpro::profiler::Node< Counter >::deep_copy ( const std::shared_ptr< Node< Counter >> &  subtree,
std::shared_ptr< Node< Counter >>  parent 
)
inlinestatic

Creates a deep copy of the subtree with copies of Counter objects.

◆ find_parent()

template<class Counter >
std::shared_ptr<Node<Counter> > molpro::profiler::Node< Counter >::find_parent ( const std::string &  parent_name)
inline

Searches from current parent up to the root returning a node with specified name.

Parameters
parent_namename of the node that needs to be returned
Returns
parent with matching name or nullptr if no such node exists

◆ make_root()

template<class Counter >
static std::shared_ptr<Node<Counter> > molpro::profiler::Node< Counter >::make_root ( const std::string &  name,
const Counter counter 
)
inlinestatic

Builds the root tree whose parent is nullptr.

◆ operator=() [1/2]

template<class Counter >
Node<Counter>& molpro::profiler::Node< Counter >::operator= ( const Node< Counter > &  )
delete

◆ operator=() [2/2]

template<class Counter >
Node<Counter>& molpro::profiler::Node< Counter >::operator= ( Node< Counter > &&  )
defaultnoexcept

◆ walk() [1/2]

template<class Counter >
std::shared_ptr<Node<Counter> > molpro::profiler::Node< Counter >::walk ( const std::list< std::string > &  path_to_node)
inline

◆ walk() [2/2]

template<class Counter >
template<typename ForwardIt >
std::shared_ptr<Node<Counter> > molpro::profiler::Node< Counter >::walk ( ForwardIt  start_name,
ForwardIt  end_name 
)
inline

Recursively walks down a single branch described by node names.

Consider a single branch root->A->B->C, the path can be stored as std::list<std::string> path{"A","B","C"} and calling root.walk(path.begin, path.end) returns the node C.

Template Parameters
ForwardItforward iterator for a container of strings
Parameters
start_namename for a child of the current node
end_nameindicates end of the path
Returns

◆ walk_up()

template<class Counter >
std::shared_ptr<Node<Counter> > molpro::profiler::Node< Counter >::walk_up ( int  n)
inline

Walks up n levels by following the parent nodes.

Parameters
nnumber of levels to walk up ( n > 0)
Returns
node n levels up (n=1 is the parent) or nullptr if n exceeds distance to root

Member Data Documentation

◆ children

template<class Counter >
std::map<std::string, std::shared_ptr<Node<Counter> > > molpro::profiler::Node< Counter >::children

child nodes

◆ counter

template<class Counter >
Counter molpro::profiler::Node< Counter >::counter

◆ name

template<class Counter >
std::string molpro::profiler::Node< Counter >::name

name of the node. This is a duplicate, same name is stored in parent's map of children.

◆ parent

template<class Counter >
std::shared_ptr<Node<Counter> > molpro::profiler::Node< Counter >::parent = nullptr

resource counter

parent node