GNUMessenger::XMLNode Class Reference
[XML]

#include <xmlnode.h>

Inheritance diagram for GNUMessenger::XMLNode:

Inheritance graph
[legend]
Collaboration diagram for GNUMessenger::XMLNode:

Collaboration graph
[legend]
List of all members.

Public Member Functions

 XMLNode ()
 Default constructor, allocates XMLNodeData.
 XMLNode (const XMLNode &other)
 Constructs the object as a counted reference of the given object.
 XMLNode (const Contact &other)
 Creates an XMLNode from a Contact object.
virtual const string & name () const
 a virtual function to return a 'name'
virtual const string type () const
const string & data () const
map< string, string > & properties ()
 Return all properties.
const map< string, string > & const_properties () const
 Return all properties (read only).
const string property (const string &name) const
 Return a single property.
int intProperty (const string &name) const
 Return property as an integer if possible, otherwise 0.
bool hasChild (const string &name, int n=1) const
 True if the node has a child with the specified name.
unsigned int numChildren (const string &name) const
 Return how many children of a specified name there is in the node.
vector< XMLNode > & children ()
 Return all children.
vector< XMLNode > & const_children () const
 Return all children (read only).
XMLNodechild (const string &name, int n=1)
 Return a single child.
XMLNode child (const string &name, int n=1) const
 Returns a child XMLNode.
XMLNodesetName (const string &name)
 Set tag name.
XMLNodesetData (const string &data)
 Set data.
XMLNodesetCData (const string &data)
 Set data as cdata sections.
XMLNodesetProperty (const string &name, const string &value)
 Set a property.
XMLNodesetProperty (const string &name, int value)
 Set a property integer type.
XMLNodeaddChild (XMLNode &node)
 Add a child node to the tree.
XMLNodeaddChild (const string &name, const string &data="")
 Add a child node to the tree.
XMLNodedelChild (const string &name, int n=1)
 Delete a child node, throws InvalidNode.
XMLNodemoveChild (unsigned int index, unsigned int newIndex)
 moves the child at position index to in front of position newIndex
XMLNodeoperator<< (const string &str) throw (ParseFailure)
 Parse a string into a XMLNode directly.
XMLNodeoperator= (const XMLNode &other)
 Assignment operator.
 operator string () const
 Implicitly convert to string.
string & operator[] (const string &name)
 Set and get tag properties using operator[].
string operator[] (const string &name) const
 Returns tag properties using overloaded operator [].

Protected Attributes

XMLNodeDatam_xmlData

Static Protected Attributes

bool m_isValid

Friends

ostream & operator<< (ostream &o, XMLNode &n)
 Outputs the XMLNode to an std output stream.

Detailed Description

An XML Tag represented as a single class.

This is a parsed xml tag. It stores all properties and all nested nodes and the text between the start tag. It can be used as a combined tree, array and associative map data structure without any artificial size limits.

Terminology:

Example:
 <tag property1="value" property2="a value">
 .. some text here ..
 </tag>
 

Author:
Henrik Abelsson

Definition at line 67 of file xmlnode.h.


Constructor & Destructor Documentation

GNUMessenger::XMLNode::XMLNode const XMLNode other  ) 
 

Constructs the object as a counted reference of the given object.

Parameters:
other The XMLNode to be referenced
Definition at line 52 of file xmlnode.cpp.

References m_xmlData, and GNUMessenger::XMLNode::XMLNodeData::ref().

00053 { 00054 other.m_xmlData->ref(); 00055 m_xmlData=other.m_xmlData; 00056 }

Here is the call graph for this function:

GNUMessenger::XMLNode::XMLNode const Contact other  ) 
 

Creates an XMLNode from a Contact object.

Parameters:
other The Contact to be referenced/converted
Definition at line 58 of file xmlnode.cpp.

References m_xmlData, and GNUMessenger::XMLNode::XMLNodeData::ref().

00059 { 00060 other.m_xmlData->ref(); 00061 m_xmlData=other.m_xmlData; 00062 }

Here is the call graph for this function:


Member Function Documentation

XMLNode GNUMessenger::XMLNode::child const string &  name,
int  n = 1
const
 

Returns a child XMLNode.

Parameters:
name The name of the XMLNode child
n The index of the child if more then one child share a name
Exceptions:
InvalidChild is thrown if the child does not exist
Definition at line 175 of file xmlnode.cpp.

References GNUMessenger::XMLNode::XMLNodeData::m_children, and XMLNode().

00176 { 00177 vector<XMLNode>::const_iterator it; 00178 00179 for(it=m_xmlData->m_children.begin(); it!=m_xmlData->m_children.end(); it++) 00180 { 00181 if (it->m_xmlData->m_name == name) 00182 n--; 00183 if (n == 0) 00184 return *it; 00185 } 00186 LOG_THROW(string("Child: ") + name + string(" could not be found in: ") + this->name(), InvalidChild); 00187 00188 return XMLNode(); 00189 }

Here is the call graph for this function:

XMLNode & GNUMessenger::XMLNode::child const string &  name,
int  n = 1
 

Return a single child.

Parameters:
name name of tag to look for
n which tag to return if there are more than one
Note:
If this child does not exist it will be added to the tree
Definition at line 150 of file xmlnode.cpp.

References GNUMessenger::XMLNode::XMLNodeData::m_children, and setName().

Referenced by GNUMessenger::ContactManager::addContact(), GNUMessenger::Contact::addProtocol(), GNUMessenger::XMLManager::baseSearch(), GNUMessenger::ContactManager::deleteAllInfo(), GNUMessenger::ContactManager::deleteAllNets(), GNUMessenger::ContactManager::deleteContact(), GNUMessenger::ContactManager::deleteFolder(), GNUMessenger::ContactManager::deleteInfo(), GNUMessenger::ContactManager::getAllContacts(), GNUMessenger::XMLManager::getAllTags(), GNUMessenger::ContactManager::getCount(), GNUMessenger::ContactManager::getFolder(), GNUMessenger::NetConf::getLoginServer(), GNUMessenger::Contact::getOverallStatus(), GNUMessenger::Contact::getProtocol(), GNUMessenger::ContactManager::getPublicKey(), GNUMessenger::NetConf::getServer(), GNUMessenger::Contact::getServerId(), GNUMessenger::Contact::getStatus(), GNUMessenger::ContactManager::getXML(), GNUMessenger::Contact::hasProtocol(), GNUMessenger::TocProtocol::login(), GNUMessenger::ContactManager::moveContact(), GNUMessenger::ContactManager::renameContact(), GNUMessenger::XMLManager::search(), GNUMessenger::ContactManager::setInfo(), GNUMessenger::NetConf::setServer(), GNUMessenger::Contact::setServerId(), and GNUMessenger::Contact::setStatus().

00151 { 00152 vector<XMLNode>::iterator it; 00153 00154 for(it=m_xmlData->m_children.begin(); it!=m_xmlData->m_children.end(); it++) 00155 { 00156 if (it->m_xmlData->m_name == name) 00157 n--; 00158 if (n == 0) { 00159 // LOG_DEBUG("Found child"); 00160 return *it; 00161 } 00162 } 00163 00164 LOG_DEBUG("Adding new child, child not found."); 00165 00166 XMLNode newNode; 00167 00168 newNode.setName(name); 00169 00170 return *(m_xmlData->m_children.insert(m_xmlData->m_children.end(), newNode)); 00171 00172 }

Here is the call graph for this function:

XMLNode & GNUMessenger::XMLNode::delChild const string &  name,
int  n = 1
 

Delete a child node, throws InvalidNode.

Parameters:
name name of tag to look for
n which tag to delete if there are more than one
Definition at line 216 of file xmlnode.cpp.

References GNUMessenger::XMLNode::XMLNodeData::m_children.

Referenced by GNUMessenger::ContactManager::deleteAllInfo(), GNUMessenger::ContactManager::deleteAllNets(), GNUMessenger::ContactManager::deleteContact(), GNUMessenger::ContactManager::deleteFolder(), GNUMessenger::ContactManager::deleteInfo(), and GNUMessenger::ContactManager::moveContact().

00217 { 00218 00219 vector<XMLNode>::iterator it; 00220 00221 for(it=m_xmlData->m_children.begin(); it!=m_xmlData->m_children.end(); it++) 00222 { 00223 if (it->m_xmlData->m_name == name) 00224 n--; 00225 00226 if (n == 0) 00227 { 00228 m_xmlData->m_children.erase(it); 00229 return *this; 00230 } 00231 } 00232 00233 LOG_THROW("delChild: InvalidChild", InvalidChild); 00234 00235 return *this; //To get rid of warning 00236 }

bool GNUMessenger::XMLNode::hasChild const string &  name,
int  n = 1
const
 

True if the node has a child with the specified name.

Parameters:
name name of tag to look for
n how many tags are required (n=2 means there has to be two children with the specified name)
Definition at line 75 of file xmlnode.cpp.

References GNUMessenger::XMLNode::XMLNodeData::m_children.

Referenced by GNUMessenger::Contact::addProtocol(), GNUMessenger::Contact::getOverallStatus(), GNUMessenger::Contact::getProtocol(), GNUMessenger::Contact::getServerId(), GNUMessenger::Contact::getStatus(), GNUMessenger::Contact::hasProtocol(), GNUMessenger::Contact::setServerId(), and GNUMessenger::Contact::setStatus().

00076 { 00077 00078 vector<XMLNode>::const_iterator it; 00079 00080 for(it=m_xmlData->m_children.begin(); it!=m_xmlData->m_children.end(); it++) 00081 { 00082 if (it->m_xmlData->m_name == name) 00083 n--; 00084 if (n == 0) 00085 return true; 00086 } 00087 00088 return false; 00089 }

XMLNode & GNUMessenger::XMLNode::operator<< const string &  str  )  throw (ParseFailure)
 

Parse a string into a XMLNode directly.

Parameters:
str The string to parse into an XMLNode
Exceptions:
ParseFailure if the text could not be parsed into an XMLNode
Definition at line 311 of file xmlnode.cpp.

References GNUMessenger::XMLParser::get_root().

00312 { 00313 00314 try 00315 { 00316 XMLParser p(str); 00317 *this = p.get_root(); 00318 } 00319 catch(XMLParser::ParseFailure &e) 00320 { 00321 LOG_THROW(e.what(), ParseFailure); 00322 } 00323 catch(...) 00324 { 00325 LOG_THROW("Unexpected exception from parse failure.", ParseFailure); 00326 } 00327 00328 return *this; 00329 }

Here is the call graph for this function:

XMLNode & GNUMessenger::XMLNode::operator= const XMLNode other  ) 
 

Assignment operator.

Parameters:
other The XMLNode object to assign to this object
Note:
This function will be valid regardless if the XMLNode has been destroyed
Definition at line 331 of file xmlnode.cpp.

References GNUMessenger::XMLNode::XMLNodeData::deref(), m_xmlData, and GNUMessenger::XMLNode::XMLNodeData::ref().

00332 { 00333 if (!other.m_xmlData) 00334 return *this; 00335 00336 if (other.m_xmlData == m_xmlData) 00337 return *this; 00338 00339 00342 if (other.m_xmlData) 00343 other.m_xmlData->ref(); 00344 00345 00346 if (m_xmlData && m_xmlData->deref()) 00347 { 00348 delete m_xmlData; 00349 m_xmlData=0; 00350 } 00351 00352 00353 00354 m_xmlData=other.m_xmlData; 00355 return *this; 00356 }

Here is the call graph for this function:

string GNUMessenger::XMLNode::operator[] const string &  name  )  const
 

Returns tag properties using overloaded operator [].

Parameters:
name The name of the property to return
Exceptions:
InvalidNode if the property does not exist
Definition at line 287 of file xmlnode.cpp.

References GNUMessenger::XMLNode::XMLNodeData::m_properties.

00288 { 00289 00290 map<string,string>::const_iterator it=m_xmlData->m_properties.find(name); 00291 00292 if (it==m_xmlData->m_properties.end()) 00293 return ""; 00294 else 00295 return it->second; 00296 00297 LOG_THROW("The specified child does not exist.", InvalidChild); 00298 }


Friends And Related Function Documentation

ostream& operator<< ostream &  o,
XMLNode n
[friend]
 

Outputs the XMLNode to an std output stream.

Parameters:
o A reference to the output stream
n A reference to an XMLNode
Definition at line 300 of file xmlnode.cpp.
00301 { 00302 00303 string str; 00304 00305 XMLParser::printTag(n,str); 00306 o << str; 00307 00308 return o; 00309 }


The documentation for this class was generated from the following files:
Generated on Tue Oct 5 14:42:00 2004 for GNU Messenger by doxygen 1.3.8