feisty meow concerns codebase  2.140
textual::xml_generator Class Reference

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

#include <xml_generator.h>

Public Types

enum  behavioral_mods { HUMAN_READABLE = 0x1 , CLEAN_ILLEGAL_CHARS = 0x2 }
 
enum  outcomes { OKAY = basis::common::OKAY , NOT_FOUND = basis::common::NOT_FOUND , ERRONEOUS_TAG = basis::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. More...
 
virtual ~xml_generator ()
 
 DEFINE_CLASS_NAME ("xml_generator")
 
void reset ()
 throws out all accumulated information. More...
 
basis::astring generate ()
 writes the current state into a string and returns it. More...
 
void generate (basis::astring &generated)
 synonym method, writes the current state into "generated". More...
 
basis::outcome add_header (const basis::astring &tag_name, const structures::string_table &attributes)
 adds an xml style header with the "tag_name" and "attributes". More...
 
basis::outcome open_tag (const basis::astring &tag_name, const structures::string_table &attributes)
 adds a tag with "tag_name" and the "attributes", if any. More...
 
basis::outcome open_tag (const basis::astring &tag_name)
 adds a tag with "tag_name" without any attributes. More...
 
basis::outcome close_tag (const basis::astring &tag_name)
 closes a previously added "tag_name". More...
 
void close_all_tags ()
 a wide-bore method that closes all outstanding tags. More...
 
basis::outcome add_content (const basis::astring &content)
 stores content into the currently opened tag. More...
 
void set_indentation (int to_indent)
 sets the number of spaces to indent for the human readable form. More...
 

Static Public Member Functions

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

Detailed Description

Supports simple XML output with consistency checking.

Definition at line 29 of file xml_generator.h.

Member Enumeration Documentation

◆ behavioral_mods

Enumerator
HUMAN_READABLE 
CLEAN_ILLEGAL_CHARS 

Definition at line 32 of file xml_generator.h.

◆ outcomes

the possible ways that operations here can complete.

Enumerator
OKAY 
NOT_FOUND 
ERRONEOUS_TAG 

Definition at line 45 of file xml_generator.h.

Constructor & Destructor Documentation

◆ xml_generator()

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

creates an xml generator with the specified behavior.

Definition at line 55 of file xml_generator.cpp.

◆ ~xml_generator()

textual::xml_generator::~xml_generator ( )
virtual

Definition at line 64 of file xml_generator.cpp.

References basis::WHACK().

Member Function Documentation

◆ add_content()

outcome textual::xml_generator::add_content ( const basis::astring content)

stores content into the currently opened tag.

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

Definition at line 145 of file xml_generator.cpp.

References clean_reserved(), textual::string_manipulation::indentation(), OKAY, and textual::parser_bits::platform_eol_to_chars().

◆ add_header()

outcome textual::xml_generator::add_header ( const basis::astring tag_name,
const structures::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 112 of file xml_generator.cpp.

References OKAY.

◆ clean_reserved()

astring textual::xml_generator::clean_reserved ( const basis::astring 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 251 of file xml_generator.cpp.

References clean_reserved_mod().

Referenced by add_content().

◆ clean_reserved_mod()

void textual::xml_generator::clean_reserved_mod ( basis::astring 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 226 of file xml_generator.cpp.

References basis::astring::length(), and PLUGIN_REPLACEMENT.

Referenced by clean_reserved().

◆ close_all_tags()

void textual::xml_generator::close_all_tags ( )

a wide-bore method that closes all outstanding tags.

Definition at line 138 of file xml_generator.cpp.

References close_tag().

Referenced by generate().

◆ close_tag()

outcome textual::xml_generator::close_tag ( const basis::astring 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 128 of file xml_generator.cpp.

References ERRONEOUS_TAG, NOT_FOUND, and OKAY.

Referenced by close_all_tags().

◆ DEFINE_CLASS_NAME()

textual::xml_generator::DEFINE_CLASS_NAME ( "xml_generator"  )

◆ generate() [1/2]

astring textual::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 91 of file xml_generator.cpp.

◆ generate() [2/2]

void textual::xml_generator::generate ( basis::astring generated)

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

Definition at line 98 of file xml_generator.cpp.

References close_all_tags(), and textual::parser_bits::platform_eol_to_chars().

◆ open_tag() [1/2]

outcome textual::xml_generator::open_tag ( const basis::astring tag_name)

adds a tag with "tag_name" without any attributes.

Definition at line 106 of file xml_generator.cpp.

References open_tag().

◆ open_tag() [2/2]

outcome textual::xml_generator::open_tag ( const basis::astring tag_name,
const structures::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 120 of file xml_generator.cpp.

References OKAY.

Referenced by open_tag().

◆ outcome_name()

const char * textual::xml_generator::outcome_name ( const basis::outcome to_name)
static

reports the string version of "to_name".

Definition at line 70 of file xml_generator.cpp.

References ERRONEOUS_TAG, and basis::outcome::value().

◆ reset()

void textual::xml_generator::reset ( )

throws out all accumulated information.

Definition at line 84 of file xml_generator.cpp.

References basis::astring::reset().

◆ set_indentation()

void textual::xml_generator::set_indentation ( int  to_indent)

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

Definition at line 78 of file xml_generator.cpp.


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