ADTF
Loading...
Searching...
No Matches
result_info_decl.h
Go to the documentation of this file.
1
14
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
30
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
57namespace a_util {
58namespace result {
66template <typename ResultType>
67DEV_ESSENTIAL_DEPRECATED("Usage of this function template is not type safe.")
68bool isOk(const ResultType& result);
69
77template <typename ResultType>
78DEV_ESSENTIAL_DEPRECATED("Usage of this function template is not type safe.")
79bool isFailed(const ResultType& result);
80
85template <typename T>
86struct ResultInfo {
91 static std::int32_t getCode();
96 static const char* getLabel();
97};
98
102template <>
103struct ResultInfo<void> {
108 static std::int32_t getCode();
113 static const char* getLabel();
114};
115
116namespace {
118const ResultInfo<void> SUCCESS = ResultInfo<void>();
119} // namespace
120
129template <typename ResultTypeLHS, typename ResultTypeRHS>
130bool operator==(const ResultInfo<ResultTypeLHS>& lhs, const ResultInfo<ResultTypeRHS>& rhs);
131
140template <typename ResultTypeLHS, typename ResultTypeRHS>
141bool operator!=(const ResultInfo<ResultTypeLHS>& lhs, const ResultInfo<ResultTypeRHS>& rhs);
142
151template <typename ResultTypeLHS, typename ResultTypeRHS>
152bool operator<(const ResultInfo<ResultTypeLHS>& lhs, const ResultInfo<ResultTypeRHS>& rhs);
153
162template <typename ResultTypeLHS, typename ResultTypeRHS>
163bool operator>(const ResultInfo<ResultTypeLHS>& lhs, const ResultInfo<ResultTypeRHS>& rhs);
164
173template <typename ResultTypeLHS, typename ResultTypeRHS>
174bool operator<=(const ResultInfo<ResultTypeLHS>& lhs, const ResultInfo<ResultTypeRHS>& rhs);
175
184template <typename ResultTypeLHS, typename ResultTypeRHS>
185bool 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
#define DEV_ESSENTIAL_DEPRECATED(msg)
Definition deprecated.h:44
bool operator!=(const ResultInfo< ResultTypeLHS > &lhs, const ResultInfo< ResultTypeRHS > &rhs)
Definition result_info_impl.h:66
bool operator>(const ResultInfo< ResultTypeLHS > &lhs, const ResultInfo< ResultTypeRHS > &rhs)
Definition result_info_impl.h:78
bool operator>=(const ResultInfo< ResultTypeLHS > &lhs, const ResultInfo< ResultTypeRHS > &rhs)
Definition result_info_impl.h:90
bool operator==(const ResultInfo< ResultTypeLHS > &lhs, const ResultInfo< ResultTypeRHS > &rhs)
Definition result_info_impl.h:58
bool isOk(const ResultType &result)
Definition result_info_impl.h:24
bool operator<=(const ResultInfo< ResultTypeLHS > &lhs, const ResultInfo< ResultTypeRHS > &rhs)
Definition result_info_impl.h:84
bool operator<(const ResultInfo< ResultTypeLHS > &lhs, const ResultInfo< ResultTypeRHS > &rhs)
Definition result_info_impl.h:72
bool isFailed(const ResultType &result)
Definition result_info_impl.h:30
Serves as the root component, with common functionality documented in core functionality.
Definition base.h:24
Definition result_info_decl.h:86
static std::int32_t getCode()
Definition result_info_impl.h:42
static const char * getLabel()
Definition result_info_impl.h:36