Loading [MathJax]/extensions/tex2jax.js
The Gaudi Framework  v31r0 (aeb156f0)
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
Node.cpp
Go to the documentation of this file.
1 // ============================================================================
2 // Includes:
3 // ============================================================================
4 #include "Node.h"
5 #include <algorithm>
6 #include <numeric>
7 // ============================================================================
8 namespace gp = Gaudi::Parsers;
9 // ============================================================================
10 
12  std::vector<std::string> n( gp::Node::NodeType::number_of_node_types );
13  n[gp::Node::NodeType::kRoot] = "root";
14  n[gp::Node::NodeType::kInclude] = "include";
15  n[gp::Node::NodeType::kIdentifier] = "identifier";
16  n[gp::Node::NodeType::kProperty] = "property";
17  n[gp::Node::NodeType::kOperation] = "operation";
18  n[gp::Node::NodeType::kValue] = "value";
19  n[gp::Node::NodeType::kAssign] = "assign";
20  n[gp::Node::NodeType::kEqual] = "equal";
21  n[gp::Node::NodeType::kPlusEqual] = "plus_equal";
22  n[gp::Node::NodeType::kMinusEqual] = "minus_equal";
23  n[gp::Node::NodeType::kVector] = "vector";
24  n[gp::Node::NodeType::kMap] = "map";
25  n[gp::Node::NodeType::kPair] = "pair";
26  n[gp::Node::NodeType::kSimple] = "simple";
27  n[gp::Node::NodeType::kString] = "string";
28  n[gp::Node::NodeType::kReal] = "real";
29  n[gp::Node::NodeType::kBool] = "bool";
30  n[gp::Node::NodeType::kUnits] = "units";
31  n[gp::Node::NodeType::kUnit] = "unit";
32  n[gp::Node::NodeType::kCondition] = "condition";
33  n[gp::Node::NodeType::kIfdef] = "ifdef";
34  n[gp::Node::NodeType::kIfndef] = "ifndef";
35  n[gp::Node::NodeType::kElse] = "else";
36  n[gp::Node::NodeType::kPrintOptions] = "print_options";
37  n[gp::Node::NodeType::kPrintOn] = "print_on";
38  n[gp::Node::NodeType::kPrintOff] = "print_off";
39  n[gp::Node::NodeType::kShell] = "shell";
40  n[gp::Node::NodeType::kPrintTree] = "print_tree";
41  n[gp::Node::NodeType::kDumpFile] = "dump_file";
42  n[gp::Node::NodeType::kPropertyRef] = "property_ref";
43  return n;
44 }
45 
46 // ============================================================================
48  static const auto names = init_names();
49  return names[type];
50 }
51 
52 // ============================================================================
53 std::string gp::Node::ToString( int indent ) const {
54 
55  std::string result( indent, ' ' );
56  result += "<" + name();
57  if ( !value.empty() ) result += " value=\"" + value + "\"";
58  if ( position.line() != 0 ) result += " line=\"" + std::to_string( position.line() ) + "\"";
59  if ( position.column() != 0 ) result += " column=\"" + std::to_string( position.column() ) + "\"";
60  if ( children.empty() ) {
61  result += "/>\n";
62  } else {
63  result = std::accumulate( std::begin( children ), std::end( children ), result + ">\n",
64  [&]( std::string s, const gp::Node& node ) { return s + node.ToString( indent + 2 ); } )
65  .append( ' ', indent ) +
66  "</" + name() + ">\n";
67  }
68  return result;
69 }
70 // ============================================================================
std::vector< std::string > init_names()
Definition: Node.cpp:11
T to_string(T...args)
T end(T...args)
STL class.
T begin(T...args)
string s
Definition: gaudirun.py:312
T accumulate(T...args)