1 // ANNA - Anna is Not Nothingness Anymore //
3 // (c) Copyright 2005-2015 Eduardo Ramos Testillano & Francisco Ruiz Rayo //
5 // See project site at http://redmine.teslayout.com/projects/anna-suite //
6 // See accompanying file LICENSE or copy at http://www.teslayout.com/projects/public/anna.LICENSE //
9 #ifndef anna_xml_Compiler_hpp
10 #define anna_xml_Compiler_hpp
12 #include <anna/config/defines.hpp>
13 #include <anna/core/RuntimeException.hpp>
14 #include <anna/core/mt/Mutex.hpp>
16 // Three-space tabulator for xml string presentation (node indent)
17 #define ANNA_XML_COMPILER_TAB " "
28 Genera el documento XML a correspondiente a un nodo anna::xml::Node.
30 class Compiler : public Mutex {
33 Modo de generacion del documento XML.
37 Visual = 0, /**< Separa cada uno de los componentes con espacios y retornos de carro */
38 Compact = 1, /**< Los componentes no tienen separacion entre si. Se puede usar para optimizar envios de mensajes */
39 ShowNullAttribute = 2, /**< Visualiza el valor nulo de un atributo como ="" */
40 NoNamespaces = 4 /**<Obtiene el documento XML sin ofrecer informaciĆ³n sobre los namespaces */
50 Obtiene el documento XML correspondiente al nodo recibido.
51 \param node Nodo XML del que queremos obtener el documento XML origen.
52 \param flag Combinacion de valores que configura la forma de crear el documento.
53 \return Una cadena con el documento XML correspondiente al nodo recibido.
55 const char* apply(const Node* node, const int flag = Mode::Visual) throw(RuntimeException);
58 Obtiene el documento XML correspondiente al nodo recibido.
59 \param document Documento del que obtener los ajustes de configuraciĆ³n del documento XML.
60 \param node Nodo XML del que queremos obtener el documento XML origen.
61 \param flag Combinacion de valores que configura la forma de crear el documento.
62 \return Una cadena con el documento XML correspondiente al nodo recibido.
64 const char* apply(const Document& document, const Node* node, const int flag = Mode::Visual) throw(RuntimeException);
70 a_buffer = new char [a_maxSize = 8192];
71 a_buffer [a_size = 0] = 0;
73 ~Result() { delete [] a_buffer; }
75 void clear() throw() { a_buffer [a_size = 0] = 0; }
77 void operator += (const char c)
78 throw(RuntimeException) {
79 extend(sizeof(c) * 2);
80 a_buffer [a_size ++] = c;
81 a_buffer [a_size] = 0;
84 void operator += (const char* str)
85 throw(RuntimeException) {
86 const int len = anna_strlen(str);
88 anna_strcpy(a_buffer + a_size, str);
92 void operator += (const std::string& str) throw(RuntimeException) {(*this) += str.c_str(); }
94 const char* c_str() const throw() { return a_buffer; }
101 void extend(const int size) throw(RuntimeException);
106 Compiler(const Compiler&);
108 static void apply(const Node*, Result&, const int level, const int flags) throw(RuntimeException);
109 static void apply(const Node*, Result&, const int flags) throw(RuntimeException);
110 static void open(const Node*, Result&, const int level, const bool quickClose, const bool newline, const int flags)
111 throw(RuntimeException);
112 static void writeFullName(const Node*, Result&, const int flags) throw(RuntimeException);
113 static void writeFullName(const Attribute*, Result&, const int flags) throw(RuntimeException);
114 static void close(const Node*, Result&, const int level, const int flags) throw(RuntimeException);