ANNA Suite  2020b
Multipurpose development suite for Telco applications
TextComposer.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_core_util_TextComposer_hpp
10 #define anna_core_util_TextComposer_hpp
11 
12 #include <vector>
13 
15 #include <anna/core/mt/Mutex.hpp>
16 #include <anna/core/mt/Guard.hpp>
17 #include <anna/core//DataBlock.hpp>
18 
20 
21 namespace anna {
22 
23 class TextManager;
24 class TextVariable;
25 
59 class TextComposer : std::vector <TextVariable*> {
60  typedef std::vector <TextVariable*> container;
61  typedef container::iterator variable_iterator;
62  typedef container::const_iterator const_variable_iterator;
63 
64 public:
65 
69  ~TextComposer();
70 
71  TextVariable& operator[](const char* varName) noexcept(false) {
72  return *(find(varName, Exception::Mode::Throw));
73  }
74 
79  void initialize() noexcept(false);
80 
86  const int getId() const { return a_id; }
87 
92  int getNumberOfVariables() const { return container::size(); }
93 
98  String asString() const ;
99 
100 protected:
107  TextComposer(const int id, const char* expression) : a_id(id), a_expression(expression), a_prefix(NULL), a_buffer(true) {;}
108 
113  String apply() const noexcept(false);
114 
119  static TextVariable* textVariable(variable_iterator ii) { return *ii; }
120 
125  static const TextVariable* textVariable(const_variable_iterator ii) { return *ii; }
126 
127 private:
128  const int a_id;
129  const String a_expression;
130  String* a_prefix;
131  Mutex a_mutex;
132  mutable DataBlock a_buffer;
133 
134  TextComposer(const TextComposer&);
135 
136  TextVariable* find(const char* name, const Exception::Mode::_v) noexcept(false);
137  void lock() noexcept(false) { a_mutex.lock(); }
138  void unlock() { a_mutex.unlock(); }
139 
140  static TextVariable::Type::_v calculeType(const char* format) noexcept(false);
141 
142  friend class TextManager;
143 // friend class Guard <TextComposer>;
144 // friend class Protector;
145 };
146 
147 }
148 
149 #endif
150 
Definition: TextComposer.hpp:59
Definition: Exception.hpp:26
TextComposer(const int id, const char *expression)
Definition: TextComposer.hpp:107
_v
Definition: Exception.hpp:26
void initialize() noexcept(false)
Definition: TextVariable.hpp:24
virtual void unlock()
String asString() const
virtual void lock() noexcept(false)
static const TextVariable * textVariable(const_variable_iterator ii)
Definition: TextComposer.hpp:125
Definition: TextManager.hpp:24
const int getId() const
Definition: TextComposer.hpp:86
Definition: String.hpp:25
int getNumberOfVariables() const
Definition: TextComposer.hpp:92
String apply() const noexcept(false)
Definition: app.hpp:12
_v
Definition: Variable.hpp:31
static TextVariable * textVariable(variable_iterator ii)
Definition: TextComposer.hpp:119
TextVariable & operator[](const char *varName) noexcept(false)
Definition: TextComposer.hpp:71
Definition: Mutex.hpp:41
Definition: DataBlock.hpp:24