00001
00002 #ifndef JOBOPTIONSVC_NODE_H_
00003 #define JOBOPTIONSVC_NODE_H_
00004
00005
00006
00007
00008
00009 #include <iostream>
00010 #include <string>
00011 #include <vector>
00012
00013
00014
00015
00016 #include <boost/fusion/include/adapt_struct.hpp>
00017 #include <boost/fusion/include/unused.hpp>
00018 #include <boost/range/iterator_range.hpp>
00019
00020 #include "Position.h"
00021 #include "Iterator.h"
00022
00023 namespace Gaudi { namespace Parsers {
00024
00025 class Node {
00026 public:
00027 enum NodeType {kRoot,kInclude, kIdentifier, kProperty, kOperation,
00028 kValue, kAssign, kEqual, kPlusEqual, kMinusEqual, kVector, kMap, kPair,
00029 kSimple, kString, kReal, kBool, kUnits, kUnit, kCondition, kIfdef, kIfndef,
00030 kElse, kPrintOptions, kPrintOn, kPrintOff, kShell, kPrintTree, kDumpFile,
00031 kPropertyRef};
00032 NodeType type;
00033 std::string value;
00034 std::vector<Node> children;
00035 Position position;
00036
00037 Node(): type(kRoot){}
00038 std::string name() const;
00039 std::string ToString() const;
00040 std::string ToString(int indent) const;
00041 };
00042
00043 class NodeOperations {
00044 public:
00045 struct value {};
00046 template<typename A, typename B = boost::fusion::unused_type,
00047 typename C = boost::fusion::unused_type,
00048 typename D = boost::fusion::unused_type>
00049 struct result {
00050 typedef void type;
00051 };
00052
00053 void operator()(Node& node, Node::NodeType type) const {
00054 node.type = type;
00055 }
00056
00057 void operator()(Node& node, Node& child) const {
00058 node.children.push_back(child);
00059 }
00060
00061 void operator()(Node& node, const std::string& val) const {
00062 node.value = val;
00063 }
00064
00065 void operator()(Node& node, boost::iterator_range<Iterator> range) const {
00066 node.value = boost::copy_range<std::string>(range);
00067 }
00068
00069 void operator()(Node& node, bool val) const {
00070 node.value = val?"1":"0";
00071 }
00072
00073 void operator()(Node& node, const Iterator& iter) const {
00074 const IteratorPosition& pos = iter.get_position();
00075 node.position = Position(pos.file, pos.line, pos.column);
00076 }
00077
00078
00079 };
00080
00081 } }
00082
00083 BOOST_FUSION_ADAPT_STRUCT(
00084 Gaudi::Parsers::Node,
00085 (Gaudi::Parsers::Node::NodeType, type)
00086 (std::string, value)
00087 (std::vector<Gaudi::Parsers::Node>, children)
00088 )
00089
00090 #endif // JOBOPTIONSVC_NODE_H_