on the fly XML writer More...
#include <xmlstorage.h>
Classes | |
struct | StackEntry |
container for XMLWriter state information More... | |
Public Types | |
enum | WRITESTATE { NOTHING, ATTRIBUTES, PRE_CLOSED, POST } |
Public Member Functions | |
XMLWriter (std::ostream &out, const XMLFormat &format=XMLFormat()) | |
XMLWriter (FILE *pFile, const XMLFormat &format=XMLFormat()) | |
XMLWriter (LPCTSTR path, const XMLFormat &format=XMLFormat()) | |
~XMLWriter () | |
bool | good () const |
void | create (const XS_String &name) |
create node and move to it | |
bool | back () |
go back to previous position | |
void | put (const XS_String &attr_name, const XS_String &value) |
attribute setting | |
XS_String & | operator[] (const XS_String &attr_name) |
index operator write access to an attribute | |
void | set_attributes (const XMLNode::AttributeMap &attrs) |
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 | |
void | create_node_content (const XS_String &node_name, const XS_String &content) |
create node with string content | |
void | write (const std::string &s) |
direct string output | |
Protected Types | |
typedef XMLNode::AttributeMap | AttrMap |
Protected Member Functions | |
void | close_pre (StackEntry &entry) |
void | write_pre (StackEntry &entry) |
void | write_attributes (StackEntry &entry) |
void | write_post (StackEntry &entry) |
Protected Attributes | |
tofstream * | _pofstream |
std::ostream & | _out |
XMLFormat | _format |
std::stack< StackEntry > | _stack |
Static Protected Attributes | |
static XS_String | s_empty_attr |
on the fly XML writer
Definition at line 4058 of file xmlstorage.h.
typedef XMLNode::AttributeMap XMLStorage::XMLWriter::AttrMap [protected] |
Definition at line 4158 of file xmlstorage.h.
Definition at line 4149 of file xmlstorage.h.
{ NOTHING, /*PRE,*/ ATTRIBUTES, PRE_CLOSED, /*CONTENT,*/ POST };
XMLStorage::XMLWriter::XMLWriter | ( | std::ostream & | out, |
const XMLFormat & | format = XMLFormat() |
||
) | [inline] |
Definition at line 4060 of file xmlstorage.h.
References _out, and XMLStorage::XMLFormat::print_header().
: _pofstream(NULL), _out(out), _format(format) { format.print_header(_out, false); // _format._endl is printed in write_pre() }
Definition at line 4068 of file xmlstorage.h.
References _out, and XMLStorage::XMLFormat::print_header().
: _pofstream(new tofstream(pFile)), _out(*_pofstream), _format(format) { format.print_header(_out, false); // _format._endl is printed in write_pre() }
Definition at line 4076 of file xmlstorage.h.
References _out, and XMLStorage::XMLFormat::print_header().
: _pofstream(new tofstream(path)), _out(*_pofstream), _format(format) { format.print_header(_out, false); // _format._endl is printed in write_pre() }
XMLStorage::XMLWriter::~XMLWriter | ( | ) | [inline] |
Definition at line 4084 of file xmlstorage.h.
References XMLStorage::XMLFormat::_endl, _format, _out, and _pofstream.
{ _out << _format._endl; delete _pofstream; }
bool XMLStorage::XMLWriter::back | ( | ) |
go back to previous position
Definition at line 1052 of file xmlstorage.cpp.
Referenced by create_node_content().
{ if (!_stack.empty()) { write_post(_stack.top()); _stack.pop(); return true; } else { assert(!_stack.empty()); return false; } }
void XMLStorage::XMLWriter::close_pre | ( | StackEntry & | entry ) | [protected] |
Definition at line 1065 of file xmlstorage.cpp.
{ _out << '>'; entry._state = PRE_CLOSED; }
void XMLStorage::XMLWriter::create | ( | const XS_String & | name ) |
create node and move to it
Definition at line 1032 of file xmlstorage.cpp.
References XMLStorage::XMLWriter::StackEntry::_children, XMLStorage::XMLWriter::StackEntry::_node_name, and XMLStorage::XMLWriter::StackEntry::_state.
Referenced by create_node_content().
{ if (!_stack.empty()) { StackEntry& last = _stack.top(); if (last._state < PRE_CLOSED) { write_attributes(last); close_pre(last); } ++last._children; } StackEntry entry; entry._node_name = name; _stack.push(entry); write_pre(entry); }
void XMLStorage::XMLWriter::create_node_content | ( | const XS_String & | node_name, |
const XS_String & | content | ||
) | [inline] |
create node with string content
Definition at line 4138 of file xmlstorage.h.
References back(), create(), and set_content().
{ create(node_name); set_content(content); back(); }
bool XMLStorage::XMLWriter::good | ( | ) | const [inline] |
index operator write access to an attribute
Definition at line 4109 of file xmlstorage.h.
References _stack, and s_empty_attr.
{ if (_stack.empty()) return s_empty_attr; return _stack.top()._attributes[attr_name]; }
void XMLStorage::XMLWriter::set_attributes | ( | const XMLNode::AttributeMap & | attrs ) | [inline] |
Definition at line 4117 of file xmlstorage.h.
References _stack.
void XMLStorage::XMLWriter::set_content | ( | const XS_String & | s, |
bool | cdata = false |
||
) | [inline] |
set element node content
Definition at line 4124 of file xmlstorage.h.
References _stack, and XMLStorage::EncodeXMLString().
Referenced by create_node_content().
{ if (!_stack.empty()) _stack.top()._content = EncodeXMLString(s.c_str(), cdata); }
void XMLStorage::XMLWriter::set_encoded_content | ( | const std::string & | s ) | [inline] |
set element node content from encoded string
Definition at line 4131 of file xmlstorage.h.
References _stack.
void XMLStorage::XMLWriter::write | ( | const std::string & | s ) |
direct string output
Definition at line 1122 of file xmlstorage.cpp.
{ if (!_stack.empty()) { StackEntry& last = _stack.top(); if (last._state < PRE_CLOSED) { write_attributes(last); close_pre(last); } } _out.write(s.c_str(), s.length()); }
void XMLStorage::XMLWriter::write_attributes | ( | StackEntry & | entry ) | [protected] |
Definition at line 1086 of file xmlstorage.cpp.
{ for(AttrMap::const_iterator it=entry._attributes.begin(); it!=entry._attributes.end(); ++it) _out << ' ' << EncodeXMLString(it->first) << "=\"" << EncodeXMLString(it->second) << "\""; entry._state = ATTRIBUTES; }
void XMLStorage::XMLWriter::write_post | ( | StackEntry & | entry ) | [protected] |
Definition at line 1094 of file xmlstorage.cpp.
{ if (entry._state < ATTRIBUTES) write_attributes(entry); if (entry._children || !entry._content.empty()) { if (entry._state < PRE_CLOSED) close_pre(entry); _out << entry._content; //entry._state = CONTENT; if (_format._pretty>=PRETTY_LINEFEED && entry._content.empty()) _out << _format._endl; if (_format._pretty==PRETTY_INDENT && entry._content.empty()) { for(size_t i=_stack.size(); --i>0; ) _out << XML_INDENT_SPACE; } _out << "</" << EncodeXMLString(entry._node_name) << ">"; } else { _out << "/>"; } entry._state = POST; }
void XMLStorage::XMLWriter::write_pre | ( | StackEntry & | entry ) | [protected] |
Definition at line 1072 of file xmlstorage.cpp.
{ if (_format._pretty >= PRETTY_LINEFEED) _out << _format._endl; if (_format._pretty == PRETTY_INDENT) { for(size_t i=_stack.size(); --i>0; ) _out << XML_INDENT_SPACE; } _out << '<' << EncodeXMLString(entry._node_name); //entry._state = PRE; }
XMLFormat XMLStorage::XMLWriter::_format [protected] |
Definition at line 4156 of file xmlstorage.h.
Referenced by ~XMLWriter().
std::ostream& XMLStorage::XMLWriter::_out [protected] |
Definition at line 4155 of file xmlstorage.h.
Referenced by good(), XMLWriter(), and ~XMLWriter().
tofstream* XMLStorage::XMLWriter::_pofstream [protected] |
Definition at line 4154 of file xmlstorage.h.
Referenced by ~XMLWriter().
std::stack<StackEntry> XMLStorage::XMLWriter::_stack [protected] |
Definition at line 4171 of file xmlstorage.h.
Referenced by operator[](), put(), set_attributes(), set_content(), and set_encoded_content().
XS_String XMLStorage::XMLWriter::s_empty_attr [static, protected] |
Definition at line 4173 of file xmlstorage.h.
Referenced by operator[]().
ROS Explorer Source Code Documentation
generated on 02.01.2013 by ![]() |