ANNA Suite  2020b
Multipurpose development suite for Telco applications
Compiler.hpp
Go to the documentation of this file.
1 // ANNA - Anna is Not Nothingness Anymore //
2 // //
3 // (c) Copyright 2005-2015 Eduardo Ramos Testillano & Francisco Ruiz Rayo //
4 // //
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 //
7 
8 
9 #ifndef anna_xml_Compiler_hpp
10 #define anna_xml_Compiler_hpp
11 
12 #include <anna/config/defines.hpp>
14 #include <anna/core/mt/Mutex.hpp>
15 
16 
17 namespace anna {
18 
19 namespace xml {
20 
21 class Node;
22 class Document;
23 class Attribute;
24 
28 class Compiler : public Mutex {
29 public:
33  struct Mode {
34  enum _v {
35  Visual = 0,
36  Compact = 1,
39  Sort = 8,
40  };
41  };
42 
46  Compiler();
47 
54  const char* apply(const Node* node, const int flag = Mode::Visual) noexcept(false);
55 
63  const char* apply(const Document& document, const Node* node, const int flag = Mode::Visual) noexcept(false);
64 
65 private:
66  class Result {
67  public:
68  Result() {
69  a_buffer = new char [a_maxSize = 8192];
70  a_buffer [a_size = 0] = 0;
71  }
72  ~Result() { delete [] a_buffer; }
73 
74  void clear() { a_buffer [a_size = 0] = 0; }
75 
76  void operator += (const char c)
77  noexcept(false) {
78  extend(sizeof(c) * 2);
79  a_buffer [a_size ++] = c;
80  a_buffer [a_size] = 0;
81  }
82 
83  void operator += (const char* str)
84  noexcept(false) {
85  const int len = anna_strlen(str);
86  extend(len + 1);
87  anna_strcpy(a_buffer + a_size, str);
88  a_size += len;
89  }
90 
91  void operator += (const std::string& str) noexcept(false) {(*this) += str.c_str(); }
92 
93  const char* c_str() const { return a_buffer; }
94 
95  private:
96  char* a_buffer;
97  int a_size;
98  int a_maxSize;
99 
100  void extend(const int size) noexcept(false);
101  };
102 
103  Result a_result;
104 
105  Compiler(const Compiler&);
106 
107  static void apply(const Node*, Result&, const int level, const int flags) noexcept(false);
108  static void apply(const Node*, Result&, const int flags) noexcept(false);
109  static void open(const Node*, Result&, const int level, const bool quickClose, const bool newline, const int flags)
110  noexcept(false);
111  static void writeFullName(const Node*, Result&, const int flags) noexcept(false);
112  static void writeFullName(const Attribute*, Result&, const int flags) noexcept(false);
113  static void close(const Node*, Result&, const int level, const int flags) noexcept(false);
114 };
115 
116 }
117 }
118 
119 #endif
Definition: Compiler.hpp:28
Definition: Document.hpp:49
Definition: Compiler.hpp:35
xml::Attribute Attribute
Definition: Attribute.hpp:21
#define anna_strcpy(a, b)
Definition: defines.hpp:45
Definition: Compiler.hpp:36
Definition: Node.hpp:56
#define anna_strlen(a)
Definition: defines.hpp:50
Definition: Attribute.hpp:35
Definition: Compiler.hpp:39
const char * apply(const Node *node, const int flag=Mode::Visual) noexcept(false)
_v
Definition: Compiler.hpp:34
Definition: Compiler.hpp:33
Definition: Compiler.hpp:38
xml::Node Node
Definition: Node.hpp:21
Definition: app.hpp:12
Definition: Mutex.hpp:41