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

Functions

std::string nodeToString (const INode &node)
 
std::string nodePath (const INode &node, const INode *root=nullptr)
 

Function Documentation

◆ nodeToString()

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

Returns multiline string representing tree structure starting from given node.

Definition at line 67 of file NodeUtils.cpp.

68 {
69  std::ostringstream result;
70 
72  it.first();
73  while (!it.isDone()) {
74  const INode* child = it.getCurrent();
75  result << nodeString(*child, it.depth() - 1);
76  it.next();
77  }
78 
79  return result.str();
80 }
Base class for tree-like structures containing parameterized objects.
Definition: INode.h:49
Iterator through INode tree of objects.
Definition: NodeIterator.h:90
std::string nodeString(const INode &node, int depth)
Definition: NodeUtils.cpp:59

References NodeIterator< Strategy >::depth(), NodeIterator< Strategy >::first(), NodeIterator< Strategy >::getCurrent(), NodeIterator< Strategy >::isDone(), NodeIterator< Strategy >::next(), and anonymous_namespace{NodeUtils.cpp}::nodeString().

Referenced by INode::treeToString().

Here is the call graph for this function:

◆ 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 82 of file NodeUtils.cpp.

83 {
84  std::vector<std::string> pathElements;
85  const INode* current = &node;
86  while (current && current != root) {
87  pathElements.push_back(current->displayName());
88  pathElements.push_back("/");
89  current = current->parent();
90  }
91 
92  if (root != nullptr && current != root) {
93  throw Exceptions::RuntimeErrorException("NodeUtils::nodePath() -> Error. Node doesn't "
94  "belong to root's branch");
95  }
96 
97  std::reverse(pathElements.begin(), pathElements.end());
98  std::ostringstream result;
99  std::copy(pathElements.begin(), pathElements.end(), std::ostream_iterator<std::string>(result));
100  return result.str();
101 }
std::string displayName() const
Returns display name, composed from the name of node and it's copy number.
Definition: INode.cpp:105
const INode * parent() const
Definition: INode.cpp:74

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

Referenced by INode::createParameterTree().

Here is the call graph for this function: