xml_generator Class Reference

Supports simple XML output with consistency checking. More...

#include <xml_generator.h>

Collaboration diagram for xml_generator:

Collaboration graph
[legend]
List of all members.

Public Types

enum  behavioral_mods { HUMAN_READABLE = 0x1, CLEAN_ILLEGAL_CHARS = 0x2 }
enum  outcomes { OKAY = common::OKAY, NOT_FOUND = common::NOT_FOUND, ERRONEOUS_TAG = common::INVALID }
 the possible ways that operations here can complete. More...

Public Member Functions

 xml_generator (int modifiers=HUMAN_READABLE|CLEAN_ILLEGAL_CHARS)
 creates an xml generator with the specified behavior.
virtual ~xml_generator ()
 IMPLEMENT_CLASS_NAME ("xml_generator")
void reset ()
 throws out all accumulated information.
istring generate ()
 writes the current state into a string and returns it.
void generate (istring &generated)
 synonym method, writes the current state into "generated".
outcome add_header (const istring &tag_name, const string_table &attributes)
 adds an xml style header with the "tag_name" and "attributes".
outcome open_tag (const istring &tag_name, const string_table &attributes)
 adds a tag with "tag_name" and the "attributes", if any.
outcome open_tag (const istring &tag_name)
 adds a tag with "tag_name" without any attributes.
outcome close_tag (const istring &tag_name)
 closes a previously added "tag_name".
void close_all_tags ()
 a wide-bore method that closes all outstanding tags.
outcome add_content (const istring &content)
 stores content into the currently opened tag.
void set_indentation (int to_indent)
 sets the number of spaces to indent for the human readable form.

Static Public Member Functions

static const char * outcome_name (const outcome &to_name)
 reports the string version of "to_name".
static istring clean_reserved (const istring &to_modify, bool replace_spaces=false)
 returns a cleaned version of "to_modify" to make it XML appropriate.
static void clean_reserved_mod (istring &to_modify, bool replace_spaces=false)
 ensures that "to_modify" contains only characters valid for XML.

Detailed Description

Supports simple XML output with consistency checking.

Definition at line 30 of file xml_generator.h.


Member Enumeration Documentation

enum xml_generator::behavioral_mods

Enumerator:
HUMAN_READABLE 
CLEAN_ILLEGAL_CHARS 

Definition at line 33 of file xml_generator.h.

enum xml_generator::outcomes

the possible ways that operations here can complete.

Enumerator:
OKAY 
NOT_FOUND 
ERRONEOUS_TAG 

Definition at line 46 of file xml_generator.h.


Constructor & Destructor Documentation

xml_generator::xml_generator ( int  modifiers = HUMAN_READABLE|CLEAN_ILLEGAL_CHARS  ) 

creates an xml generator with the specified behavior.

Definition at line 53 of file xml_generator.cpp.

xml_generator::~xml_generator (  )  [virtual]

Definition at line 62 of file xml_generator.cpp.

References WHACK().


Member Function Documentation

xml_generator::IMPLEMENT_CLASS_NAME ( "xml_generator"   ) 

const char * xml_generator::outcome_name ( const outcome to_name  )  [static]

reports the string version of "to_name".

Definition at line 68 of file xml_generator.cpp.

References ERRONEOUS_TAG, common::outcome_name(), and outcome::value().

void xml_generator::reset (  ) 

throws out all accumulated information.

Definition at line 82 of file xml_generator.cpp.

References common::OKAY, and istring::reset().

istring xml_generator::generate (  ) 

writes the current state into a string and returns it.

if there was an error during generation, the string will be empty. note that unclosed tags are not considered an error; they will simply be closed. note that the accumulated string is not cleared after the generate() invocation. use reset() to clear out all prior state.

Definition at line 89 of file xml_generator.cpp.

void xml_generator::generate ( istring generated  ) 

synonym method, writes the current state into "generated".

Definition at line 96 of file xml_generator.cpp.

References close_all_tags(), and log_base::platform_ending().

outcome xml_generator::add_header ( const istring tag_name,
const string_table attributes 
)

adds an xml style header with the "tag_name" and "attributes".

headers can be located anywhere in the file.

Definition at line 110 of file xml_generator.cpp.

References OKAY.

outcome xml_generator::open_tag ( const istring tag_name,
const string_table attributes 
)

adds a tag with "tag_name" and the "attributes", if any.

this adds an item into the output string in the form:

       <tag_name attrib1="value1" attrib2="value2"...> 
it is required that you close the tag later on, after the tag's contents have been added.

Definition at line 118 of file xml_generator.cpp.

References OKAY.

Referenced by open_tag().

outcome xml_generator::open_tag ( const istring tag_name  ) 

adds a tag with "tag_name" without any attributes.

Definition at line 104 of file xml_generator.cpp.

References open_tag().

outcome xml_generator::close_tag ( const istring tag_name  ) 

closes a previously added "tag_name".

this will generate xml code like so:

       </tag_name> 
note that it is an error to try to close any tag but the most recently opened one.

Definition at line 126 of file xml_generator.cpp.

References ERRONEOUS_TAG, NOT_FOUND, and OKAY.

Referenced by close_all_tags().

void xml_generator::close_all_tags (  ) 

a wide-bore method that closes all outstanding tags.

Definition at line 136 of file xml_generator.cpp.

References close_tag().

Referenced by generate().

outcome xml_generator::add_content ( const istring content  ) 

stores content into the currently opened tag.

it is an error to add content when no tag is open.

Definition at line 143 of file xml_generator.cpp.

References clean_reserved(), string_manipulation::indentation(), OKAY, and log_base::platform_ending().

void xml_generator::set_indentation ( int  to_indent  ) 

sets the number of spaces to indent for the human readable form.

Definition at line 76 of file xml_generator.cpp.

istring xml_generator::clean_reserved ( const istring to_modify,
bool  replace_spaces = false 
) [static]

returns a cleaned version of "to_modify" to make it XML appropriate.

if "replace_spaces" is true, then any spaces will be turned into their html code equivalent; this helps in attribute names.

Definition at line 250 of file xml_generator.cpp.

References clean_reserved_mod().

Referenced by add_content().

void xml_generator::clean_reserved_mod ( istring to_modify,
bool  replace_spaces = false 
) [static]

ensures that "to_modify" contains only characters valid for XML.

this is only different from the other clean method because this one modifies the string in place.

Definition at line 225 of file xml_generator.cpp.

References istring::length(), and PLUGIN_REPLACEMENT.

Referenced by clean_reserved().


The documentation for this class was generated from the following files:
Generated on Fri Nov 28 04:31:04 2008 for HOOPLE Libraries by  doxygen 1.5.1