00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025 #ifndef UAPNode_hpp
00026 #define UAPNode_hpp 1
00027
00028 #include <iostream>
00029 #include <string>
00030 #include <map>
00031 #include <list>
00032 #include <cassert>
00033
00034 #include "UAP/UAPAttribute.hpp"
00035 #include "UAP/UAPException.hpp"
00036
00037 class UAPNode;
00038
00042 typedef std::vector<UAPAttribute> AttributeVec;
00043 typedef std::vector<UAPAttribute>::iterator AttributeVecIter;
00044 typedef std::vector<UAPAttribute>::const_iterator AttributeVecCIter;
00045
00049 typedef std::vector<UAPNode*> NodeVec;
00050 typedef std::vector<UAPNode*>::iterator NodeVecIter;
00051 typedef std::vector<UAPNode*>::reverse_iterator NodeVecRevIter;
00052 typedef std::vector<UAPNode*>::const_iterator NodeVecCIter;
00053
00057 typedef std::map<Str, UAPNode*> NodeMap;
00058 typedef std::map<Str, UAPNode*>::iterator NodeMapIter;
00059 typedef std::map<Str, UAPNode*>::const_iterator NodeMapCIter;
00060
00062 enum UAPNode_type {ELEMENT_NODE, TEXT_NODE};
00063
00067 enum UAPNode_list {SLAVE, MASTER, CONTROLLER};
00068
00128 class UAPNode{
00129 public:
00130
00132 UAPNode();
00133
00139 UAPNode(enum UAPNode_type _type, const Str& _name);
00140
00146 UAPNode(const Str& _name);
00147
00151 UAPNode(const UAPNode& node);
00152
00156 Str getName() const;
00157
00161 void setName(const Str& _name);
00162
00167 void getPath(IntArray& path) const;
00168
00172 enum UAPNode_type getType() const;
00173
00177 void setType(enum UAPNode_type _type);
00178
00182 UAPNode* getParent() const;
00183
00187 void setParent(UAPNode* _parent);
00188
00192 UAPNode* getTwin() const;
00193
00197 void setTwin(UAPNode* _twin);
00198
00202 UAPNode* getConnect() const;
00203
00207 void setConnect(UAPNode* _connect);
00208
00214 UAPNode* detachNode();
00215
00219 void deleteNode();
00220
00226 NodeVec& getChildren();
00227
00233 NodeVecIter getChildIter (const UAPNode* child);
00234
00256 UAPNode* addChild(const Str& _name, enum UAPNode_type _type, UAPNode* old_child = NULL);
00257 UAPNode* addChild(const Str& _name, UAPNode* old_child = NULL,
00258 enum UAPNode_type _type = ELEMENT_NODE);
00259
00260
00269 UAPNode* addChild(UAPNode* node, const UAPNode* old_child = NULL);
00270
00279 UAPNode* addChildCopy(const UAPNode* node, const UAPNode* old_child = NULL);
00280
00287 AttributeVec& getAttributes();
00288
00294 UAPAttribute* getAttribute(const Str& _name);
00295
00309 UAPNode* addAttribute(const Str& _name, const Str& _value, bool allow_repeats=false);
00310
00317 Str getAttributeString(const Str& _name);
00318
00324 bool removeAttribute(const Str& _name);
00325
00331 NodeVec getChildrenByName(const Str& _name);
00332
00340 UAPNode* getChildByName (const Str& _name, bool create = false);
00341
00349 NodeVec getSubNodesByName(const Str& _name);
00350
00354 void getSubNodesByName(const Str& _name, NodeVec& nodeList);
00355
00359 int getChildIndexNumber () const;
00360
00369 UAPNode* add (UAPNode_list list_name, UAPNode* new_ele, UAPNode* old_ele = NULL);
00370
00379 UAPNode* add (UAPNode_list list_name, UAPNode* new_ele, NodeVecIter insert_pt);
00380
00387 NodeVec& getList(UAPNode_list list_name);
00388
00399 Str toString(int indent = 0, bool encode_all = true, const Str& prefix = "") const;
00400
00411 Str toStringTree(int indent = 0) const;
00412
00418 Str toXMLTree (int indent = 0) const;
00419
00424 void checkTree ();
00425
00429 Str getXMLURI() const;
00430
00434 void setXMLURI(const Str& uri);
00435
00439 Str getXMLPrefix() const;
00440
00444 void setXMLPrefix(const Str& prefix);
00445
00450 Str getQName () const;
00451
00456 Str getUniversalName () const;
00457
00471 void addXMLNSAttributes (bool close_to_root = true);
00472
00476 friend std::ostream& operator << (std::ostream& os, const UAPNode& node);
00477 friend std::ostream& operator << (std::ostream& os, const UAPNode* node);
00478
00479 private:
00480
00481
00482
00483 Str name;
00484
00485
00486
00487 Str xml_prefix;
00488
00489
00490 Str xml_uri;
00491
00492
00493 enum UAPNode_type type;
00494
00495
00496 UAPNode* parent;
00497
00498
00499 UAPNode* twin;
00500
00501
00502 UAPNode* connect;
00503
00504
00505 NodeVec children;
00506
00507
00508 AttributeVec attributes;
00509
00510
00511
00512 NodeVec slaves;
00513 NodeVec masters;
00514 NodeVec controllers;
00515
00516
00517
00518
00519
00520 int ix_child;
00521
00522
00523
00524
00525 void deleteTree2();
00526
00527
00528 Str toStringTree2(int indent, int depth) const;
00529
00530
00531 void setChildIndexNumber (const int ix_c);
00532
00533
00534 void getPath2(IntArray& path, int n) const;
00535
00536
00537 void add_xmlns_close_to_root(bool at_top_level, StrMap existing_xmlns, StrMap& needed_xmlns);
00538 void add_xmlns_far_from_root(StrMap existing_xmlns);
00539
00540 };
00541
00542 #endif