in memory representation of an XML node More...
#include <xmlstorage.h>


Classes | |
| struct | AttributeMap |
| map of XML node attributes More... | |
| struct | Children |
| internal children node list More... | |
Public Types | |
| enum | COPY_FLAGS { COPY_NOCHILDREN } |
Public Member Functions | |
| XMLNode (const XS_String &name) | |
| XMLNode (const XS_String &name, const std::string &leading) | |
| XMLNode (const XMLNode &other) | |
| XMLNode (const XMLNode &other, COPY_FLAGS copy_no_children) | |
| virtual | ~XMLNode () |
| void | clear () |
| XMLNode & | operator= (const XMLNode &other) |
| void | add_child (XMLNode *child) |
| add a new child node | |
| void | remove_children (const XS_String &name) |
| remove all children named 'name' | |
| void | put (const XS_String &attr_name, const XS_String &value) |
| write access to an attribute | |
| XS_String & | operator[] (const XS_String &attr_name) |
| index operator write access to an attribute | |
| XS_String | operator[] (const XS_String &attr_name) const |
| index operator read 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 | |
| void | erase (const XS_String &attr_name) |
| remove the attribute 'attr_name' | |
| XS_String | subvalue (const XS_String &child_name, const XS_String &attr_name, int n=0) const |
| convenient value access in children node | |
| XS_String & | subvalue (const XS_String &child_name, const XS_String &attr_name, int n=0) |
| convenient storage of distinct values in children node | |
| const Children & | get_children () const |
| Children & | get_children () |
| const AttributeMap & | get_attributes () const |
| AttributeMap & | get_attributes () |
| XS_String | get_content () const |
| read element node content | |
| std::string | get_encoded_content () const |
| read element node content as encoded string | |
| XS_String | get_sub_content (const XPath &xpath) const |
| read content of a subnode specified by an XPath expression | |
| void | set_content (const XS_String &s, bool cdata=false) |
| set element node content | |
| void | set_encoded_content (const std::string &s) |
| set element node content from encoded string | |
| bool | set_sub_content (const XPath &xpath, const XS_String &s, bool cdata=false) |
| set content of a subnode specified by an XPath expression | |
| bool | write (std::ostream &out, const XMLFormat &format, WRITE_MODE mode=FORMAT_SMART, int indent=0) const |
| write node with children tree to output stream | |
| int | count (const XPath &xpath) const |
| count the nodes matching the given relative XPath expression | |
| int | count (XPath::const_iterator from, const XPath::const_iterator &to) const |
| count the nodes matching the given relative XPath expression | |
| bool | filter (const XPath &xpath, XMLNode &target) const |
| copy matching tree nodes using the given XPath filter expression | |
| const XMLNode * | find_relative (const XPath &xpath) const |
| XPath find function (const) | |
| XMLNode * | find_relative (const XPath &xpath) |
| XPath find function. | |
| XMLNode * | get_first_child () const |
Protected Member Functions | |
| XMLNode * | create_relative (const XPath &xpath) |
| relative XPath create function | |
| XMLNode * | filter (XPath::const_iterator from, const XPath::const_iterator &to) const |
| create a new node tree using the given XPath filter expression | |
| void | original_write_worker (std::ostream &out) const |
| write node with children tree to output stream using original white space | |
| void | plain_write_worker (std::ostream &out) const |
| print node without any white space | |
| void | pretty_write_worker (std::ostream &out, const XMLFormat &format, int indent) const |
| pretty print node with children tree to output stream | |
| void | smart_write_worker (std::ostream &out, const XMLFormat &format, int indent) const |
| write node with children tree to output stream using smart formating | |
Protected Attributes | |
| Children | _children |
| AttributeMap | _attributes |
| std::string | _leading |
| std::string | _content |
| std::string | _end_leading |
| std::string | _trailing |
| bool | _cdata_content |
Friends | |
| struct | XMLPos |
| struct | const_XMLPos |
| struct | XMLReaderBase |
| struct | XPathElement |
in memory representation of an XML node
Definition at line 1378 of file xmlstorage.h.
| XMLStorage::XMLNode::XMLNode | ( | const XS_String & | name ) | [inline] |
Definition at line 1508 of file xmlstorage.h.
Referenced by XMLStorage::XMLNode::Children::copy(), create_relative(), filter(), XMLStorage::XMLReaderBase::StartElementHandler(), and subvalue().
: XS_String(name), _cdata_content(false) { }

| XMLStorage::XMLNode::XMLNode | ( | const XS_String & | name, |
| const std::string & | leading | ||
| ) | [inline] |
Definition at line 1514 of file xmlstorage.h.
: XS_String(name), _leading(leading), _cdata_content(false) { }
| XMLStorage::XMLNode::XMLNode | ( | const XMLNode & | other ) | [inline] |
Definition at line 1521 of file xmlstorage.h.
References _children.
: XS_String(other), _attributes(other._attributes), _leading(other._leading), _content(other._content), _end_leading(other._end_leading), _trailing(other._trailing), #ifdef XMLNODE_LOCATION _location(other._location), #endif _cdata_content(false) { for(Children::const_iterator it=other._children.begin(); it!=other._children.end(); ++it) _children.push_back(new XMLNode(**it)); }
| XMLStorage::XMLNode::XMLNode | ( | const XMLNode & | other, |
| COPY_FLAGS | copy_no_children | ||
| ) | [inline] |
Definition at line 1542 of file xmlstorage.h.
References COPY_NOCHILDREN.
: XS_String(other), _attributes(other._attributes), _leading(other._leading), _content(other._content), _end_leading(other._end_leading), _trailing(other._trailing), #ifdef XMLNODE_LOCATION _location(other._location), #endif _cdata_content(false) { assert(copy_no_children==COPY_NOCHILDREN); }
| virtual XMLStorage::XMLNode::~XMLNode | ( | ) | [inline, virtual] |
| void XMLStorage::XMLNode::add_child | ( | XMLNode * | child ) | [inline] |
add a new child node
Definition at line 1594 of file xmlstorage.h.
References _children.
Referenced by XMLStorage::XMLPos::add_down(), XMLStorage::XMLPos::create_node_content(), create_relative(), filter(), and subvalue().
{
_children.push_back(child);
}

| void XMLStorage::XMLNode::clear | ( | ) | [inline] |
Definition at line 1565 of file xmlstorage.h.
References _attributes, _children, _content, _end_leading, _leading, _trailing, XMLStorage::XMLNode::Children::clear(), XMLStorage::XS_StringMap::clear(), and erase().
Referenced by XMLStorage::XMLNode::Children::clear().
{
_leading.erase();
_content.erase();
_end_leading.erase();
_trailing.erase();
_attributes.clear();
_children.clear();
XS_String::erase();
}


| int XMLStorage::XMLNode::count | ( | const XPath & | xpath ) | const [inline] |
count the nodes matching the given relative XPath expression
Definition at line 1796 of file xmlstorage.h.
Referenced by XMLStorage::XMLPos::count().
{
return count(xpath.begin(), xpath.end());
}

| int XMLStorage::XMLNode::count | ( | XPath::const_iterator | from, |
| const XPath::const_iterator & | to | ||
| ) | const |
count the nodes matching the given relative XPath expression
Definition at line 320 of file xmlstorage.cpp.
References _children, and XMLStorage::XPathElement::matches().
{
const XPathElement& elem = *from++;
int cnt = 0;
int n = 0;
for(XMLNode::Children::const_iterator it=_children.begin(); it!=_children.end(); ++it)
if (elem.matches(**it, n)) {
if (from != to)
// iterate deeper
cnt += (*it)->count(from, to);
else
// increment match counter
++cnt;
}
return cnt;
}

relative XPath create function
Definition at line 298 of file xmlstorage.cpp.
References add_child(), and XMLNode().
Referenced by XMLStorage::XMLPos::create_relative(), and set_sub_content().
{
XMLNode* node = this;
for(XPath::const_iterator it=xpath.begin(); it!=xpath.end(); ++it) {
XMLNode* child = it->find(node);
if (!child) {
child = new XMLNode(it->_child_name);
node->add_child(child);
for(XPathElement::MAPATTR::const_iterator b=it->_mAttrAndAttr.begin(), e=it->_mAttrAndAttr.end(); b!=e; ++b)
(*this)[b->first] = b->second;
}
node = child;
}
return node;
}


| void XMLStorage::XMLNode::erase | ( | const XS_String & | attr_name ) | [inline] |
remove the attribute 'attr_name'
Definition at line 1646 of file xmlstorage.h.
References _attributes, and XMLStorage::XS_StringMap::erase().
Referenced by clear(), XMLStorage::XMLPos::erase(), and XMLStorage::XMLNode::Children::remove().
{
_attributes.erase(attr_name);
}


copy matching tree nodes using the given XPath filter expression
Definition at line 340 of file xmlstorage.cpp.
References _attributes, _children, and XMLStorage::XMLNode::Children::move().
Referenced by XMLStorage::XMLPos::filter(), and filter().
{
XMLNode* ret = filter(xpath.begin(), xpath.end());
if (!ret)
return false;
// move returned nodes to target node
target._children.move(ret->_children);
target._attributes = ret->_attributes;
delete ret;
return true;
}


| XMLNode * XMLStorage::XMLNode::filter | ( | XPath::const_iterator | from, |
| const XPath::const_iterator & | to | ||
| ) | const [protected] |
create a new node tree using the given XPath filter expression
Definition at line 356 of file xmlstorage.cpp.
References _children, add_child(), COPY_NOCHILDREN, filter(), XMLStorage::XPathElement::matches(), and XMLNode().
{
XMLNode* copy = NULL;
const XPathElement& elem = *from++;
int cnt = 0;
int n = 0;
for(XMLNode::Children::const_iterator it=_children.begin(); it!=_children.end(); ++it)
if (elem.matches(**it, n)) {
if (!copy)
copy = new XMLNode(*this, XMLNode::COPY_NOCHILDREN);
if (from != to) {
XMLNode* ret = (*it)->filter(from, to);
if (ret) {
copy->add_child(ret);
++cnt;
}
} else {
copy->add_child(new XMLNode(**it, XMLNode::COPY_NOCHILDREN));
++cnt;
}
}
if (!cnt) {
delete copy;
copy = NULL;
}
return copy;
}

XPath find function (const)
Definition at line 270 of file xmlstorage.cpp.
Referenced by get_sub_content(), XMLStorage::const_XMLPos::go(), and XMLStorage::XMLPos::go().
{
const XMLNode* node = this;
for(XPath::const_iterator it=xpath.begin(); it!=xpath.end(); ++it) {
node = it->const_find(node);
if (!node)
break;
}
return node;
}

XPath find function.
Definition at line 284 of file xmlstorage.cpp.
{
XMLNode* node = this;
for(XPath::const_iterator it=xpath.begin(); it!=xpath.end(); ++it) {
node = it->find(node);
if (!node)
break;
}
return node;
}
| 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 1635 of file xmlstorage.h.
References _attributes, XMLStorage::XS_StringMap::end(), and XMLStorage::XS_StringMap::find().
Referenced by XMLStorage::const_XMLPos::get(), XMLStorage::XMLPos::get(), XMLStorage::XPathElement::matches(), XMLStorage::const_XMLPos::operator[](), NotifyArea::read_config(), subvalue(), XMLStorage::XMLBool::XMLBool(), XMLStorage::XMLDouble::XMLDouble(), XMLStorage::XMLInt::XMLInt(), XMLStorage::XMLInt64::XMLInt64(), and XMLStorage::XMLString::XMLString().
{
AttributeMap::const_iterator found = _attributes.find(attr_name);
if (found != _attributes.end())
return found->second;
else
return def;
}


| const AttributeMap& XMLStorage::XMLNode::get_attributes | ( | ) | const [inline] |
| AttributeMap& XMLStorage::XMLNode::get_attributes | ( | ) | [inline] |
| const Children& XMLStorage::XMLNode::get_children | ( | ) | const [inline] |
| Children& XMLStorage::XMLNode::get_children | ( | ) | [inline] |
| XS_String XMLStorage::XMLNode::get_content | ( | ) | const [inline] |
read element node content
Definition at line 1722 of file xmlstorage.h.
References _content, and XMLStorage::DecodeXMLString().
Referenced by get_sub_content().
{
return DecodeXMLString(_content);
}


| std::string XMLStorage::XMLNode::get_encoded_content | ( | ) | const [inline] |
read element node content as encoded string
Definition at line 1728 of file xmlstorage.h.
References _content.
{
return _content;
}
| XMLNode* XMLStorage::XMLNode::get_first_child | ( | ) | const [inline] |
Definition at line 1813 of file xmlstorage.h.
References _children.
Referenced by XMLStorage::const_XMLPos::go_down(), and XMLStorage::XMLPos::go_down().

read content of a subnode specified by an XPath expression
Definition at line 1734 of file xmlstorage.h.
References find_relative(), get_content(), and XS_EMPTY_STR.
{
const XMLNode* node = find_relative(xpath);
if (node)
return node->get_content();
else
return XS_EMPTY_STR;
}

Definition at line 1578 of file xmlstorage.h.
References _attributes, _children, _content, _end_leading, _leading, _trailing, XMLStorage::XMLNode::Children::clear(), and XMLStorage::XMLNode::Children::copy().
{
_children.clear();
_children.copy(other._children);
_attributes = other._attributes;
_leading = other._leading;
_content = other._content;
_end_leading = other._end_leading;
_trailing = other._trailing;
return *this;
}

index operator write access to an attribute
Definition at line 1619 of file xmlstorage.h.
References _attributes.
{
return _attributes[attr_name];
}
index operator read access to an attribute
Definition at line 1625 of file xmlstorage.h.
References _attributes, and XMLStorage::XMLNode::AttributeMap::get().
{
#if defined(UNICODE) && !defined(XS_STRING_UTF8)
return _attributes.get(((std::string)attr_name).c_str());
#else
return _attributes.get(attr_name.c_str());
#endif
}

| void XMLStorage::XMLNode::original_write_worker | ( | std::ostream & | out ) | const [protected] |
write node with children tree to output stream using original white space
Definition at line 569 of file xmlstorage.cpp.
References _attributes, _children, _content, _leading, XMLStorage::XS_StringMap::begin(), XMLStorage::EncodeXMLString(), and XMLStorage::XS_StringMap::end().
Referenced by write().
{
out << _leading << '<' << EncodeXMLString(*this);
for(AttributeMap::const_iterator it=_attributes.begin(); it!=_attributes.end(); ++it)
out << ' ' << EncodeXMLString(it->first) << "=\"" << EncodeXMLString(it->second) << "\"";
if (!_children.empty() || !_content.empty()) {
out << '>';
if (_cdata_content)
out << CDATA_START << _content << CDATA_END;
else
out << _content;
for(Children::const_iterator it=_children.begin(); it!=_children.end(); ++it)
(*it)->original_write_worker(out);
out << _end_leading << "</" << EncodeXMLString(*this) << '>';
} else
out << "/>";
out << _trailing;
}


| void XMLStorage::XMLNode::plain_write_worker | ( | std::ostream & | out ) | const [protected] |
print node without any white space
Definition at line 596 of file xmlstorage.cpp.
Referenced by write().
{
out << '<' << EncodeXMLString(*this);
for(AttributeMap::const_iterator it=_attributes.begin(); it!=_attributes.end(); ++it)
out << ' ' << EncodeXMLString(it->first) << "=\"" << EncodeXMLString(it->second) << "\"";
// strip leading white space from content
const char* content = _content.c_str();
while(isspace((unsigned char)*content)) ++content;
if (!_children.empty() || *content) {
out << ">" << content;
for(Children::const_iterator it=_children.begin(); it!=_children.end(); ++it)
(*it)->plain_write_worker(out);
out << "</" << EncodeXMLString(*this) << ">";
} else
out << "/>";
}

| void XMLStorage::XMLNode::pretty_write_worker | ( | std::ostream & | out, |
| const XMLFormat & | format, | ||
| int | indent | ||
| ) | const [protected] |
pretty print node with children tree to output stream
Definition at line 620 of file xmlstorage.cpp.
Referenced by write().
{
for(int i=indent; i--; )
out << XML_INDENT_SPACE;
out << '<' << EncodeXMLString(*this);
for(AttributeMap::const_iterator it=_attributes.begin(); it!=_attributes.end(); ++it)
out << ' ' << EncodeXMLString(it->first) << "=\"" << EncodeXMLString(it->second) << "\"";
// strip leading white space from content
const char* content = _content.c_str();
while(isspace((unsigned char)*content)) ++content;
if (!_children.empty() || *content) {
out << '>' << content;
if (!_children.empty())
out << format._endl;
for(Children::const_iterator it=_children.begin(); it!=_children.end(); ++it)
(*it)->pretty_write_worker(out, format, indent+1);
for(int i=indent; i--; )
out << XML_INDENT_SPACE;
out << "</" << EncodeXMLString(*this) << '>' << format._endl;
} else
out << "/>" << format._endl;
}

write access to an attribute
Definition at line 1613 of file xmlstorage.h.
References _attributes.
Referenced by XMLStorage::XMLPos::put().
{
_attributes[attr_name] = value;
}

| void XMLStorage::XMLNode::remove_children | ( | const XS_String & | name ) | [inline] |
remove all children named 'name'
Definition at line 1600 of file xmlstorage.h.
References _children.
Referenced by XMLStorage::XMLPos::remove_children().
{
Children::iterator it, next=_children.begin();
while((it=next) != _children.end()) {
++next;
if (**it == name)
_children.erase(it);
}
}

| void XMLStorage::XMLNode::set_content | ( | const XS_String & | s, |
| bool | cdata = false |
||
| ) | [inline] |
set element node content
Definition at line 1745 of file xmlstorage.h.
References _content, and XMLStorage::EncodeXMLString().
Referenced by XMLStorage::XMLPos::create_node_content(), and set_sub_content().
{
_content.assign(EncodeXMLString(s.c_str(), cdata));
}


| void XMLStorage::XMLNode::set_encoded_content | ( | const std::string & | s ) | [inline] |
set element node content from encoded string
Definition at line 1751 of file xmlstorage.h.
References _content.
{
_content.assign(s);
}
| bool XMLStorage::XMLNode::set_sub_content | ( | const XPath & | xpath, |
| const XS_String & | s, | ||
| bool | cdata = false |
||
| ) | [inline] |
set content of a subnode specified by an XPath expression
Definition at line 1757 of file xmlstorage.h.
References create_relative(), and set_content().
{
XMLNode* node = create_relative(xpath);
if (node) {
node->set_content(s, cdata);
return true;
} else
return false;
}

| void XMLStorage::XMLNode::smart_write_worker | ( | std::ostream & | out, |
| const XMLFormat & | format, | ||
| int | indent | ||
| ) | const [protected] |
write node with children tree to output stream using smart formating
Definition at line 653 of file xmlstorage.cpp.
Referenced by write().
{
// strip the first line feed from _leading
const char* leading = _leading.c_str();
if (*leading == '\n') ++leading;
if (!*leading)
for(int i=indent; i--; )
out << XML_INDENT_SPACE;
else
out << leading;
out << '<' << EncodeXMLString(*this);
for(AttributeMap::const_iterator it=_attributes.begin(); it!=_attributes.end(); ++it)
out << ' ' << EncodeXMLString(it->first) << "=\"" << EncodeXMLString(it->second) << "\"";
// strip leading white space from content
const char* content = _content.c_str();
while(isspace((unsigned char)*content)) ++content;
if (_children.empty() && !*content)
out << "/>";
else {
out << '>';
if (_cdata_content)
out << CDATA_START << _content << CDATA_END;
else if (!*content)
out << format._endl;
else
out << content;
Children::const_iterator it = _children.begin();
if (it != _children.end()) {
for(; it!=_children.end(); ++it)
(*it)->smart_write_worker(out, format, indent+1);
// strip the first line feed from _end_leading
const char* end_leading = _end_leading.c_str();
if (*end_leading == '\n') ++end_leading;
if (!*end_leading)
for(int i=indent; i--; )
out << XML_INDENT_SPACE;
else
out << end_leading;
} else
out << _end_leading;
out << "</" << EncodeXMLString(*this) << '>';
}
if (_trailing.empty())
out << format._endl;
else
out << _trailing;
}

| XS_String& XMLStorage::XMLNode::subvalue | ( | const XS_String & | child_name, |
| const XS_String & | attr_name, | ||
| int | n = 0 |
||
| ) | [inline] |
convenient storage of distinct values in children node
Definition at line 1663 of file xmlstorage.h.
References add_child(), XMLNode(), and XPathElement.
{
XMLNode* node = XPathElement(child_name, n).find(this);
if (!node) {
node = new XMLNode(child_name);
add_child(node);
}
return (*node)[attr_name];
}

| XS_String XMLStorage::XMLNode::subvalue | ( | const XS_String & | child_name, |
| const XS_String & | attr_name, | ||
| int | n = 0 |
||
| ) | const [inline] |
convenient value access in children node
Definition at line 1652 of file xmlstorage.h.
References get(), XPathElement, and XMLStorage::XS_String::XS_String().
{
const XMLNode* node = XPathElement(child_name, n).const_find(this);
if (node)
return node->get(attr_name);
else
return XS_String();
}

| bool 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 1773 of file xmlstorage.h.
References XMLStorage::FORMAT_ORIGINAL, XMLStorage::FORMAT_PLAIN, XMLStorage::FORMAT_PRETTY, original_write_worker(), plain_write_worker(), pretty_write_worker(), and smart_write_worker().
{
switch(mode) {
case FORMAT_PLAIN:
plain_write_worker(out);
break;
case FORMAT_PRETTY:
pretty_write_worker(out, format, indent);
break;
case FORMAT_ORIGINAL:
original_write_worker(out);
break;
default: // FORMAT_SMART
smart_write_worker(out, format, indent);
}
return out.good();
}

friend struct const_XMLPos [friend] |
Definition at line 1504 of file xmlstorage.h.
friend struct XMLPos [friend] |
Definition at line 1503 of file xmlstorage.h.
friend struct XMLReaderBase [friend] |
Definition at line 1505 of file xmlstorage.h.
friend struct XPathElement [friend] |
Definition at line 1506 of file xmlstorage.h.
Referenced by subvalue().
AttributeMap XMLStorage::XMLNode::_attributes [protected] |
Definition at line 1823 of file xmlstorage.h.
Referenced by clear(), erase(), filter(), get(), get_attributes(), operator=(), operator[](), original_write_worker(), put(), and XMLStorage::XMLReaderBase::StartElementHandler().
bool XMLStorage::XMLNode::_cdata_content [protected] |
Definition at line 1834 of file xmlstorage.h.
Children XMLStorage::XMLNode::_children [protected] |
Definition at line 1822 of file xmlstorage.h.
Referenced by add_child(), clear(), XMLStorage::XPathElement::const_find(), count(), XMLStorage::XMLPos::delete_this(), filter(), XMLStorage::XPathElement::find(), get_children(), get_first_child(), operator=(), original_write_worker(), remove_children(), XMLStorage::XMLDoc::write(), XMLNode(), and ~XMLNode().
std::string XMLStorage::XMLNode::_content [protected] |
Definition at line 1826 of file xmlstorage.h.
Referenced by clear(), XMLStorage::XMLReaderBase::EndElementHandler(), XMLStorage::XMLReaderBase::finish_read(), get_content(), get_encoded_content(), operator=(), original_write_worker(), set_content(), set_encoded_content(), and XMLStorage::XMLReaderBase::StartElementHandler().
std::string XMLStorage::XMLNode::_end_leading [protected] |
Definition at line 1827 of file xmlstorage.h.
Referenced by clear(), and operator=().
std::string XMLStorage::XMLNode::_leading [protected] |
Definition at line 1825 of file xmlstorage.h.
Referenced by clear(), operator=(), and original_write_worker().
std::string XMLStorage::XMLNode::_trailing [protected] |
Definition at line 1828 of file xmlstorage.h.
Referenced by clear(), and operator=().
|
ROS Explorer Source Code Documentation
generated on 02.01.2013 by
|