XMLStorage::XMLNode Struct Reference

in memory representation of an XML node More...

#include <xmlstorage.h>

Inheritance diagram for XMLStorage::XMLNode:

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

Collaboration graph
[legend]

Public Member Functions

 XMLNode (const XS_String &name)
 XMLNode (const XS_String &name, const std::string &leading)
 XMLNode (const XMLNode &other)
virtual ~XMLNode ()
void clear ()
XMLNodeoperator= (const XMLNode &other)
void add_child (XMLNode *child)
 add a new child node
void put (const XS_String &attr_name, const XS_String &value)
 write access to an attribute
XS_Stringoperator[] (const XS_String &attr_name)
 C++ write access to an attribute.
template<typename T>
XS_String get (const T &attr_name, LPCXSSTR def=XS_EMPTY_STR) const
 read only access to an attribute
XS_String subvalue (const XS_String &name, const XS_String &attr_name, int n=0) const
 convenient value access in children node
XS_Stringsubvalue (const XS_String &name, const XS_String &attr_name, int n=0)
 convenient storage of distinct values in children node
const Childrenget_children () const
Childrenget_children ()
const AttributeMapget_attributes () const
AttributeMapget_attributes ()
XS_String get_content () const
void set_content (const XS_String &s)
std::ostream & write (std::ostream &out, const XMLFormat &format, WRITE_MODE mode=FORMAT_SMART, int indent=0) const
 write node with children tree to output stream

Protected Member Functions

XMLNodeget_first_child () const
XMLNodefind (const XS_String &name, int n=0) const
XMLNodefind (const XS_String &name, const XS_String &attr_name, const XS_String &attr_value, int n=0) const
const XMLNodefind_relative (const char *path) const
 XPath find function (const).
XMLNodefind_relative (const char *path)
 XPath find function.
XMLNodecreate_relative (const char *path)
 relative XPath create function
void write_worker (std::ostream &out, int indent) const
void plain_write_worker (std::ostream &out) const
void pretty_write_worker (std::ostream &out, const XMLFormat &format, int indent) const
void smart_write_worker (std::ostream &out, const XMLFormat &format, int indent) const

Protected Attributes

Children _children
AttributeMap _attributes
std::string _leading
std::string _content
std::string _end_leading
std::string _trailing

Friends

struct XMLPos
struct const_XMLPos
struct XMLReaderBase

Data Structures

struct  AttributeMap
struct  Children
 internal children node list More...

Detailed Description

in memory representation of an XML node

Definition at line 683 of file xmlstorage.h.


Constructor & Destructor Documentation

XMLStorage::XMLNode::XMLNode ( const XS_String name  )  [inline]

Definition at line 763 of file xmlstorage.h.

00764      :  XS_String(name)
00765     {
00766     }

XMLStorage::XMLNode::XMLNode ( const XS_String name,
const std::string &  leading 
) [inline]

Definition at line 768 of file xmlstorage.h.

00769      :  XS_String(name),
00770         _leading(leading)
00771     {
00772     }

XMLStorage::XMLNode::XMLNode ( const XMLNode other  )  [inline]

Definition at line 774 of file xmlstorage.h.

References _children.

00775      :  XS_String(other),
00776         _attributes(other._attributes),
00777         _leading(other._leading),
00778         _content(other._content),
00779         _end_leading(other._end_leading),
00780         _trailing(other._trailing)
00781 #ifdef XMLNODE_LOCATION
00782         , _location(other._location)
00783 #endif
00784     {
00785         for(Children::const_iterator it=other._children.begin(); it!=other._children.end(); ++it)
00786             _children.push_back(new XMLNode(**it));
00787     }

virtual XMLStorage::XMLNode::~XMLNode (  )  [inline, virtual]

Definition at line 789 of file xmlstorage.h.

00790     {
00791         while(!_children.empty()) {
00792             delete _children.back();
00793             _children.pop_back();
00794         }
00795     }


Member Function Documentation

void XMLStorage::XMLNode::clear (  )  [inline]

Definition at line 797 of file xmlstorage.h.

Referenced by XMLStorage::XMLNode::Children::clear().

00798     {
00799         _leading.erase();
00800         _content.erase();
00801         _end_leading.erase();
00802         _trailing.erase();
00803 
00804         _attributes.clear();
00805         _children.clear();
00806 
00807         XS_String::erase();
00808     }

Here is the caller graph for this function:

XMLNode& XMLStorage::XMLNode::operator= ( const XMLNode other  )  [inline]

Definition at line 810 of file xmlstorage.h.

References _attributes, _children, _content, _end_leading, _leading, _trailing, and XMLStorage::XS_String::assign().

00811     {
00812         _children.assign(other._children);
00813 
00814         _attributes = other._attributes;
00815 
00816         _leading = other._leading;
00817         _content = other._content;
00818         _end_leading = other._end_leading;
00819         _trailing = other._trailing;
00820 
00821         return *this;
00822     }

Here is the call graph for this function:

void XMLStorage::XMLNode::add_child ( XMLNode child  )  [inline]

add a new child node

Definition at line 825 of file xmlstorage.h.

00826     {
00827         _children.push_back(child);
00828     }

void XMLStorage::XMLNode::put ( const XS_String attr_name,
const XS_String value 
) [inline]

write access to an attribute

Definition at line 831 of file xmlstorage.h.

00832     {
00833         _attributes[attr_name] = value;
00834     }

XS_String& XMLStorage::XMLNode::operator[] ( const XS_String attr_name  )  [inline]

C++ write access to an attribute.

Definition at line 837 of file xmlstorage.h.

00838     {
00839         return _attributes[attr_name];
00840     }

template<typename T>
XS_String XMLStorage::XMLNode::get ( const T &  attr_name,
LPCXSSTR  def = XS_EMPTY_STR 
) const [inline]

read only access to an attribute

Definition at line 843 of file xmlstorage.h.

Referenced by find(), subvalue(), XMLStorage::XMLBool::XMLBool(), XMLStorage::XMLDouble::XMLDouble(), XMLStorage::XMLInt::XMLInt(), and XMLStorage::XMLString::XMLString().

00844     {
00845         AttributeMap::const_iterator found = _attributes.find(attr_name);
00846 
00847         if (found != _attributes.end())
00848             return found->second;
00849         else
00850             return def;
00851     }

Here is the caller graph for this function:

XS_String XMLStorage::XMLNode::subvalue ( const XS_String name,
const XS_String attr_name,
int  n = 0 
) const [inline]

convenient value access in children node

Definition at line 854 of file xmlstorage.h.

References get(), and XMLStorage::XS_String::XS_String().

00855     {
00856         const XMLNode* node = find(name, n);
00857 
00858         if (node)
00859             return node->get(attr_name);
00860         else
00861             return XS_String();
00862     }

Here is the call graph for this function:

XS_String& XMLStorage::XMLNode::subvalue ( const XS_String name,
const XS_String attr_name,
int  n = 0 
) [inline]

convenient storage of distinct values in children node

Definition at line 865 of file xmlstorage.h.

00866     {
00867         XMLNode* node = find(name, n);
00868 
00869         if (!node) {
00870             node = new XMLNode(name);
00871             add_child(node);
00872         }
00873 
00874         return (*node)[attr_name];
00875     }

const Children& XMLStorage::XMLNode::get_children (  )  const [inline]

Definition at line 903 of file xmlstorage.h.

00904     {
00905         return _children;
00906     }

Children& XMLStorage::XMLNode::get_children (  )  [inline]

Definition at line 908 of file xmlstorage.h.

00909     {
00910         return _children;
00911     }

const AttributeMap& XMLStorage::XMLNode::get_attributes (  )  const [inline]

Definition at line 913 of file xmlstorage.h.

00914     {
00915         return _attributes;
00916     }

AttributeMap& XMLStorage::XMLNode::get_attributes (  )  [inline]

Definition at line 918 of file xmlstorage.h.

00919     {
00920         return _attributes;
00921     }

XS_String XMLStorage::XMLNode::get_content (  )  const [inline]

Definition at line 923 of file xmlstorage.h.

References XMLStorage::assign_utf8(), and XMLStorage::DecodeXMLString().

00924     {
00925 #ifdef XS_STRING_UTF8
00926         const XS_String& ret = _content;
00927 #else
00928         XS_String ret;
00929         assign_utf8(ret, _content.c_str(), _content.length());
00930 #endif
00931 
00932         return DecodeXMLString(ret.c_str());
00933     }

Here is the call graph for this function:

void XMLStorage::XMLNode::set_content ( const XS_String s  )  [inline]

Definition at line 935 of file xmlstorage.h.

References XMLStorage::XS_String::assign(), and XMLStorage::EncodeXMLString().

00936     {
00937         _content.assign(EncodeXMLString(s.c_str()));
00938     }

Here is the call graph for this function:

std::ostream& XMLStorage::XMLNode::write ( std::ostream &  out,
const XMLFormat format,
WRITE_MODE  mode = FORMAT_SMART,
int  indent = 0 
) const [inline]

write node with children tree to output stream

Definition at line 945 of file xmlstorage.h.

References XMLStorage::FORMAT_ORIGINAL, XMLStorage::FORMAT_PLAIN, and XMLStorage::FORMAT_PRETTY.

00946     {
00947         switch(mode) {
00948           case FORMAT_PLAIN:
00949             plain_write_worker(out);
00950             break;
00951 
00952           case FORMAT_PRETTY:
00953             pretty_write_worker(out, format, indent);
00954             break;
00955 
00956           case FORMAT_ORIGINAL:
00957             write_worker(out, indent);
00958             break;
00959 
00960         default:     // FORMAT_SMART
00961             smart_write_worker(out, format, indent);
00962         }
00963 
00964         return out;
00965     }

XMLNode* XMLStorage::XMLNode::get_first_child (  )  const [inline, protected]

Definition at line 980 of file xmlstorage.h.

00981     {
00982         if (!_children.empty())
00983             return _children.front();
00984         else
00985             return NULL;
00986     }

XMLNode* XMLStorage::XMLNode::find ( const XS_String name,
int  n = 0 
) const [inline, protected]

Definition at line 988 of file xmlstorage.h.

00989     {
00990         for(Children::const_iterator it=_children.begin(); it!=_children.end(); ++it)
00991             if (**it == name)
00992                 if (!n--)
00993                     return *it;
00994 
00995         return NULL;
00996     }

XMLNode* XMLStorage::XMLNode::find ( const XS_String name,
const XS_String attr_name,
const XS_String attr_value,
int  n = 0 
) const [inline, protected]

Definition at line 998 of file xmlstorage.h.

References get().

00999     {
01000         for(Children::const_iterator it=_children.begin(); it!=_children.end(); ++it) {
01001             const XMLNode& node = **it;
01002 
01003             if (node==name && node.get(attr_name)==attr_value)
01004                 if (!n--)
01005                     return *it;
01006         }
01007 
01008         return NULL;
01009     }

Here is the call graph for this function:

const XMLNode* XMLStorage::XMLNode::find_relative ( const char *  path  )  const [protected]

XPath find function (const).

XMLNode* XMLStorage::XMLNode::find_relative ( const char *  path  )  [inline, protected]

XPath find function.

Definition at line 1041 of file xmlstorage.h.

01042         {return const_cast<XMLNode*>(const_cast<const XMLNode*>(this)->find_relative(path));}

XMLNode* XMLStorage::XMLNode::create_relative ( const char *  path  )  [protected]

relative XPath create function

void XMLStorage::XMLNode::write_worker ( std::ostream &  out,
int  indent 
) const [protected]

void XMLStorage::XMLNode::plain_write_worker ( std::ostream &  out  )  const [protected]

void XMLStorage::XMLNode::pretty_write_worker ( std::ostream &  out,
const XMLFormat format,
int  indent 
) const [protected]

void XMLStorage::XMLNode::smart_write_worker ( std::ostream &  out,
const XMLFormat format,
int  indent 
) const [protected]


Friends And Related Function Documentation

friend struct XMLPos [friend]

Definition at line 759 of file xmlstorage.h.

friend struct const_XMLPos [friend]

Definition at line 760 of file xmlstorage.h.

friend struct XMLReaderBase [friend]

Definition at line 761 of file xmlstorage.h.


Field Documentation

Children XMLStorage::XMLNode::_children [protected]

Definition at line 968 of file xmlstorage.h.

Referenced by operator=(), and XMLNode().

AttributeMap XMLStorage::XMLNode::_attributes [protected]

Definition at line 969 of file xmlstorage.h.

Referenced by operator=().

std::string XMLStorage::XMLNode::_leading [protected]

Definition at line 971 of file xmlstorage.h.

Referenced by operator=().

std::string XMLStorage::XMLNode::_content [protected]

Definition at line 972 of file xmlstorage.h.

Referenced by operator=().

std::string XMLStorage::XMLNode::_end_leading [protected]

Definition at line 973 of file xmlstorage.h.

Referenced by operator=().

std::string XMLStorage::XMLNode::_trailing [protected]

Definition at line 974 of file xmlstorage.h.

Referenced by operator=().


The documentation for this struct was generated from the following file:
IBrowser Source Code Documentation
generated on 18.09.2008 by doxygen

Homepage