ADTF  3.18.2
result_info_decl.h
Go to the documentation of this file.
1 
15 #ifndef A_UTIL_UTIL_RESULT_RESULT_INFO_DECL_HEADER_INCLUDED
16 #define A_UTIL_UTIL_RESULT_RESULT_INFO_DECL_HEADER_INCLUDED
17 
19 
20 #include <cstdint>
21 #include <limits>
22 
24 #ifndef DEV_ESSENTIAL_DISABLE_MAKE_RESULT_CHECK_RESERVED_ZERO
25 #define DEV_ESSENTIAL_INTERNAL_MAKE_RESULT_CHECK_NOT_ZERO(_no) _no != 0
26 #else
27 #define DEV_ESSENTIAL_INTERNAL_MAKE_RESULT_CHECK_NOT_ZERO(...) true
28 #endif // DEV_ESSENTIAL_DISABLE_MAKE_RESULT_CHECK_RESERVED_ZERO
36 #define _MAKE_RESULT(_no, _label) \
37  namespace { \
38  struct ResultType_##_label : public ::a_util::result::ResultInfo<ResultType_##_label> { \
39  static std::int32_t getCode() \
40  { \
41  static_assert(std::is_same<decltype((_no)), std::int32_t>::value, \
42  #_no " is not in range of std::int32_t."); \
43  return _no; \
44  } \
45  static const char* getLabel() \
46  { \
47  return #_label; \
48  } \
49  }; \
50  const ::a_util::result::ResultInfo<ResultType_##_label> _label = ResultType_##_label(); \
51  } /* ns anonymous */ \
52  static_assert(DEV_ESSENTIAL_INTERNAL_MAKE_RESULT_CHECK_NOT_ZERO(_no), \
53  "'0' is not allowed, because it is reserved for results indicating no error. " \
54  "Please use a_util::result::SUCCESS instead. To disable this check, define " \
55  "'DEV_ESSENTIAL_DISABLE_MAKE_RESULT_CHECK_RESERVED_ZERO'")
56 
57 namespace a_util {
58 namespace result {
66 template <typename ResultType>
67 DEV_ESSENTIAL_DEPRECATED("Usage of this function template is not type safe.")
68 bool isOk(const ResultType& result);
69 
77 template <typename ResultType>
78 DEV_ESSENTIAL_DEPRECATED("Usage of this function template is not type safe.")
79 bool isFailed(const ResultType& result);
80 
85 template <typename T>
86 struct ResultInfo {
91  static std::int32_t getCode();
96  static const char* getLabel();
97 };
98 
102 template <>
103 struct ResultInfo<void> {
108  static std::int32_t getCode();
113  static const char* getLabel();
114 };
115 
116 namespace {
118 const ResultInfo<void> SUCCESS = ResultInfo<void>();
119 } // namespace
120 
129 template <typename ResultTypeLHS, typename ResultTypeRHS>
130 bool operator==(const ResultInfo<ResultTypeLHS>& lhs, const ResultInfo<ResultTypeRHS>& rhs);
131 
140 template <typename ResultTypeLHS, typename ResultTypeRHS>
141 bool operator!=(const ResultInfo<ResultTypeLHS>& lhs, const ResultInfo<ResultTypeRHS>& rhs);
142 
151 template <typename ResultTypeLHS, typename ResultTypeRHS>
152 bool operator<(const ResultInfo<ResultTypeLHS>& lhs, const ResultInfo<ResultTypeRHS>& rhs);
153 
162 template <typename ResultTypeLHS, typename ResultTypeRHS>
163 bool operator>(const ResultInfo<ResultTypeLHS>& lhs, const ResultInfo<ResultTypeRHS>& rhs);
164 
173 template <typename ResultTypeLHS, typename ResultTypeRHS>
174 bool operator<=(const ResultInfo<ResultTypeLHS>& lhs, const ResultInfo<ResultTypeRHS>& rhs);
175 
184 template <typename ResultTypeLHS, typename ResultTypeRHS>
185 bool operator>=(const ResultInfo<ResultTypeLHS>& lhs, const ResultInfo<ResultTypeRHS>& rhs);
186 
187 } // namespace result
188 } // namespace a_util
189 
193 #endif // A_UTIL_UTIL_RESULT_RESULT_INFO_DECL_HEADER_INCLUDED
Definition of preprocessor macro DEV_ESSENTIAL_DEPRECATED.
#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)
Greater-than operator for two specialized result information objects.
bool operator<=(const ResultInfo< ResultTypeLHS > &lhs, const ResultInfo< ResultTypeRHS > &rhs)
Less-than-or-equal operator for two specialized result information objects.
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 isFailed(const ResultType &result)
Check whether a return value indicates an unsuccessful function execution.
bool operator<(const ResultInfo< ResultTypeLHS > &lhs, const ResultInfo< ResultTypeRHS > &rhs)
Less-than operator for two specialized result information objects.
bool operator!=(const ResultInfo< ResultTypeLHS > &lhs, const ResultInfo< ResultTypeRHS > &rhs)
Compare two specialized result information objects for inequality.
bool operator>=(const ResultInfo< ResultTypeLHS > &lhs, const ResultInfo< ResultTypeRHS > &rhs)
Greater-than-or-equal operator for two specialized result information objects.
Serves as the root component, with common functionality documented in core functionality.
Definition: base.h:24
Private implementation for ResultInfo 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.
static std::int32_t getCode()
Get the result code distributed with value of type T.
static const char * getLabel()
Get the string representation of an error code distributed by value of type T.