00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 #ifndef Twig_hpp
00025 #define Twig_hpp 1
00026
00027 #include <iostream>
00028 #include <string>
00029 #include <map>
00030 #include <list>
00031 #include <cassert>
00032
00033 #include "UAP/UAPNode.hpp"
00034
00035
00036
00037
00041 struct AttributeID {
00042
00043 AttributeID ();
00044 AttributeID (std::string name, std::string value);
00045
00046 std::string name;
00047 std::string value;
00048 };
00049
00050
00051
00052
00053 typedef std::vector<AttributeID> AttributeIDVec;
00054 typedef std::vector<AttributeID>::iterator AttributeIDVecIter;
00055 typedef std::vector<AttributeID>::const_iterator AttributeIDVecCIter;
00056
00057
00058
00062 class NodeID {
00063
00064 public:
00065
00070 void addAttribute(std::string name, std::string value);
00071
00077 UAPNode* getChild(UAPNode* parent, bool create = false);
00078
00082 std::string toString () const;
00083
00084 bool operator== (const NodeID& n) const;
00085 bool operator== (UAPNode* u);
00086
00087
00088
00089 std::string name;
00090 std::string xml_local_name;
00091 std::string xml_prefix;
00092 std::string xml_uri;
00093 AttributeIDVec attribute;
00094 };
00095
00096
00097
00098
00099 typedef std::vector<NodeID> NodeIDVec;
00100 typedef std::vector<NodeID>::iterator NodeIDVecIter;
00101 typedef std::vector<NodeID>::reverse_iterator NodeIDVecRIter;
00102 typedef std::vector<NodeID>::const_iterator NodeIDVecCIter;
00103
00104 bool operator== (const NodeIDVec& x, const NodeIDVec& y);
00105
00106
00107
00108
00184 class Twig {
00185
00186 public:
00187
00190 Twig ();
00191
00195 Twig (std::string twig_str, bool has_ele_name = false);
00196
00209 bool fromString (std::string trig_str, bool has_ele_name = false);
00210
00214 std::string toString ();
00215
00220 std::string toNodeString (bool include_target_attrib = false);
00221
00232 UAPNode* getLocalSubNode (UAPNode* root, bool create = false);
00233
00244 static UAPNode* getLocalSubNode (UAPNode* root, std::string twig_str, bool create = false);
00245
00250 UAPNode* getSubNode (UAPNode* root);
00251
00257 static NodeVec getSubNodes (UAPNode* root, std::string twig_str);
00258
00263 NodeVec getSubNodes (UAPNode* root);
00264
00272 bool matchNameAndPrefix (UAPNode* named_node);
00273
00277 bool operator== (Twig t);
00278
00279 public:
00280
00281
00282
00283 std::string name;
00284 StrList prefix;
00285 NodeIDVec nodeid_vec;
00286 std::string target_attribute;
00287 bool has_brackets;
00288
00289 private:
00290
00291 StrList break_line_into_words(std::string line, bool& ok);
00292 static UAPNode* get_sub_node (UAPNode* root, NodeID node0, NodeIDVec id_vec);
00293 static void get_sub_nodes (UAPNode* root, NodeID node0,
00294 NodeIDVec id_vec, NodeVec& node_vec);
00295 static void get_local_sub_nodes (UAPNode* root, NodeIDVec id_vec, NodeVec& node_vec);
00296 bool matchName (std::string twig_name, std::string node_name);
00297 bool matchPrefix (StrList& twig_prefix, StrListCIter twig_iter,
00298 StrList& node_prefix, StrListCIter node_iter);
00299
00300 void nodeid_vec_push_back (NodeID& node, const std::string& twig_str);
00301
00302 };
00303
00304 #endif