ANNA Suite  2020b
Multipurpose development suite for Telco applications
DataBlock.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_DataBlock_hpp
10 #define anna_core_DataBlock_hpp
11 
13 #include <anna/config/defines.hpp>
14 
15 namespace anna {
16 
24 class DataBlock {
25 public:
33  explicit DataBlock(const bool deepCopy = false) :
34  a_buffer(NULL),
35  a_size(0),
36  a_deepCopy(deepCopy),
37  a_maxSize(0) {}
38 
48  DataBlock(const char* buffer, const int size, const bool deepCopy = false) noexcept(false);
49 
56  DataBlock(const DataBlock& other) noexcept(false);
57 
61  virtual ~DataBlock();
62 
63  // Accesores
70  int getMaxSize() const { return a_maxSize; }
71 
78  int getSize() const { return a_size; }
79 
86  const char* getData() const { return a_buffer; }
87 
93  bool isEmpty() const { return (a_size == 0) ? true : false; }
94 
100  bool deepCopy() const { return a_deepCopy; }
101 
107  void setSize(const int size) noexcept(false);
108 
118  DataBlock& operator += (const char c) noexcept(false) {
119  append(&c, sizeof(c));
120  return *this;
121  }
122 
132  DataBlock& operator += (const DataBlock& right) noexcept(false) {
133  if(this != &right)
134  append(right.a_buffer, right.a_size);
135 
136  return *this;
137  }
138 
148  DataBlock& operator += (const std::string& str) noexcept(false) {
149  append(str.c_str(), str.length());
150  return *this;
151  }
152 
158  const char operator [](const int pos) const noexcept(false);
159 
165  char& operator [](const int pos) noexcept(false);
166 
175  void append(const char* data, const int len) noexcept(false);
176 
184  void append(const DataBlock& other) noexcept(false) { append(other.a_buffer, other.a_size); }
185 
191  void assign(const DataBlock& right) noexcept(false) { *this = right; }
192 
199  void assign(const char* buffer, const int size) noexcept(false);
200 
207  DataBlock& operator = (const DataBlock& right) noexcept(false);
208 
215  DataBlock& operator = (const char c) noexcept(false) { clear(); (*this) += c; return *this; }
216 
223  DataBlock& operator = (const std::string& str) noexcept(false) { clear(); (*this) += str; return *this; }
224 
225  // Metodos
232  void allocate(const int nbytes) noexcept(false);
233 
240  void clear() noexcept(false) { a_size = 0; }
241 
248  void remove(const int pos, const int nbytes) noexcept(false);
249 
254  void remove(const int nbytes) noexcept(false);
255 
259  std::string asString(const int characterByLine = 24) const ;
260 
261 protected:
270  void initialize(const char* buffer, const int size) noexcept(false);
271 
277  void setBuffer(const char* buffer) { a_buffer = (char*) buffer; }
278 
284  void setMaxSize(const int maxSize) { a_maxSize = maxSize; }
285 
286 private:
287  char* a_buffer;
288  int a_size;
289  bool a_deepCopy;
290  int a_maxSize;
291 
292  void extend(const int nbytes) noexcept(false);
293 };
294 
295 } //namespace anna
296 
297 #endif
298 
bool isEmpty() const
Definition: DataBlock.hpp:93
DataBlock & operator=(const DataBlock &right) noexcept(false)
void append(const DataBlock &other) noexcept(false)
Definition: DataBlock.hpp:184
const char operator[](const int pos) const noexcept(false)
const char * getData() const
Definition: DataBlock.hpp:86
void setBuffer(const char *buffer)
Definition: DataBlock.hpp:277
int getMaxSize() const
Definition: DataBlock.hpp:70
virtual ~DataBlock()
void setSize(const int size) noexcept(false)
int getSize() const
Definition: DataBlock.hpp:78
bool deepCopy() const
Definition: DataBlock.hpp:100
DataBlock & operator+=(const char c) noexcept(false)
Definition: DataBlock.hpp:118
void initialize(const char *buffer, const int size) noexcept(false)
void clear() noexcept(false)
Definition: DataBlock.hpp:240
Definition: app.hpp:12
void append(const char *data, const int len) noexcept(false)
void setMaxSize(const int maxSize)
Definition: DataBlock.hpp:284
DataBlock(const bool deepCopy=false)
Definition: DataBlock.hpp:33
void assign(const DataBlock &right) noexcept(false)
Definition: DataBlock.hpp:191
void allocate(const int nbytes) noexcept(false)
std::string asString(const int characterByLine=24) const
Definition: DataBlock.hpp:24