feisty meow concerns codebase  2.140
xml_generator.h
Go to the documentation of this file.
1 #ifndef XML_GENERATOR_CLASS
2 #define XML_GENERATOR_CLASS
3 
4 /*****************************************************************************\
5 * *
6 * Name : xml_generator *
7 * Author : Chris Koeritz *
8 * *
9 *******************************************************************************
10 * Copyright (c) 2007-$now By Author. This program is free software; you can *
11 * redistribute it and/or modify it under the terms of the GNU General Public *
12 * License as published by the Free Software Foundation; either version 2 of *
13 * the License or (at your option) any later version. This is online at: *
14 * http://www.fsf.org/copyleft/gpl.html *
15 * Please send any updates to: fred@gruntose.com *
16 \*****************************************************************************/
17 
18 #include <basis/astring.h>
19 #include <basis/contracts.h>
21 
22 namespace textual {
23 
24 class tag_info;
25 class tag_stack;
26 
28 
30 {
31 public:
35  };
36 
39 
40  virtual ~xml_generator();
41 
42  DEFINE_CLASS_NAME("xml_generator");
43 
45  enum outcomes {
46  OKAY = basis::common::OKAY,
47  NOT_FOUND = basis::common::NOT_FOUND,
48  ERRONEOUS_TAG = basis::common::INVALID //temporary until we can shed a compatibility concern.
49 // DEF INE_OUTCOME(ERRONEOUS_TAG, -75, "The most recently opened tag must be "
50 // "closed before a new tag can be opened and before any other tag can "
51 // "be closed"),
52  };
53 
54  static const char *outcome_name(const basis::outcome &to_name);
56 
57  void reset();
58 
61 
66  void generate(basis::astring &generated);
68 
69  basis::outcome add_header(const basis::astring &tag_name, const structures::string_table &attributes);
71 
73  basis::outcome open_tag(const basis::astring &tag_name, const structures::string_table &attributes);
75 
80  basis::outcome open_tag(const basis::astring &tag_name);
82 
83  basis::outcome close_tag(const basis::astring &tag_name);
85 
90  void close_all_tags();
92 
95 
97  void set_indentation(int to_indent);
99 
100  static basis::astring clean_reserved(const basis::astring &to_modify,
101  bool replace_spaces = false);
103 
106  static void clean_reserved_mod(basis::astring &to_modify,
107  bool replace_spaces = false);
109 
112 private:
113  tag_stack *_tags;
114  basis::astring *_accumulator;
115  bool _human_read;
116  bool _clean_chars;
117  int _indentation;
118 
119  enum open_types { NORMAL_TAG, HEADER_TAG };
120  void print_open_tag(const tag_info &to_print, int type = NORMAL_TAG);
122  void print_close_tag(const basis::astring &tag_name);
124 };
125 
126 } //namespace.
127 
128 #endif
129 
Provides a dynamically resizable ASCII character string.
Definition: astring.h:35
Outcomes describe the state of completion for an operation.
Definition: outcome.h:31
Provides a symbol_table that holds strings as the content.
Definition: string_table.h:32
Supports simple XML output with consistency checking.
Definition: xml_generator.h:30
basis::outcome add_content(const basis::astring &content)
stores content into the currently opened tag.
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.
static const char * outcome_name(const basis::outcome &to_name)
reports the string version of "to_name".
static void clean_reserved_mod(basis::astring &to_modify, bool replace_spaces=false)
ensures that "to_modify" contains only characters valid for XML.
basis::outcome close_tag(const basis::astring &tag_name)
closes a previously added "tag_name".
DEFINE_CLASS_NAME("xml_generator")
outcomes
the possible ways that operations here can complete.
Definition: xml_generator.h:45
xml_generator(int modifiers=HUMAN_READABLE|CLEAN_ILLEGAL_CHARS)
creates an xml generator with the specified behavior.
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.
basis::astring generate()
writes the current state into a string and returns it.
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".
void close_all_tags()
a wide-bore method that closes all outstanding tags.
void reset()
throws out all accumulated information.
void set_indentation(int to_indent)
sets the number of spaces to indent for the human readable form.