ADTF  3.18.2
result_type_decl.h
Go to the documentation of this file.
1 
15 #ifndef A_UTIL_UTIL_RESULT_RESULT_TYPE_DECL_HEADER_INCLUDED
16 #define A_UTIL_UTIL_RESULT_RESULT_TYPE_DECL_HEADER_INCLUDED
17 
20 
21 #include <utility> //std::swap
22 
23 namespace a_util {
24 namespace result {
25 namespace detail {
26 // forward declaration
27 class IErrorDescription;
28 
29 } // namespace detail
30 
34 class Result {
35 public: // construction
45  Result();
46 
54  Result(bool val);
55 
64  Result(const ResultInfo<void>&);
65 
70  template <typename ErrorType>
71  Result(const ResultInfo<ErrorType>& error);
72 
82  template <typename ErrorType>
83  explicit Result(ResultInfo<ErrorType> error,
84  const char* error_description,
85  std::int32_t line,
86  const char* file,
87  const char* function);
88 
93  Result(std::int32_t error_code);
94 
103  explicit Result(std::int32_t error_code,
104  const char* error_description,
105  std::int32_t line,
106  const char* file,
107  const char* function);
108 
117  explicit Result(const Result& other_result,
118  const char* error_description,
119  std::int32_t line,
120  const char* file,
121  const char* function);
122 
126  ~Result();
127 
134  Result(const Result& other);
135 
146 
153  Result& operator=(Result other);
154 
161  Result& operator=(bool val);
162 
169  Result& operator=(std::int32_t val);
170 
175  Result(Result&& other);
176 
177 public: // access
182  std::int32_t getErrorCode() const;
183 
188  const char* getErrorLabel() const;
189 
194  const char* getDescription() const;
195 
200  std::int32_t getLine() const;
201 
206  const char* getFile() const;
207 
212  const char* getFunction() const;
213 
218  explicit operator bool() const noexcept;
219 
225  friend void swap(Result& lhs, Result& rhs);
226 
233  friend bool operator==(const Result& lhs, const Result& rhs);
234 
235 private: // private constructor
245  explicit Result(std::int32_t error_code,
246  const char* error_description,
247  std::int32_t line,
248  const char* file,
249  const char* function,
250  const char* label);
251 
261  static Result createFrom(std::int32_t error_code,
262  const char* error_description,
263  std::int32_t line,
264  const char* file,
265  const char* function);
266 
267 private: // private member data
271 }; // class Result
272 
279 bool operator!=(const Result& lhs, const Result& rhs);
280 
288 template <typename T>
289 bool operator==(const Result& result, const ResultInfo<T>& error_code);
290 
298 template <typename T>
299 bool operator!=(const Result& result, const ResultInfo<T>& error_code);
300 
308 template <typename T>
309 bool operator==(const ResultInfo<T>& error_code, const Result& result);
310 
318 template <typename T>
319 bool operator!=(const ResultInfo<T>& error_code, const Result& result);
320 
327 template <>
328 DEV_ESSENTIAL_DEPRECATED("Please use the conversion Result::operator bool().")
329 bool isOk<Result>(const Result& result);
330 
331 } // namespace result
332 } // namespace a_util
333 
335 namespace std {
341 template <>
342 void swap<a_util::result::Result>(a_util::result::Result& lhs, a_util::result::Result& rhs);
343 } // namespace std
344 
348 #endif // A_UTIL_UTIL_RESULT_RESULT_TYPE_DECL_HEADER_INCLUDED
A common result class usable as return value throughout.
const char * getFunction() const
Get name of the function the error was reported in.
const char * getFile() const
Get name of the file the error was reported in.
Result & operator=(const ResultInfo< void > &)
Assign with a_util::result::SUCCESS.
std::int32_t getLine() const
Get line in source file where the error was reported.
Result()
Construct empty which basically means no error occurred.
friend bool operator==(const Result &lhs, const Result &rhs)
Comparison operator (shallow comparison)
const char * getDescription() const
Get user provided error description.
friend void swap(Result &lhs, Result &rhs)
Specialized friend swap function to enable ADL in std::swap later.
std::int32_t getErrorCode() const
Get error code.
detail::ResultDescription< detail::IErrorDescription > DescriptionType
Error description type.
const char * getErrorLabel() const
Get error label as string representation.
static Result createFrom(std::int32_t error_code, const char *error_description, std::int32_t line, const char *file, const char *function)
Create a detailed object of type Result on the heap from an error code.
DescriptionType _result_handle
The result handler wrapper.
#define DEV_ESSENTIAL_DEPRECATED(msg)
Adds [[deprecated("msg")]] to allowed declarations.
Definition: deprecated.h:28
bool operator==(const ResultInfo< ResultTypeLHS > &lhs, const ResultInfo< ResultTypeRHS > &rhs)
Compare two specialized result information objects for equality.
bool isOk(const ResultType &result)
Check whether a return value indicates a successful function execution.
bool operator!=(const ResultInfo< ResultTypeLHS > &lhs, const ResultInfo< ResultTypeRHS > &rhs)
Compare two specialized result information objects for inequality.
Serves as the root component, with common functionality documented in core functionality.
Definition: base.h:24
Private API for ResultDescription type and functions.
Common include for ResultInfo functionality.
Private implementation for Result type and functions.
Implements basic success result information for usage with a_util::result::Result.
Basic result information template, used by a_util::result::Result.