BornAgain  1.18.0
Simulate and fit neutron and x-ray scattering at grazing incidence
INodeUtils Namespace Reference

Functions

template<typename T >
std::vector< const T * > ChildNodesOfType (const INode &node)
 
template<typename T >
const T * OnlyChildOfType (const INode &node)
 
template<typename T >
std::vector< const T * > AllDescendantsOfType (const INode &node)
 

Function Documentation

◆ ChildNodesOfType()

template<typename T >
std::vector<const T*> INodeUtils::ChildNodesOfType ( const INode node)

Definition at line 22 of file INodeUtils.h.

23 {
24  std::vector<const T*> result;
25  for (const auto& p_child : node.getChildren()) {
26  if (const auto* t = dynamic_cast<const T*>(p_child))
27  result.push_back(t);
28  }
29  return result;
30 }
virtual std::vector< const INode * > getChildren() const
Returns a vector of children (const).
Definition: INode.cpp:64

References INode::getChildren().

Here is the call graph for this function:

◆ OnlyChildOfType()

template<typename T >
const T* INodeUtils::OnlyChildOfType ( const INode node)

Definition at line 32 of file INodeUtils.h.

33 {
34  const auto list = ChildNodesOfType<T>(node);
35  if (list.size() != 1)
36  return nullptr;
37  return list.front();
38 }

◆ AllDescendantsOfType()

template<typename T >
std::vector<const T*> INodeUtils::AllDescendantsOfType ( const INode node)

Definition at line 40 of file INodeUtils.h.

41 {
42  std::vector<const T*> result;
43  for (const auto* p_child : node.getChildren()) {
44  if (const auto* t = dynamic_cast<const T*>(p_child))
45  result.push_back(t);
46  for (const auto* t : AllDescendantsOfType<T>(*p_child))
47  result.push_back(t);
48  }
49  return result;
50 }

References INode::getChildren().

Here is the call graph for this function: