The Gaudi Framework  master (82fdf313)
Loading...
Searching...
No Matches
Node.cpp
Go to the documentation of this file.
1/***********************************************************************************\
2* (c) Copyright 1998-2025 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#include "Node.h"
12#include <numeric>
13
14namespace gp = Gaudi::Parsers;
15
16std::vector<std::string> init_names() {
17 std::vector<std::string> n( gp::Node::NodeType::number_of_node_types );
18 n[gp::Node::NodeType::kRoot] = "root";
19 n[gp::Node::NodeType::kInclude] = "include";
20 n[gp::Node::NodeType::kIdentifier] = "identifier";
21 n[gp::Node::NodeType::kProperty] = "property";
22 n[gp::Node::NodeType::kOperation] = "operation";
23 n[gp::Node::NodeType::kValue] = "value";
24 n[gp::Node::NodeType::kAssign] = "assign";
25 n[gp::Node::NodeType::kEqual] = "equal";
26 n[gp::Node::NodeType::kPlusEqual] = "plus_equal";
27 n[gp::Node::NodeType::kMinusEqual] = "minus_equal";
28 n[gp::Node::NodeType::kVector] = "vector";
29 n[gp::Node::NodeType::kMap] = "map";
30 n[gp::Node::NodeType::kPair] = "pair";
31 n[gp::Node::NodeType::kSimple] = "simple";
32 n[gp::Node::NodeType::kString] = "string";
33 n[gp::Node::NodeType::kReal] = "real";
34 n[gp::Node::NodeType::kBool] = "bool";
35 n[gp::Node::NodeType::kUnits] = "units";
36 n[gp::Node::NodeType::kUnit] = "unit";
37 n[gp::Node::NodeType::kCondition] = "condition";
38 n[gp::Node::NodeType::kIfdef] = "ifdef";
39 n[gp::Node::NodeType::kIfndef] = "ifndef";
40 n[gp::Node::NodeType::kElse] = "else";
41 n[gp::Node::NodeType::kPrintOptions] = "print_options";
42 n[gp::Node::NodeType::kPrintOn] = "print_on";
43 n[gp::Node::NodeType::kPrintOff] = "print_off";
44 n[gp::Node::NodeType::kShell] = "shell";
45 n[gp::Node::NodeType::kPrintTree] = "print_tree";
46 n[gp::Node::NodeType::kDumpFile] = "dump_file";
47 n[gp::Node::NodeType::kPropertyRef] = "property_ref";
48 return n;
49}
50
51std::string gp::Node::name() const {
52 static const auto names = init_names();
53 return names[type];
54}
55
56std::string gp::Node::ToString( int indent ) const {
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}
std::vector< std::string > init_names()
Definition Node.cpp:16
std::string value
Definition Node.h:58
Position position
Definition Node.h:60
std::vector< Node > children
Definition Node.h:59
NodeType type
Definition Node.h:57
std::string ToString(int indent=0) const
Definition Node.cpp:56
std::string name() const
Definition Node.cpp:51