xmlnode.h

00001 // --*-c++-*-- 00002 /* 00003 $Id: xmlnode_8h-source.html,v 1.1 2004/10/05 21:12:03 mentat Exp $ 00004 00005 GNU Messenger - The secure instant messenger 00006 Copyright (C) 2001-2002 Henrik Abelsson <henrik@abelsson.com> 00007 00008 This program is free software; you can redistribute it and/or modify 00009 it under the terms of the GNU General Public License as published by 00010 the Free Software Foundati 00011 on; either version 2 of the License, or 00012 (at your option) any later version. 00013 00014 This program is distributed in the hope that it will be useful, 00015 but WITHOUT ANY WARRANTY; without even the implied warranty of 00016 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00017 GNU General Public License for more details. 00018 00019 You should have received a copy of the GNU General Public License 00020 along with this program; if not, write to the Free Software 00021 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 00022 00023 */ 00024 00025 #ifndef GM_XMLNODE_H 00026 #define GM_XMLNODE_H 00027 00028 #include <iostream> 00029 #include <string> 00030 #include <map> 00031 #include <vector> 00032 #include "gm/exception.h" 00033 00034 namespace GNUMessenger 00035 { 00036 00037 using namespace std; 00038 class Contact; 00039 00042 00067 class XMLNode 00068 { 00069 public: 00070 00075 class InvalidChild: public Exception 00076 { 00077 public: 00078 InvalidChild(const string& error): Exception(error) {} 00079 }; 00080 00085 class ParseFailure: public Exception 00086 { 00087 public: 00088 ParseFailure(const string& error): Exception(error) {} 00089 }; 00090 00096 class NodeDestroyed: public Exception 00097 { 00098 public: 00099 NodeDestroyed(const string& error): Exception(error) {} 00100 }; 00101 00103 XMLNode(); 00104 00107 XMLNode(const XMLNode &other); 00108 00111 XMLNode(const Contact &other); 00112 00113 00114 virtual ~XMLNode(); 00115 00117 //virtual const string getName() const { return ""; } 00118 00119 virtual const string& name() const { return m_xmlData->m_name; } 00120 00121 virtual const string type() const { return "xml"; } 00122 00123 const string &data() const { return m_xmlData->m_data; } 00124 00126 map<string,string> &properties() { return m_xmlData->m_properties; } 00127 00129 const map<string,string> &const_properties() const { return m_xmlData->m_properties; } 00130 00132 const string property(const string &name) const; 00133 00135 int intProperty(const string &name) const; 00136 00140 bool hasChild(const string &name, int n=1) const; 00141 00143 unsigned int numChildren(const string &name) const; 00144 00146 vector<XMLNode> &children() { return m_xmlData->m_children; } 00147 00148 00150 vector<XMLNode> &const_children() const { return m_xmlData->m_children; } 00151 00156 XMLNode& child(const string &name, int n=1); 00157 00164 XMLNode child(const string& name, int n = 1) const; 00165 00167 inline XMLNode &setName(const string &name) { m_xmlData->m_name = name; return *this; } 00168 00170 inline XMLNode &setData(const string &data) { m_xmlData->m_data = data; return *this; } 00171 00173 XMLNode &setCData(const string &data) { m_xmlData->data_is_cdata=true; m_xmlData->m_data = data; return *this; } 00174 00176 XMLNode &setProperty(const string &name, const string &value); 00178 XMLNode &setProperty(const string &name, int value); 00179 00181 XMLNode &addChild( XMLNode &node) { m_xmlData->m_children.push_back(node); return node;} 00182 00184 XMLNode &addChild(const string &name, const string &data=""); 00185 00191 XMLNode &delChild(const string &name, int n=1); 00192 00194 XMLNode& moveChild(unsigned int index, unsigned int newIndex); 00195 00201 friend ostream& operator<<(ostream &o, XMLNode &n); 00202 00208 XMLNode &operator<<(const string &str) throw(ParseFailure); 00209 00216 XMLNode &operator=(const XMLNode &other); 00217 00219 operator string() const; 00220 00222 string& operator[](const string &name); 00223 00229 string operator[](const string &name) const; 00230 00231 friend class XMLParser; 00232 00233 00234 protected: 00235 00239 class XMLNodeData 00240 { 00241 public: 00242 XMLNodeData() 00243 { refCount=1; /*cout << (unsigned long)this << " created." << endl;*/ } 00244 00245 ~XMLNodeData() { /*cout << (unsigned long)this << " deleting." << endl;*/ } 00246 00249 inline void ref() { refCount++; } 00250 00253 inline bool deref() 00254 { if (--refCount == 0) return true; return false; } 00255 00256 vector<XMLNode> m_children; 00257 map <string,string> m_properties; 00258 00259 string m_name; 00260 string m_data; 00261 00262 private: 00263 int refCount; 00264 00265 public: 00266 bool data_is_cdata; 00267 bool oneline; 00268 }; 00269 00270 static bool m_isValid; 00271 00272 XMLNodeData *m_xmlData; 00273 }; 00274 00275 00276 } // !GNUMessenger 00277 00278 #endif // !GM_XMLNODE_H

Generated on Tue Oct 5 14:41:47 2004 for GNU Messenger by doxygen 1.3.8