Go to the documentation of this file.00001
00002
00003
00004
00005 #include "Node.h"
00006
00007
00008
00009 #include <boost/foreach.hpp>
00010 #include <boost/format.hpp>
00011
00012 namespace gp = Gaudi::Parsers;
00013
00014 void tab(std::string* str, int indent) {
00015 for (int i = 0; i < indent; ++i)
00016 *str += ' ';
00017 }
00018
00019 std::string names[100];
00020
00021 std::string gp::Node::name() const {
00022 static bool init = false;
00023 if (!init) {
00024 names[kRoot] = "root";
00025 names[kInclude] = "include";
00026 names[kIdentifier] = "identifier";
00027 names[kProperty] = "property";
00028 names[kOperation] = "operation";
00029 names[kValue] = "value";
00030 names[kAssign] = "assign";
00031 names[kEqual] = "equal";
00032 names[kPlusEqual] = "plus_equal";
00033 names[kMinusEqual] = "minus_equal";
00034 names[kVector] = "vector";
00035 names[kMap] = "map";
00036 names[kPair] = "pair";
00037 names[kSimple] = "simple";
00038 names[kString] = "string";
00039 names[kReal] = "real";
00040 names[kBool] = "bool";
00041 names[kUnits] = "units";
00042 names[kUnit] = "unit";
00043 names[kCondition] = "condition";
00044 names[kIfdef] = "ifdef";
00045 names[kIfndef] = "ifndef";
00046 names[kElse] = "else";
00047 names[kPrintOptions] = "print_options";
00048 names[kPrintOn] = "print_on";
00049 names[kPrintOff] = "print_off";
00050 names[kShell] = "shell";
00051 names[kPrintTree] = "print_tree";
00052 names[kDumpFile] = "dump_file";
00053 names[kPropertyRef] = "property_ref";
00054 }
00055 return names[type];
00056 }
00057
00058
00059 std::string gp::Node::ToString() const {
00060 return ToString(0);
00061 }
00062
00063 std::string gp::Node::ToString(int indent) const {
00064
00065 std::string result = "";
00066 tab(&result, indent);
00067 result += "<" + name();
00068 if (value != "")
00069 result += " value=\"" + value + "\"";
00070 if (position.line() != 0)
00071 result += " line=\"" + str(boost::format("%1%") % position.line())
00072 + "\"";
00073 if (position.column() != 0)
00074 result += " column=\"" + str(boost::format("%1%") % position.column())
00075 + "\"";
00076
00077 if (children.size() == 0) {
00078 result += "/>\n";
00079 } else {
00080 result += ">\n";
00081 BOOST_FOREACH(Node const& node, children)
00082 {
00083 result += node.ToString(indent + 2);
00084 }
00085 tab(&result, indent);
00086 result += str(boost::format("</%1%>\n") % name());
00087 }
00088 return result;
00089 }
00090