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_comm_Variable_hpp
10 #define anna_comm_Variable_hpp
11 
13 #include <anna/core/DataBlock.hpp>
14 
15 #include <anna/comm/functions.hpp>
16 
17 namespace anna {
18 
19 namespace comm {
20 
21 class CompatCodec;
22 
28 class Variable : public anna::Variable {
29 public:
36  Variable(const short int id, const char* name, std::string& value) :
37  anna::Variable(name, value),
38  a_id(id), a_precode(true) {;}
39 
47  Variable(const short int id, const char* name, int& value) :
48  anna::Variable(name, value),
49  a_id(id), a_precode(true) {;}
50 
58  Variable(const short int id, const char* name, S64& value) :
59  anna::Variable(name, value),
60  a_id(id), a_precode(true) {;}
61 
69  Variable(const short int id, const char* name, bool& value) :
70  anna::Variable(name, value),
71  a_id(id), a_precode(true) {;}
72 
80  Variable(const short int id, const char* name, DataBlock& value) :
81  anna::Variable(name, value),
82  a_id(id), a_precode(true) {;}
83 
91  Variable(const short int id, const char* name, float& value) :
92  anna::Variable(name, value),
93  a_id(id), a_precode(true) {;}
94 
102  Variable(const short int id, const char* name, double& value) :
103  anna::Variable(name, value),
104  a_id(id), a_precode(true) {;}
105 
113  Variable(const short int id, const char* name, comm::CompatCodec& value) :
114  anna::Variable(name, (void*) &value),
115  a_id(id), a_precode(true) {;}
116 
121  short int getId() const { return a_id; }
122 
123 private:
124  const short int a_id;
125  DataBlock a_precode;
126 
127  const DataBlock& codec() const noexcept(false) {
128  return (a_precode.isEmpty() == false) ? a_precode : precodec();
129  }
130  const DataBlock& precodec() const noexcept(false) {
131  char aux [sizeof(short int)];
132  const_cast <comm::Variable*>(this)->a_precode.append(comm::functions::codeShort(aux, a_id), sizeof(short int));
133  const_cast <comm::Variable*>(this)->a_precode += (char) getType();
134  return a_precode;
135  }
136 
137  friend class CompatCodec;
138 };
139 
140 }
141 
142 }
143 
144 #endif
145 
Definition: CompatCodec.hpp:91
bool isEmpty() const
Definition: DataBlock.hpp:93
Variable(const short int id, const char *name, DataBlock &value)
Definition: Variable.hpp:80
Variable(const short int id, const char *name, comm::CompatCodec &value)
Definition: Variable.hpp:113
static const char * codeShort(char *result, const short int n)
short int getId() const
Definition: Variable.hpp:121
int64_t S64
Definition: defines.hpp:84
Definition: Variable.hpp:28
Variable(const short int id, const char *name, std::string &value)
Definition: Variable.hpp:36
Variable(const short int id, const char *name, float &value)
Definition: Variable.hpp:91
Variable(const short int id, const char *name, double &value)
Definition: Variable.hpp:102
Variable(const short int id, const char *name, bool &value)
Definition: Variable.hpp:69
Definition: app.hpp:12
Variable(const short int id, const char *name, int &value)
Definition: Variable.hpp:47
void append(const char *data, const int len) noexcept(false)
Variable(const short int id, const char *name, S64 &value)
Definition: Variable.hpp:58
Type::_v getType() const
Definition: Variable.hpp:183
Definition: Variable.hpp:25
Definition: DataBlock.hpp:24