BornAgain  1.19.0
Simulate and fit neutron and x-ray scattering at grazing incidence
NodeUtils Namespace Reference

Functions

std::string nodePath (const INode *node, const INode *root=nullptr)
 Returns path composed of node's displayName, with respect to root node. More...
 
std::string nodeToString (const INode *node)
 Returns multiline string representing tree structure starting from given node. More...
 
std::vector< std::tuple< const INode *, int, const INode * > > progenyPlus (const INode *node, int level=0)
 Returns a vector of triples (descendant, depth, parent) More...
 

Function Documentation

◆ nodePath()

std::string NodeUtils::nodePath ( const INode node,
const INode root = nullptr 
)

Returns path composed of node's displayName, with respect to root node.

Definition at line 89 of file NodeUtils.cpp.

90 {
91  std::vector<std::string> pathElements;
92  const INode* current = node;
93  while (current && current != root) {
94  pathElements.push_back(current->displayName());
95  pathElements.push_back("/");
96  current = current->parent();
97  }
98  if (root != nullptr && current != root)
99  throw std::runtime_error("NodeUtils::nodePath() -> Error. Node doesn't "
100  "belong to root's branch");
101  std::reverse(pathElements.begin(), pathElements.end());
102  std::ostringstream result;
103  std::copy(pathElements.begin(), pathElements.end(), std::ostream_iterator<std::string>(result));
104  return result.str();
105 }
Base class for tree-like structures containing parameterized objects.
Definition: INode.h:49
std::string displayName() const
Returns display name, composed from the name of node and it's copy number.
Definition: INode.cpp:115
const INode * parent() const
Definition: INode.cpp:84

References INode::displayName(), and INode::parent().

Referenced by INode::createParameterTree(), and ParticleDistribution::generateParticles().

Here is the call graph for this function:

◆ nodeToString()

std::string NodeUtils::nodeToString ( const INode node)

Returns multiline string representing tree structure starting from given node.

Definition at line 81 of file NodeUtils.cpp.

82 {
83  std::ostringstream result;
84  for (const auto& [child, depth, parent] : progenyPlus(node))
85  result << nodeString(*child, depth);
86  return result.str();
87 }
std::vector< std::tuple< const INode *, int, const INode * > > progenyPlus(const INode *node, int level=0)
Returns a vector of triples (descendant, depth, parent)
Definition: NodeUtils.cpp:69

References progenyPlus().

Referenced by INode::treeToString().

Here is the call graph for this function:

◆ progenyPlus()

std::vector< std::tuple< const INode *, int, const INode * > > NodeUtils::progenyPlus ( const INode node,
int  level = 0 
)

Returns a vector of triples (descendant, depth, parent)

Definition at line 69 of file NodeUtils.cpp.

71 {
72  std::vector<std::tuple<const INode*, int, const INode*>> result;
73  result.push_back({node, level, nullptr});
74  for (const auto* child : node->getChildren()) {
75  for (const auto& [subchild, sublevel, subparent] : progenyPlus(child, level + 1))
76  result.push_back({subchild, sublevel, child});
77  }
78  return result;
79 }
virtual std::vector< const INode * > getChildren() const
Returns a vector of children.
Definition: INode.cpp:63

References INode::getChildren().

Referenced by nodeToString(), and GUIDomainSampleVisitor::populateSampleModel().

Here is the call graph for this function: