handlers.hpp
Go to the documentation of this file.
1 
8 /*****************************************************************************
9 ** Ifdefs
10 *****************************************************************************/
11 
12 #ifndef ECL_ERRORS_HANDLERS_HPP_
13 #define ECL_ERRORS_HANDLERS_HPP_
14 
15 /*****************************************************************************
16 ** Includes
17 *****************************************************************************/
18 
19 #include <ecl/config/macros.hpp>
20 #include <cstring>
21 #include <cstdio>
22 #include "macros.hpp"
23 #include "flags.hpp"
24 
25 /*****************************************************************************
26 ** Namespaces
27 *****************************************************************************/
28 
29 namespace ecl {
30 
58 class ecl_errors_PUBLIC Error {
59 public:
65  Error(const ErrorFlag& flag = UnknownError) : error_flag(flag) {}
66  virtual ~Error() {}
67 
72  virtual ErrorFlag flag() const { return error_flag; }
73  virtual void operator=(const ErrorFlag &error) { error_flag = error; }
74 
75 // virtual void debug(const char* loc) {
76 // #if !defined(NDEBUG) && !defined(ECL_NDEBUG)
77 // printf("%s - %s\n",loc,what());
78 // #endif
79 // }
80 
94  virtual void print(const char* loc) {
95  printf("%s - %s\n",loc,what());
96  }
97 
103  virtual const char* what() const {
104  switch (error_flag) {
105  case (NoError) : { return noErrorString(); }
106  case (OutOfRangeError) : { return outOfRangeErrorString(); }
107  case (ConstructorError) : { return constructorErrorString(); }
108  case (DestructorError) : { return destructorErrorString(); }
109  case (ConversionError) : { return conversionErrorString(); }
110  case (OpenError) : { return openErrorString(); }
111  case (CloseError) : { return closeErrorString(); }
112  case (InvalidArgError) : { return invalidArgErrorString(); }
113  case (ConfigurationError) : { return configurationErrorString(); }
114  case (ConnectionError) : { return connectErrorString(); }
115  case (ReadError) : { return readErrorString(); }
116  case (WriteError) : { return writeErrorString(); }
117  case (NotInitialisedError) : { return notInitialisedErrorString(); }
118  case (PermissionsError) : { return permissionsErrorString(); }
119  case (MemoryError) : { return memoryErrorString(); }
120  case (UsageError) : { return usageErrorString(); }
121  case (RaiiError) : { return raiiErrorString(); }
122  case (ArgNotSupportedError) : { return argNotSupportedErrorString(); }
123  case (NotSupportedError) : { return notSupportedErrorString(); }
124  case (BusyError) : { return busyErrorString(); }
125  case (OutOfResourcesError) : { return outOfResourcesErrorString(); }
126  case (InterruptedError) : { return interruptedErrorString(); }
127  case (BlockingError) : { return blockingErrorString(); }
128  case (SystemFailureError) : { return systemFailureErrorString(); }
129  case (InvalidObjectError) : { return invalidObjectErrorString(); }
130  case (IsLockedError) : { return isLockedErrorString(); }
131  case (TimeOutError) : { return isTimeOutErrorString(); }
132  case (NotFoundError) : { return notFoundErrorString(); }
133  case (ConnectionRefusedError) : { return connectionRefusedString(); }
134 
135  default : { return unknownErrorString(); } // also covers the 'UnknownError flag.
136  }
137  }
138 protected:
139  virtual const char* noErrorString() const { return "No error."; }
140  virtual const char* outOfRangeErrorString() const { return "Out of range error - tried to access beyond the range of the object (usually container)."; }
141  virtual const char* constructorErrorString() const { return "The constructor did not produce a valid object."; }
142  virtual const char* destructorErrorString() const { return "The destructor failed to self destruct."; }
143  virtual const char* conversionErrorString() const { return "Conversion from one type to another failed."; }
144  virtual const char* openErrorString() const { return "Could not open the requested object."; }
145  virtual const char* closeErrorString() const { return "Could not close the requested object."; }
146  virtual const char* invalidArgErrorString() const { return "One of the supplied input arguments was invalid."; }
147  virtual const char* configurationErrorString() const { return "There was a configuration error."; }
148  virtual const char* connectErrorString() const { return "Could not connect."; }
149  virtual const char* readErrorString() const { return "Could not read from the object."; }
150  virtual const char* writeErrorString() const { return "Could not write to the object."; }
151  virtual const char* notInitialisedErrorString() const { return "The object has not been properly initialised yet."; }
152  virtual const char* permissionsErrorString() const { return "The caller does not have the required permissions."; }
153  virtual const char* memoryErrorString() const { return "There was a problem allocating the requested memory."; }
154  virtual const char* usageErrorString() const { return "The object was used incorrectly."; }
155  virtual const char* raiiErrorString() const { return "The object is pure RAII style and must be initialised correctly, you may not use the default constructor."; }
156  virtual const char* argNotSupportedErrorString() const { return "The combination of input arguments is not supported on this platform."; }
157  virtual const char* notSupportedErrorString() const { return "This operation is not supported on this platform."; }
158  virtual const char* busyErrorString() const { return "Resources are busy, operation is not permitted"; }
159  virtual const char* outOfResourcesErrorString() const { return "Out of resources, cannot proceed."; }
160  virtual const char* interruptedErrorString() const { return "This operation was interrupted."; }
161  virtual const char* blockingErrorString() const { return "A device marked as blocking, but used as non-blocking, or vice versa."; }
162  virtual const char* systemFailureErrorString() const { return "A subsystem has failed mid operation."; }
163  virtual const char* invalidObjectErrorString() const { return "Attempted to work on an invalid object."; }
164  virtual const char* isLockedErrorString() const { return "Invalidates attempts to work further because an object is locked."; }
165  virtual const char* isTimeOutErrorString() const { return "A timeout occured."; }
166  virtual const char* notFoundErrorString() const { return "The resource could not be found."; }
167  virtual const char* connectionRefusedString() const { return "The connection was refused by the listener at the other end of the connection."; }
168  virtual const char* unknownErrorString() const { return "Unknown error."; }
169 
170  ErrorFlag error_flag;
171 };
172 
173 
174 } // namespace ecl
175 
176 #endif /* ECL_ERRORS_HANDLERS_HPP_ */
ConstructorError
InvalidObjectError
InterruptedError
void print(const Container &byte_array)
ErrorFlag
PermissionsError
CloseError
ConversionError
InvalidArgError
NotSupportedError
UnknownError
ConfigurationError
NotInitialisedError
OutOfRangeError
WriteError
BlockingError
NotFoundError
IsLockedError
ConnectionError
OutOfResourcesError
UsageError
#define ecl_errors_PUBLIC
TimeOutError
DestructorError
SystemFailureError
MemoryError
ConnectionRefusedError
ArgNotSupportedError


xbot_driver
Author(s): Roc, wangpeng@droid.ac.cn
autogenerated on Sat Oct 10 2020 03:27:37