ANNA Suite  2020b
Multipurpose development suite for Telco applications
ResultCode.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_dbms_ResultCode_hpp
10 #define anna_dbms_ResultCode_hpp
11 
12 #include <string>
13 
14 #include <string.h>
15 
16 #include <stdlib.h>
17 
18 #include <anna/config/defines.hpp>
20 
21 namespace anna {
22 
23 namespace dbms {
24 
29 class ResultCode {
30 public:
36  ResultCode() : a_errorText(NULL), a_errorDecoder(NULL), a_errorCode(0) {;}
37 
42  ResultCode(const ResultCode& other) :
43  a_errorText(NULL),
44  a_errorDecoder(other.a_errorDecoder) {
45  set(other.a_errorCode, other.a_errorText);
46  }
47 
51  virtual ~ResultCode() { if(a_errorText != NULL) free(a_errorText); }
52 
57  int getErrorCode() const { return a_errorCode; }
58 
63  const char* getErrorText() const { return (a_errorText != NULL) ? a_errorText : ""; }
64 
65  // Operadores
71  ResultCode& operator = (const ResultCode& resultCode)
72  {
73  if(this != &resultCode) {
74  a_errorDecoder = resultCode.a_errorDecoder;
75  set(resultCode.a_errorCode, resultCode.a_errorText);
76  }
77 
78  return *this;
79  }
80 
87  bool notFound() const noexcept(false);
88 
95  bool successful() const noexcept(false);
96 
105  bool locked() const noexcept(false);
106 
111  bool lostConnection() const noexcept(false);
112 
117  std::string asString() const ;
118 
119 protected:
120  static const int MaxErrorLen = 512;
121 
126  class ErrorDecoder {
127  public:
128  virtual bool notFound(const int errorCode) const = 0;
129  virtual bool successful(const int errorCode) const = 0;
130  virtual bool locked(const int errorCode) const = 0;
131  virtual bool lostConnection(const int errorCode) const = 0;
132  };
133 
142  ResultCode(const int errorCode, const char* errorText, const ErrorDecoder* errorDecoder) :
143  a_errorText(NULL),
144  a_errorDecoder(errorDecoder) {
145  set(errorCode, errorText);
146  }
147 
154  void set(const int errorCode, const char* errorText)
155  {
156  a_errorCode = errorCode;
157  copy(errorText);
158  }
159 
160 private:
161  int a_errorCode;
162  char* a_errorText;
163  const ErrorDecoder* a_errorDecoder;
164 
165  void copy(const char* text) ;
166 };
167 
168 }
169 }
170 
171 #endif
172 
virtual ~ResultCode()
Definition: ResultCode.hpp:51
ResultCode(const ResultCode &other)
Definition: ResultCode.hpp:42
ResultCode(const int errorCode, const char *errorText, const ErrorDecoder *errorDecoder)
Definition: ResultCode.hpp:142
Definition: ResultCode.hpp:126
ResultCode & operator=(const ResultCode &resultCode)
Definition: ResultCode.hpp:71
static const int MaxErrorLen
Definition: ResultCode.hpp:120
virtual bool lostConnection(const int errorCode) const =0
int getErrorCode() const
Definition: ResultCode.hpp:57
virtual bool notFound(const int errorCode) const =0
virtual bool successful(const int errorCode) const =0
bool notFound() const noexcept(false)
Definition: app.hpp:12
std::string asString() const
virtual bool locked(const int errorCode) const =0
bool locked() const noexcept(false)
bool lostConnection() const noexcept(false)
Definition: ResultCode.hpp:29
const char * getErrorText() const
Definition: ResultCode.hpp:63
ResultCode()
Definition: ResultCode.hpp:36
bool successful() const noexcept(false)