The Gaudi Framework  v29r0 (ff2e7097)
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 {
13  std::vector<std::string> n( gp::Node::NodeType::number_of_node_types );
14  n[gp::Node::NodeType::kRoot] = "root";
15  n[gp::Node::NodeType::kInclude] = "include";
16  n[gp::Node::NodeType::kIdentifier] = "identifier";
17  n[gp::Node::NodeType::kProperty] = "property";
18  n[gp::Node::NodeType::kOperation] = "operation";
19  n[gp::Node::NodeType::kValue] = "value";
20  n[gp::Node::NodeType::kAssign] = "assign";
21  n[gp::Node::NodeType::kEqual] = "equal";
22  n[gp::Node::NodeType::kPlusEqual] = "plus_equal";
23  n[gp::Node::NodeType::kMinusEqual] = "minus_equal";
24  n[gp::Node::NodeType::kVector] = "vector";
25  n[gp::Node::NodeType::kMap] = "map";
26  n[gp::Node::NodeType::kPair] = "pair";
27  n[gp::Node::NodeType::kSimple] = "simple";
28  n[gp::Node::NodeType::kString] = "string";
29  n[gp::Node::NodeType::kReal] = "real";
30  n[gp::Node::NodeType::kBool] = "bool";
31  n[gp::Node::NodeType::kUnits] = "units";
32  n[gp::Node::NodeType::kUnit] = "unit";
33  n[gp::Node::NodeType::kCondition] = "condition";
34  n[gp::Node::NodeType::kIfdef] = "ifdef";
35  n[gp::Node::NodeType::kIfndef] = "ifndef";
36  n[gp::Node::NodeType::kElse] = "else";
37  n[gp::Node::NodeType::kPrintOptions] = "print_options";
38  n[gp::Node::NodeType::kPrintOn] = "print_on";
39  n[gp::Node::NodeType::kPrintOff] = "print_off";
40  n[gp::Node::NodeType::kShell] = "shell";
41  n[gp::Node::NodeType::kPrintTree] = "print_tree";
42  n[gp::Node::NodeType::kDumpFile] = "dump_file";
43  n[gp::Node::NodeType::kPropertyRef] = "property_ref";
44  return n;
45 }
46 
47 // ============================================================================
49 {
50  static const auto names = init_names();
51  return names[type];
52 }
53 
54 // ============================================================================
55 std::string gp::Node::ToString( int indent ) const
56 {
57 
58  std::string result( indent, ' ' );
59  result += "<" + name();
60  if ( !value.empty() ) result += " value=\"" + value + "\"";
61  if ( position.line() != 0 ) result += " line=\"" + std::to_string( position.line() ) + "\"";
62  if ( position.column() != 0 ) result += " column=\"" + std::to_string( position.column() ) + "\"";
63  if ( children.empty() ) {
64  result += "/>\n";
65  } else {
66  result = std::accumulate( std::begin( children ), std::end( children ), result + ">\n",
67  [&]( std::string s, const gp::Node& node ) { return s + node.ToString( indent + 2 ); } )
68  .append( ' ', indent ) +
69  "</" + name() + ">\n";
70  }
71  return result;
72 }
73 // ============================================================================
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:253
T accumulate(T...args)