BornAgain  1.19.79
Open-source research software to simulate and fit neutron and x-ray reflectometry and grazing-incidence small-angle scattering
NodeUtils Namespace Reference

Functions

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

Function Documentation

◆ AllDescendantsOfType()

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

Definition at line 51 of file NodeUtils.h.

52 {
53  std::vector<const T*> result;
54  for (const auto* child : node.nodeChildren()) {
55  ASSERT(child);
56  if (const auto* t = dynamic_cast<const T*>(child))
57  result.push_back(t);
58  for (const auto* t : AllDescendantsOfType<T>(*child))
59  result.push_back(t);
60  }
61  return result;
62 }
#define ASSERT(condition)
Definition: Assert.h:45
virtual std::vector< const INode * > nodeChildren() const
Returns all children.
Definition: INode.cpp:56

References ASSERT, and INode::nodeChildren().

Here is the call graph for this function:

◆ ChildNodesOfType()

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

Definition at line 31 of file NodeUtils.h.

32 {
33  std::vector<const T*> result;
34  for (const auto& p_child : node.nodeChildren()) {
35  if (const auto* t = dynamic_cast<const T*>(p_child))
36  result.push_back(t);
37  }
38  return result;
39 }

References INode::nodeChildren().

Here is the call graph for this function:

◆ OnlyChildOfType()

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

Definition at line 42 of file NodeUtils.h.

43 {
44  const auto list = ChildNodesOfType<T>(node);
45  if (list.size() != 1)
46  return nullptr;
47  return list.front();
48 }