The Gaudi Framework  master (37c0b60a)
Node.cpp
Go to the documentation of this file.
1 /***********************************************************************************\
2 * (c) Copyright 1998-2019 CERN for the benefit of the LHCb and ATLAS collaborations *
3 * *
4 * This software is distributed under the terms of the Apache version 2 licence, *
5 * copied verbatim in the file "LICENSE". *
6 * *
7 * In applying this licence, CERN does not waive the privileges and immunities *
8 * granted to it by virtue of its status as an Intergovernmental Organization *
9 * or submit itself to any jurisdiction. *
10 \***********************************************************************************/
11 // ============================================================================
12 // Includes:
13 // ============================================================================
14 #include "Node.h"
15 #include <algorithm>
16 #include <numeric>
17 // ============================================================================
18 namespace gp = Gaudi::Parsers;
19 // ============================================================================
20 
22  std::vector<std::string> n( gp::Node::NodeType::number_of_node_types );
23  n[gp::Node::NodeType::kRoot] = "root";
24  n[gp::Node::NodeType::kInclude] = "include";
25  n[gp::Node::NodeType::kIdentifier] = "identifier";
26  n[gp::Node::NodeType::kProperty] = "property";
27  n[gp::Node::NodeType::kOperation] = "operation";
28  n[gp::Node::NodeType::kValue] = "value";
29  n[gp::Node::NodeType::kAssign] = "assign";
30  n[gp::Node::NodeType::kEqual] = "equal";
31  n[gp::Node::NodeType::kPlusEqual] = "plus_equal";
32  n[gp::Node::NodeType::kMinusEqual] = "minus_equal";
33  n[gp::Node::NodeType::kVector] = "vector";
34  n[gp::Node::NodeType::kMap] = "map";
35  n[gp::Node::NodeType::kPair] = "pair";
36  n[gp::Node::NodeType::kSimple] = "simple";
37  n[gp::Node::NodeType::kString] = "string";
38  n[gp::Node::NodeType::kReal] = "real";
39  n[gp::Node::NodeType::kBool] = "bool";
40  n[gp::Node::NodeType::kUnits] = "units";
41  n[gp::Node::NodeType::kUnit] = "unit";
42  n[gp::Node::NodeType::kCondition] = "condition";
43  n[gp::Node::NodeType::kIfdef] = "ifdef";
44  n[gp::Node::NodeType::kIfndef] = "ifndef";
45  n[gp::Node::NodeType::kElse] = "else";
46  n[gp::Node::NodeType::kPrintOptions] = "print_options";
47  n[gp::Node::NodeType::kPrintOn] = "print_on";
48  n[gp::Node::NodeType::kPrintOff] = "print_off";
49  n[gp::Node::NodeType::kShell] = "shell";
50  n[gp::Node::NodeType::kPrintTree] = "print_tree";
51  n[gp::Node::NodeType::kDumpFile] = "dump_file";
52  n[gp::Node::NodeType::kPropertyRef] = "property_ref";
53  return n;
54 }
55 
56 // ============================================================================
58  static const auto names = init_names();
59  return names[type];
60 }
61 
62 // ============================================================================
63 std::string gp::Node::ToString( int indent ) const {
64 
65  std::string result( indent, ' ' );
66  result += "<" + name();
67  if ( !value.empty() ) result += " value=\"" + value + "\"";
68  if ( position.line() != 0 ) result += " line=\"" + std::to_string( position.line() ) + "\"";
69  if ( position.column() != 0 ) result += " column=\"" + std::to_string( position.column() ) + "\"";
70  if ( children.empty() ) {
71  result += "/>\n";
72  } else {
73  result = std::accumulate( std::begin( children ), std::end( children ), result + ">\n",
74  [&]( std::string s, const gp::Node& node ) { return s + node.ToString( indent + 2 ); } )
75  .append( ' ', indent ) +
76  "</" + name() + ">\n";
77  }
78  return result;
79 }
80 // ============================================================================
std::string
STL class.
gaudirun.s
string s
Definition: gaudirun.py:346
std::vector< std::string >
Gaudi::Parsers::Node
Definition: Node.h:35
init_names
std::vector< std::string > init_names()
Definition: Node.cpp:21
Gaudi::Parsers::Node::name
std::string name() const
Definition: Node.cpp:57
Gaudi::Parsers::Node::ToString
std::string ToString(int indent=0) const
Definition: Node.cpp:63
Gaudi::Parsers::Node::type
NodeType type
Definition: Node.h:69
std::to_string
T to_string(T... args)
std::accumulate
T accumulate(T... args)
cpluginsvc.n
n
Definition: cpluginsvc.py:234
Node.h
ConditionsStallTest.name
name
Definition: ConditionsStallTest.py:77
std::begin
T begin(T... args)
Gaudi::Parsers
Definition: DODBasicMapper.cpp:17
std::end
T end(T... args)