XMLStorage::XMLWriter Struct Reference

#include <xmlstorage.h>

Collaboration diagram for XMLStorage::XMLWriter:

Collaboration graph
[legend]

Public Types

enum  WRITESTATE { NOTHING, ATTRIBUTES, PRE_CLOSED, POST }

Public Member Functions

 XMLWriter (std::ostream &out, const XMLFormat &format=XMLFormat())
 XMLWriter (LPCTSTR path, const XMLFormat &format=XMLFormat())
 ~XMLWriter ()
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_Stringoperator[] (const XS_String &attr_name)
 C++ write access to an attribute.
void set_content (const XS_String &s)

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
const XMLFormat_format
std::stack< StackEntry_stack

Static Protected Attributes

static XS_String s_empty_attr

Data Structures

struct  StackEntry

Detailed Description

Definition at line 2311 of file xmlstorage.h.


Member Typedef Documentation

typedef XMLNode::AttributeMap XMLStorage::XMLWriter::AttrMap [protected]

Definition at line 2400 of file xmlstorage.h.


Member Enumeration Documentation

enum XMLStorage::XMLWriter::WRITESTATE

Enumerator:
NOTHING 
ATTRIBUTES 
PRE_CLOSED 
POST 

Definition at line 2391 of file xmlstorage.h.

02391                     {
02392         NOTHING, /*PRE,*/ ATTRIBUTES, PRE_CLOSED, /*CONTENT,*/ POST
02393     };


Constructor & Destructor Documentation

XMLStorage::XMLWriter::XMLWriter ( std::ostream &  out,
const XMLFormat format = XMLFormat() 
) [inline]

Definition at line 2313 of file xmlstorage.h.

02314      :  _pofstream(NULL),
02315         _out(out),
02316         _format(format)
02317     {
02318         format.print_header(_out, false);   // _format._endl is printed in write_pre()
02319     }

XMLStorage::XMLWriter::XMLWriter ( LPCTSTR  path,
const XMLFormat format = XMLFormat() 
) [inline]

Definition at line 2321 of file xmlstorage.h.

02322      :  _pofstream(new tofstream(path)),
02323         _out(*_pofstream),
02324         _format(format)
02325     {
02326         format.print_header(_out, false);   // _format._endl is printed in write_pre()
02327     }

XMLStorage::XMLWriter::~XMLWriter (  )  [inline]

Definition at line 2329 of file xmlstorage.h.

02330     {
02331         _out << _format._endl;
02332         delete _pofstream;
02333     }


Member Function Documentation

void XMLStorage::XMLWriter::create ( const XS_String name  )  [inline]

create node and move to it

Definition at line 2336 of file xmlstorage.h.

References XMLStorage::XMLWriter::StackEntry::_children, XMLStorage::XMLWriter::StackEntry::_node_name, and XMLStorage::XMLWriter::StackEntry::_state.

02337     {
02338         if (!_stack.empty()) {
02339             StackEntry& last = _stack.top();
02340 
02341             if (last._state < PRE_CLOSED) {
02342                 write_attributes(last);
02343                 close_pre(last);
02344             }
02345 
02346             ++last._children;
02347         }
02348 
02349         StackEntry entry;
02350         entry._node_name = name;
02351         _stack.push(entry);
02352 
02353         write_pre(entry);
02354     }

bool XMLStorage::XMLWriter::back (  )  [inline]

go back to previous position

Definition at line 2357 of file xmlstorage.h.

02358     {
02359         if (!_stack.empty()) {
02360             write_post(_stack.top());
02361 
02362             _stack.pop();
02363             return true;
02364         } else
02365             return false;
02366     }

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

attribute setting

Definition at line 2369 of file xmlstorage.h.

02370     {
02371         if (!_stack.empty())
02372             _stack.top()._attributes[attr_name] = value;
02373     }

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

C++ write access to an attribute.

Definition at line 2376 of file xmlstorage.h.

02377     {
02378         if (_stack.empty())
02379             return s_empty_attr;
02380 
02381         return _stack.top()._attributes[attr_name];
02382     }

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

Definition at line 2384 of file xmlstorage.h.

References XMLStorage::EncodeXMLString().

02385     {
02386         if (!_stack.empty())
02387             _stack.top()._content = EncodeXMLString(s.c_str());
02388     }

Here is the call graph for this function:

void XMLStorage::XMLWriter::close_pre ( StackEntry entry  )  [inline, protected]

Definition at line 2416 of file xmlstorage.h.

References XMLStorage::XMLWriter::StackEntry::_state.

02417     {
02418         _out << '>';
02419 
02420         entry._state = PRE_CLOSED;
02421     }

void XMLStorage::XMLWriter::write_pre ( StackEntry entry  )  [inline, protected]

Definition at line 2423 of file xmlstorage.h.

References XMLStorage::XMLWriter::StackEntry::_node_name, XMLStorage::EncodeXMLString(), XMLStorage::PRETTY_INDENT, XMLStorage::PRETTY_LINEFEED, and XML_INDENT_SPACE.

02424     {
02425         if (_format._pretty >= PRETTY_LINEFEED)
02426             _out << _format._endl;
02427 
02428         if (_format._pretty == PRETTY_INDENT)
02429             for(size_t i=_stack.size(); --i>0; )
02430                 _out << XML_INDENT_SPACE;
02431 
02432         _out << '<' << EncodeXMLString(entry._node_name);
02433         //entry._state = PRE;
02434     }

Here is the call graph for this function:

void XMLStorage::XMLWriter::write_attributes ( StackEntry entry  )  [inline, protected]

Definition at line 2436 of file xmlstorage.h.

References XMLStorage::XMLWriter::StackEntry::_attributes, XMLStorage::XMLWriter::StackEntry::_state, and XMLStorage::EncodeXMLString().

02437     {
02438         for(AttrMap::const_iterator it=entry._attributes.begin(); it!=entry._attributes.end(); ++it)
02439             _out << ' ' << EncodeXMLString(it->first) << "=\"" << EncodeXMLString(it->second) << "\"";
02440 
02441         entry._state = ATTRIBUTES;
02442     }

Here is the call graph for this function:

void XMLStorage::XMLWriter::write_post ( StackEntry entry  )  [inline, protected]

Definition at line 2444 of file xmlstorage.h.

References XMLStorage::XMLWriter::StackEntry::_children, XMLStorage::XMLWriter::StackEntry::_content, XMLStorage::XMLWriter::StackEntry::_node_name, XMLStorage::XMLWriter::StackEntry::_state, XMLStorage::EncodeXMLString(), XMLStorage::PRETTY_INDENT, XMLStorage::PRETTY_LINEFEED, and XML_INDENT_SPACE.

02445     {
02446         if (entry._state < ATTRIBUTES)
02447             write_attributes(entry);
02448 
02449         if (entry._children || !entry._content.empty()) {
02450             if (entry._state < PRE_CLOSED)
02451                 close_pre(entry);
02452 
02453             _out << entry._content;
02454             //entry._state = CONTENT;
02455 
02456             if (_format._pretty>=PRETTY_LINEFEED && entry._content.empty())
02457                 _out << _format._endl;
02458 
02459             if (_format._pretty==PRETTY_INDENT && entry._content.empty())
02460                 for(size_t i=_stack.size(); --i>0; )
02461                     _out << XML_INDENT_SPACE;
02462 
02463             _out << "</" << EncodeXMLString(entry._node_name) << ">";
02464         } else {
02465             _out << "/>";
02466         }
02467 
02468         entry._state = POST;
02469     }

Here is the call graph for this function:


Field Documentation

tofstream* XMLStorage::XMLWriter::_pofstream [protected]

Definition at line 2396 of file xmlstorage.h.

std::ostream& XMLStorage::XMLWriter::_out [protected]

Definition at line 2397 of file xmlstorage.h.

const XMLFormat& XMLStorage::XMLWriter::_format [protected]

Definition at line 2398 of file xmlstorage.h.

std::stack<StackEntry> XMLStorage::XMLWriter::_stack [protected]

Definition at line 2412 of file xmlstorage.h.

XS_String XMLStorage::XMLWriter::s_empty_attr [static, protected]

Definition at line 2414 of file xmlstorage.h.


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

Homepage