Milo  0.1
Milo:EquationManipulationProgram
Public Member Functions | Private Types | Private Attributes | List of all members
XML::Stream Class Reference

#include <xml.h>

Collaboration diagram for XML::Stream:
Collaboration graph
[legend]

Public Member Functions

 Stream (std::ostream &os, const std::string &root, int step=2, std::string sep="\n")
 
 ~Stream ()
 
void out (State state)
 
void out (const std::string &tag)
 

Private Types

enum  Pending {
  NONE, HEADER_TAG, NAME, VALUE,
  ELEMENT_TAG
}
 

Private Attributes

std::string m_sep
 Character to output before indention.
 
std::ostream & m_os
 Ouput character stream to write XML.
 
const int m_indent_step
 Number of spaces in indention before HEADER and standalone FOOTER.
 
Pending m_pending = NONE
 Current pending state.
 
std::string m_nv
 temp space for name tag value.
 
int m_indent = 0
 current indention of XML line.
 
FSM fsm
 current FSM state.
 

Detailed Description

Output stream for XML. Overloaded << operator is used to output XML states and tags. The constructor and destructor adds the root tag supplied ("document" in this example) level to the output. Destructor will also closes all open header tags. Example code:

{
  Stream xml(std::cout, "document");  
  xml << HEADER << "foo";
  xml << HEADER << "bar" << NAME_VALUE << "flag" << "true" << ATOM_END;
  xml << HEADER << "text" << HEADER_END << ELEMENT << "Example text & element" << FOOTER;
}

This will give output:

<document>
  <foo>
    <bar flag="true">
    <text>Example text & element</text>
  </foo>
</document>

Member Enumeration Documentation

enum XML::Stream::Pending
private

Possible pending states. The HEADER tag leaves the stream in a HEADER_TAG pending state. The ELEMENT tag leaves thestream in an ELEMENT_TAG pending state. The NAME_VALUE tag leaves the stream in a NAME pending state. After the call to out(const std::string&), the stream is in a value pending state.

Constructor & Destructor Documentation

XML::Stream::Stream ( std::ostream &  os,
const std::string &  root,
int  step = 2,
std::string  sep = "\n" 
)

Constructor for class Stream. Initialize private data members and add root header.

Parameters
osOutput character stream to write XML
rootRoot tag of xml output
stepNumber of spaces to add to indention
sepCharacter to add before each indention
XML::Stream::~Stream ( )

Destructor for class stream. Close all open headers with a footer.

Member Function Documentation

void XML::Stream::out ( State  state)

Advances the XML output stream to the given state. Some states like footers are complete onto themselves and others like headers create a pending state to complete the transition.

Parameters
stateNew state for the output stream.
void XML::Stream::out ( const std::string &  tag)

Called when XML stream has a pending state that needs another string. With the pending state satisfied, it it completes the transistion to the next state.

Parameters
tagString value for pending state.

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