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

xmlstorage::XMLWriter Class Reference

on the fly XML writer More...

Collaboration diagram for xmlstorage::XMLWriter:
Collaboration graph
[legend]

List of all members.

Classes

class  StackEntry
 container for XMLWriter state information More...

Public Types

enum  WRITESTATE { NOTHING, ATTRIBUTES, PRE_CLOSED, POST }

Public Member Functions

 this (Stream o, in XMLFormat format=new XMLFormat)
 this (in char[] path, in XMLFormat format=new XMLFormat)
 ~this ()
void close ()
void create (in char[] name)
 create node and move to it
bool back ()
 go back to previous position
void put (in char[] attr_name, in char[] value)
 attribute setting
void opIndexAssign (in char[] attr_name, in char[] value)
 index operator write access to an attribute
void set_content (in char[] s, bool cdata=false)

Protected Types

typedef XMLNode.AttributeMap AttrMap

Protected Member Functions

 stack (StackEntry) _stack
void close_pre (StackEntry entry)
void write_pre (StackEntry entry)
void write_attributes (StackEntry entry)
void write_post (StackEntry entry)

Protected Attributes

Stream _own_stream
Stream _out
XMLFormat _format

Private Member Functions

 this (XMLFormat format, Stream o)

Detailed Description

on the fly XML writer

Definition at line 2283 of file xmlstorage.d.


Member Typedef Documentation

Definition at line 2394 of file xmlstorage.d.


Member Enumeration Documentation

Enumerator:
NOTHING 
ATTRIBUTES 
PRE_CLOSED 
POST 

Definition at line 2385 of file xmlstorage.d.

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

Constructor & Destructor Documentation

xmlstorage::XMLWriter::this ( XMLFormat  format,
Stream  o 
) [inline, private]

Definition at line 2286 of file xmlstorage.d.

References xmlstorage::stack().

    {
        _out = o;
        _format = format;
        _stack = new stack!(StackEntry);

        format.print_header(_out, false);   // _format._endl is printed in write_pre()
    }

Here is the call graph for this function:

xmlstorage::XMLWriter::this ( Stream  o,
in XMLFormat  format = new XMLFormat 
) [inline]

Definition at line 2296 of file xmlstorage.d.

    {
        _own_stream = null;

        this(format, o);
    }
xmlstorage::XMLWriter::this ( in char[]  path,
in XMLFormat  format = new XMLFormat 
) [inline]

Definition at line 2303 of file xmlstorage.d.

    {
        _format = format;

        _own_stream = new BufferedFile(new File(path, FileMode.Out));

        this(format, _own_stream);
    }
xmlstorage::XMLWriter::~this (  ) [inline]

Definition at line 2312 of file xmlstorage.d.

    {
        close();
    }

Member Function Documentation

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

go back to previous position

Definition at line 2353 of file xmlstorage.d.

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

            _stack.pop();
            return true;
        } else
            return false;
    }
void xmlstorage::XMLWriter::close (  ) [inline]

Definition at line 2317 of file xmlstorage.d.

    {
        if (_out) {
            _out.writeString(_format._endl);

            if (_own_stream) {
                _own_stream.close();
                delete _own_stream;
            }

            _out = null;
        }
    }
void xmlstorage::XMLWriter::close_pre ( StackEntry  entry ) [inline, protected]

Definition at line 2414 of file xmlstorage.d.

References xmlstorage::XMLWriter::StackEntry::_state.

    {
        _out.writeString(">");

        entry._state = WRITESTATE.PRE_CLOSED;
    }
void xmlstorage::XMLWriter::create ( in char[]  name ) [inline]

create node and move to it

Definition at line 2332 of file xmlstorage.d.

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

    {
        if (!_stack.empty()) {
            StackEntry last = _stack.top();

            if (last._state < WRITESTATE.PRE_CLOSED) {
                write_attributes(last);
                close_pre(last);
            }

            last._children = true;
        }

        auto entry = new StackEntry;
        entry._node_name = name;
        _stack.push(entry);

        write_pre(entry);
    }
void xmlstorage::XMLWriter::opIndexAssign ( in char[]  attr_name,
in char[]  value 
) [inline]

index operator write access to an attribute

Definition at line 2372 of file xmlstorage.d.

    {
        if (!_stack.empty())
            _stack.top()._attributes[attr_name] = value;
    }
void xmlstorage::XMLWriter::put ( in char[]  attr_name,
in char[]  value 
) [inline]

attribute setting

Definition at line 2365 of file xmlstorage.d.

    {
        if (!_stack.empty())
            _stack.top()._attributes[attr_name] = value;
    }
void xmlstorage::XMLWriter::set_content ( in char[]  s,
bool  cdata = false 
) [inline]

Definition at line 2378 of file xmlstorage.d.

References xmlstorage::EncodeXMLString().

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

Here is the call graph for this function:

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

Definition at line 2434 of file xmlstorage.d.

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

    {
        foreach(key,value; entry._attributes)
            _out.writeString(' ' ~ EncodeXMLString(key) ~ "=\"" ~ EncodeXMLString(value) ~ "\"");

        entry._state = WRITESTATE.ATTRIBUTES;
    }

Here is the call graph for this function:

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

Definition at line 2442 of file xmlstorage.d.

References xmlstorage::XMLWriter::StackEntry::_children, xmlstorage::XMLWriter::StackEntry::_content, xmlstorage::XMLWriter::StackEntry::_node_name, xmlstorage::XMLWriter::StackEntry::_state, xmlstorage::EncodeXMLString(), and xmlstorage::XML_INDENT_SPACE.

    {
        if (entry._state < WRITESTATE.ATTRIBUTES)
            write_attributes(entry);

        if (entry._children || entry._content.length) {
            if (entry._state < WRITESTATE.PRE_CLOSED)
                close_pre(entry);

            _out.writeString(entry._content);
            //entry._state = CONTENT;

            if (_format._pretty>=PRETTY_FLAGS.PRETTY_LINEFEED && !entry._content.length)
                _out.writeString(_format._endl);

            if (_format._pretty==PRETTY_FLAGS.PRETTY_INDENT && !entry._content.length)
                for(size_t i=_stack.length(); --i>0; )
                    _out.writeString(XML_INDENT_SPACE);

            _out.writeString("</" ~ EncodeXMLString(entry._node_name) ~ ">");
        } else {
            _out.writeString("/>");
        }

        entry._state = WRITESTATE.POST;
    }

Here is the call graph for this function:

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

Definition at line 2421 of file xmlstorage.d.

References xmlstorage::XMLWriter::StackEntry::_node_name, xmlstorage::EncodeXMLString(), and xmlstorage::XML_INDENT_SPACE.

    {
        if (_format._pretty >= PRETTY_FLAGS.PRETTY_LINEFEED)
            _out.writeString(_format._endl);

        if (_format._pretty == PRETTY_FLAGS.PRETTY_INDENT)
            for(size_t i=_stack.length(); --i>0; )
                _out.writeString(XML_INDENT_SPACE);

        _out.writeString('<' ~ EncodeXMLString(entry._node_name));
        //entry._state = PRE;
    }

Here is the call graph for this function:


Member Data Documentation

Definition at line 2392 of file xmlstorage.d.

Stream xmlstorage::XMLWriter::_out [protected]

Definition at line 2391 of file xmlstorage.d.

Definition at line 2387 of file xmlstorage.d.


The documentation for this class was generated from the following file: