Line data Source code
1 : /* 2 : * Copyright (c) 2013 Juniper Networks, Inc. All rights reserved. 3 : * Copyright Contributors to the OpenSDN project 4 : */ 5 : 6 : #ifndef __XML_BASE_H__ 7 : #define __XML_BASE_H__ 8 : 9 : #include "base/util.h" 10 : 11 : class XmlBase { 12 : 13 : public: 14 : // Set new xml doc. Null string means reset to new doc. 15 : // Resets previous doc 16 : virtual int LoadDoc(const std::string &doc) = 0; 17 : 18 : // returns bytes encoded. -1 for error. 19 : virtual int WriteDoc(uint8_t *buf)= 0; 20 : virtual int WriteRawDoc(uint8_t *buf) = 0; 21 : 22 : // prints the xml doc to ostream 23 : virtual void PrintDoc(std::ostream& os) const = 0; 24 : 25 : // Create child node and move node context to new node 26 : virtual int AddChildNode(const std::string &key, const std::string &value) = 0; 27 : 28 : // Create child node after node-name and move node context to new node 29 : virtual int AddChildNodeAfter(const std::string &node_name, 30 : const std::string &key, const std::string &value) = 0; 31 : 32 : // Create new node as sibling of node in context. Set context to new node 33 : virtual int AddNode(const std::string &key, const std::string &value) = 0; 34 : 35 : // Delete node 36 : virtual int DeleteNode(const std::string &key) = 0; 37 : 38 : // Find child node by key and set its value. Set context to new node. 39 : virtual int ModifyNode(const std::string &key, const std::string &value) = 0; 40 : 41 : // Add attriburte to current node context. Sets context to new attrib. 42 : virtual int AddAttribute(const std::string &key, const std::string &value) = 0; 43 : 44 : // Modify attriburte to current node context. Sets context to new attrib. 45 : virtual int ModifyAttribute(const std::string &key, const std::string &value) = 0; 46 : 47 : // Delete attribute, if exist, at current node context. Sets context to 48 : // next available attrib. 49 : virtual int DeleteAttribute(const std::string &key) = 0; 50 : 51 : // Return 'value' of given node 'name'. Set context to given node. 52 : virtual const char *ReadNode(const std::string &name) = 0; 53 : 54 : // Return 'value' of given node 'name'. Set context to given node. 55 : virtual const char *ReadNodeName(const std::string &name) = 0; 56 : 57 : // Return 'value' of given node. 58 : virtual const char *ReadNodeValue() = 0; 59 : 60 : // Moves node context to first child node. 61 : virtual const char *ReadChildNode() = 0; 62 : 63 : // Moves node context to first child node. 64 : virtual const char *ReadChildNodeName() = 0; 65 : 66 : // Get next sibling. Moves node context to next sibling 67 : virtual const char *ReadNextNode() = 0; 68 : 69 : // Get next sibling. Moves node context to next sibling 70 : virtual const char *ReadNextNodeName() = 0; 71 : 72 : // Moves node context to immediate parent 73 : virtual void RewindNode() = 0; 74 : 75 : virtual const char *ReadAttrib(const std::string &str) = 0; 76 : virtual const char *ReadFirstAttrib() = 0; 77 : virtual const char *ReadNextAttrib() = 0; 78 : virtual void RewindAttrib() = 0; 79 : 80 : // Get Parent node. Move node context to parent 81 : virtual const char *ReadParentName() = 0; 82 : 83 : virtual void RewindDoc() = 0; 84 : virtual void AppendDoc(const std::string &str, XmlBase *a_doc) = 0; 85 : 86 4165224 : virtual ~XmlBase() { } 87 4165218 : XmlBase() {} 88 : }; 89 : 90 : struct XmppXmlImplFactory { 91 : public: 92 : 93 : XmlBase *GetXmlImpl() ; 94 : void ReleaseXmlImpl(XmlBase *tmp); 95 : 96 : static XmppXmlImplFactory *Instance(); 97 : 98 : private: 99 : //singleton 100 366 : XmppXmlImplFactory() { } 101 : static XmppXmlImplFactory *Inst_; 102 : 103 : DISALLOW_COPY_AND_ASSIGN(XmppXmlImplFactory); 104 : }; 105 : 106 : #endif // __XML_BASE_H__