ANNA Suite  2020b
Multipurpose development suite for Telco applications
Variable.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_Variable_hpp
10 #define anna_core_util_Variable_hpp
11 
16 #include <anna/core/DataBlock.hpp>
17 
18 namespace anna {
19 
25 class Variable {
26 public:
30  struct Type {
31  enum _v {
32  None = -1,
38  Boolean = 5,
39  Block = 6,
43  };
45  };
46 
47  // Constructores
54  Variable(const char* name, std::string& value) :
55  a_name(name),
56  a_isNull(false),
57  a_type(Type::String),
58  a_isOwner(false) {
59  a_value.a_string = &value;
60  }
61 
62 
69  Variable(const char* name, int& value) :
70  a_name(name),
71  a_isNull(false),
72  a_type(Type::Integer),
73  a_isOwner(false) {
74  value = 0;
75  a_value.a_integer = &value;
76  }
77 
84  Variable(const char* name, S64& value) :
85  a_name(name),
86  a_isNull(false),
87  a_type(Type::Integer64),
88  a_isOwner(false) {
89  value = 0;
90  a_value.a_longInteger = &value;
91  }
92 
99  Variable(const char* name, bool& value) :
100  a_name(name),
101  a_isNull(false),
102  a_type(Type::Boolean),
103  a_isOwner(false) {
104  value = false;
105  a_value.a_boolean = &value;
106  }
107 
114  Variable(const char* name, DataBlock& value) :
115  a_name(name),
116  a_isNull(false),
117  a_type(Type::Block),
118  a_isOwner(false) {
119  a_value.a_dataBlock = &value;
120  }
121 
128  Variable(const char* name, float& value) :
129  a_name(name),
130  a_isNull(false),
131  a_type(Type::Float),
132  a_isOwner(false) {
133  value = 0;
134  a_value.a_float = &value;
135  }
136 
143  Variable(const char* name, double& value) :
144  a_name(name),
145  a_isNull(false),
146  a_type(Type::Double),
147  a_isOwner(false) {
148  value = 0;
149  a_value.a_double = &value;
150  }
151 
158  Variable(const char* name, void* value) :
159  a_name(name),
160  a_isNull(false),
161  a_type(Type::Custom),
162  a_isOwner(false) {
163  a_value.a_custom = value;
164  }
165 
171  Variable(const char* name, const Type::_v type);
172 
176  virtual ~Variable();
177 
178  // Accesores
183  Type::_v getType() const { return a_type; }
184 
189  const char* getName() const { return a_name.c_str(); }
190 
195  bool isNull() const { return a_isNull; }
196 
202  const char* getStringValue() const noexcept(false);
203 
209  int getIntegerValue() const noexcept(false);
210 
216  S64 getInteger64Value() const noexcept(false);
217 
224  bool getBooleanValue() const noexcept(false) ;
225 
231  const DataBlock& getDataBlockValue() const noexcept(false) ;
232 
238  float getFloatValue() const noexcept(false);
239 
245  double getDoubleValue() const noexcept(false);
246 
250  void* getCustom() noexcept(false) {
251  verifyMatchType(Type::Custom, ANNA_FILE_LOCATION);
252  return a_value.a_custom;
253  }
254 
258  const void* getCustom() const noexcept(false) {
259  verifyMatchType(Type::Custom, ANNA_FILE_LOCATION);
260  return a_value.a_custom;
261  }
262 
266  void setCustom(void* value) noexcept(false) {
267  verifyMatchType(Type::Custom, ANNA_FILE_LOCATION);
268  a_isNull = (value == NULL);
269  a_value.a_custom = value;
270  }
271 
276  int getInteger() const { return *a_value.a_integer; }
277 
282  S64 getInteger64() const { return *a_value.a_longInteger; }
283 
288  bool getBoolean() const { return *a_value.a_boolean; }
289 
294  const DataBlock& getDataBlock() const { return *a_value.a_dataBlock; }
295 
300  float getFloat() const { return *a_value.a_float; }
301 
306  double getDouble() const { return *a_value.a_double; }
307 
308  // Modificadores
316  void setValue(const char* value) noexcept(false);
317 
325  void setCharPointer(const char* value) noexcept(false);
326 
334  void setValue(const int value) noexcept(false);
335 
343  void setValue(const S64 value) noexcept(false) ;
344 
352  void setValue(const bool value) noexcept(false);
353 
361  void setValue(const DataBlock& value) noexcept(false) ;
362 
370  void setValue(const float value) noexcept(false) ;
371 
379  void setValue(const double value) noexcept(false) ;
380 
385  void setNull(const bool isNull = true) { a_isNull = isNull; }
386 
391  void setInteger(const int value) { *a_value.a_integer = value; a_isNull = false; }
392 
397  void setLong(const S64 value) { *a_value.a_longInteger = value; a_isNull = false; }
398 
403  void setBoolean(const bool value) { *a_value.a_boolean = value; a_isNull = false; }
404 
409  void setDataBlock(const DataBlock& value) { *a_value.a_dataBlock = value; a_isNull = false; }
410 
415  void setFloat(const float value) { *a_value.a_float = value; a_isNull = false; }
416 
421  void setDouble(const double value) { *a_value.a_double = value; a_isNull = false; }
422 
427  bool isEqual(const Variable& right) const { return a_name == right.a_name; }
428 
433  virtual String asString() const ;
434 
435 protected:
443  void* getReference() const ;
444 
451  void* buffer() const ;
452 
457  bool* getNullIndicator() { return &a_isNull; }
458 
459 private:
460  std::string a_name;
461  bool a_isNull;
462  const Type::_v a_type;
463  const bool a_isOwner;
464 
465  union {
466  std::string* a_string;
467  int* a_integer;
469  bool* a_boolean;
471  float* a_float;
472  double* a_double;
473  void* a_custom;
474  } a_value;
475  struct {
476  int integer;
478  bool boolean;
479  float theFloat;
480  double theDouble;
481  } a_aux;
482 
483  Variable(const Variable&);
484  Variable& operator = (const Variable&);
485  void verifyIsNotNull(const char* file, const int lineno) const noexcept(false);
486  void verifyMatchSomeType(const Type::_v firstType, const Type::_v secondType, const char* file, const int lineno) const noexcept(false);
487  void verifyMatchType(const Type::_v, const char* file, const int lineno) const noexcept(false);
488 
489 };
490 
491 }
492 
493 #endif
virtual ~Variable()
Definition: Variable.hpp:42
bool * getNullIndicator()
Definition: Variable.hpp:457
void setCharPointer(const char *value) noexcept(false)
void * buffer() const
Variable(const char *name, S64 &value)
Definition: Variable.hpp:84
Variable(const char *name, std::string &value)
Definition: Variable.hpp:54
Variable(const char *name, double &value)
Definition: Variable.hpp:143
Variable(const char *name, bool &value)
Definition: Variable.hpp:99
Definition: Variable.hpp:34
Definition: Variable.hpp:30
bool * a_boolean
Definition: Variable.hpp:469
double getDoubleValue() const noexcept(false)
Definition: Variable.hpp:32
const DataBlock & getDataBlock() const
Definition: Variable.hpp:294
bool getBoolean() const
Definition: Variable.hpp:288
#define anna_declare_enum(name)
Definition: define.autoenum.hpp:48
Definition: Variable.hpp:41
Definition: Variable.hpp:40
Variable(const char *name, int &value)
Definition: Variable.hpp:69
double * a_double
Definition: Variable.hpp:472
double theDouble
Definition: Variable.hpp:480
bool getBooleanValue() const noexcept(false)
int64_t S64
Definition: defines.hpp:84
const DataBlock & getDataBlockValue() const noexcept(false)
Variable(const char *name, DataBlock &value)
Definition: Variable.hpp:114
Definition: Variable.hpp:35
void setCustom(void *value) noexcept(false)
Definition: Variable.hpp:266
void setBoolean(const bool value)
Definition: Variable.hpp:403
std::string * a_string
Definition: Variable.hpp:466
bool boolean
Definition: Variable.hpp:478
void setDouble(const double value)
Definition: Variable.hpp:421
void * getCustom() noexcept(false)
Definition: Variable.hpp:250
Definition: Variable.hpp:37
Variable(const char *name, void *value)
Definition: Variable.hpp:158
double getDouble() const
Definition: Variable.hpp:306
const char * getName() const
Definition: Variable.hpp:189
float * a_float
Definition: Variable.hpp:471
void setDataBlock(const DataBlock &value)
Definition: Variable.hpp:409
float getFloat() const
Definition: Variable.hpp:300
virtual String asString() const
Definition: String.hpp:25
const void * getCustom() const noexcept(false)
Definition: Variable.hpp:258
S64 * a_longInteger
Definition: Variable.hpp:468
void * a_custom
Definition: Variable.hpp:473
Variable(const char *name, float &value)
Definition: Variable.hpp:128
float theFloat
Definition: Variable.hpp:479
void setFloat(const float value)
Definition: Variable.hpp:415
Definition: Variable.hpp:38
Definition: app.hpp:12
_v
Definition: Variable.hpp:31
Definition: Variable.hpp:33
bool isEqual(const Variable &right) const
Definition: Variable.hpp:427
S64 longInteger
Definition: Variable.hpp:477
void setInteger(const int value)
Definition: Variable.hpp:391
int getInteger() const
Definition: Variable.hpp:276
DataBlock * a_dataBlock
Definition: Variable.hpp:470
void setValue(const char *value) noexcept(false)
#define ANNA_FILE_LOCATION
Definition: defines.hpp:23
bool isNull() const
Definition: Variable.hpp:195
Type::_v getType() const
Definition: Variable.hpp:183
void setNull(const bool isNull=true)
Definition: Variable.hpp:385
S64 getInteger64() const
Definition: Variable.hpp:282
int integer
Definition: Variable.hpp:476
Definition: Variable.hpp:36
Definition: Variable.hpp:25
Definition: DataBlock.hpp:24
void setLong(const S64 value)
Definition: Variable.hpp:397
int getIntegerValue() const noexcept(false)
void * getReference() const
const char * getStringValue() const noexcept(false)
Definition: Variable.hpp:39
float getFloatValue() const noexcept(false)
S64 getInteger64Value() const noexcept(false)
int * a_integer
Definition: Variable.hpp:467