Classes | Public Types | Public Member Functions | Protected Types | Protected Member Functions | Protected Attributes | Static Protected Attributes | Private Member Functions

XMLStorage::XMLWriter Struct Reference

on the fly XML writer More...

#include <xmlstorage.h>

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

List of all members.

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_Stringoperator[] (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

Private Member Functions

 XMLWriter (const XMLWriter &)

Detailed Description

on the fly XML writer

Definition at line 4158 of file xmlstorage.h.


Member Typedef Documentation

Definition at line 4259 of file xmlstorage.h.


Member Enumeration Documentation

Enumerator:
NOTHING 
ATTRIBUTES 
PRE_CLOSED 
POST 

Definition at line 4250 of file xmlstorage.h.

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

Constructor & Destructor Documentation

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

Definition at line 4160 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()
    }

Here is the call graph for this function:

XMLStorage::XMLWriter::XMLWriter ( FILE *  pFile,
const XMLFormat format = XMLFormat() 
) [inline]

Definition at line 4168 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()
    }

Here is the call graph for this function:

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

Definition at line 4176 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()
    }

Here is the call graph for this function:

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

Definition at line 4184 of file xmlstorage.h.

References XMLStorage::XMLFormat::_endl, _format, _out, and _pofstream.

    {
        _out << _format._endl;
        _out.flush();
        delete _pofstream;
    }
XMLStorage::XMLWriter::XMLWriter ( const XMLWriter  ) [private]

Member Function Documentation

bool XMLStorage::XMLWriter::back (  )

go back to previous position

Definition at line 1051 of file xmlstorage.cpp.

Referenced by create_node_content(), XMLRPC::XMLRPCWriter::flush(), XMLRPC::XMLRPCCall::init(), test_write(), test_writer(), XMLRPC::XMLRPCWriter::write_param(), XMLRPC::XMLRPCWriter::write_string_param(), and XMLRPC::XMLRPCWriter::write_struct().

{
    if (!_stack.empty()) {
        write_post(_stack.top());

        _stack.pop();
        return true;
    } else {
        assert(!_stack.empty());
        return false;
    }
}

Here is the caller graph for this function:

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

Definition at line 1064 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 1031 of file xmlstorage.cpp.

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

Referenced by create_node_content(), XMLRPC::XMLRPCCall::init(), test_write(), test_writer(), XMLRPC::XMLRPCWriter::write_param(), XMLRPC::XMLRPCWriter::write_string_param(), and XMLRPC::XMLRPCWriter::write_struct().

{
    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);
}

Here is the caller graph for this function:

void XMLStorage::XMLWriter::create_node_content ( const XS_String node_name,
const XS_String content 
) [inline]

create node with string content

Definition at line 4239 of file xmlstorage.h.

References back(), create(), and set_content().

    {
        create(node_name);
            set_content(content);
        back();
    }

Here is the call graph for this function:

bool XMLStorage::XMLWriter::good (  ) const [inline]

Definition at line 4191 of file xmlstorage.h.

References _out.

    {
        return _out.good();
    }
XS_String& XMLStorage::XMLWriter::operator[] ( const XS_String attr_name ) [inline]

index operator write access to an attribute

Definition at line 4210 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::put ( const XS_String attr_name,
const XS_String value 
) [inline]

attribute setting

Definition at line 4203 of file xmlstorage.h.

References _stack.

    {
        if (!_stack.empty())
            _stack.top()._attributes[attr_name] = value;
    }
void XMLStorage::XMLWriter::set_attributes ( const XMLNode::AttributeMap attrs ) [inline]

Definition at line 4218 of file xmlstorage.h.

References _stack.

    {
        if (!_stack.empty())
            _stack.top()._attributes = attrs;
    }
void XMLStorage::XMLWriter::set_content ( const XS_String s,
bool  cdata = false 
) [inline]

set element node content

Definition at line 4225 of file xmlstorage.h.

References _stack, and XMLStorage::EncodeXMLString().

Referenced by create_node_content(), XMLRPC::XMLRPCCall::init(), test_write(), test_writer(), XMLRPC::XMLRPCWriter::write_param(), XMLRPC::XMLRPCWriter::write_string_param(), and XMLRPC::XMLRPCWriter::write_struct().

    {
        if (!_stack.empty())
            _stack.top()._content = EncodeXMLString(s.c_str(), cdata);
    }

Here is the call graph for this function:

Here is the caller graph for this function:

void XMLStorage::XMLWriter::set_encoded_content ( const std::string &  s ) [inline]

set element node content from encoded string

Definition at line 4232 of file xmlstorage.h.

References _stack.

    {
        if (!_stack.empty())
            _stack.top()._content = s;
    }
void XMLStorage::XMLWriter::write ( const std::string &  s )

direct string output

Definition at line 1121 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 1085 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 1093 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 1071 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;
}

Member Data Documentation

Definition at line 4257 of file xmlstorage.h.

Referenced by ~XMLWriter().

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

Definition at line 4256 of file xmlstorage.h.

Referenced by good(), XMLWriter(), and ~XMLWriter().

Definition at line 4255 of file xmlstorage.h.

Referenced by ~XMLWriter().

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

Definition at line 4272 of file xmlstorage.h.

Referenced by operator[](), put(), set_attributes(), set_content(), and set_encoded_content().

Definition at line 4274 of file xmlstorage.h.

Referenced by operator[]().


The documentation for this struct was generated from the following files: