ADTF  3.18.2
result_description_decl.h
Go to the documentation of this file.
1 
16 #ifndef A_UTIL_UTIL_RESULT_DETAIL_DESCRIPTION_DECL_HEADER_INCLUDED
17 #define A_UTIL_UTIL_RESULT_DETAIL_DESCRIPTION_DECL_HEADER_INCLUDED
18 
21 
22 #include <cstdint>
23 
24 namespace a_util {
25 namespace result {
26 namespace detail {
31 template <typename DescriptionIntf /*e.g. a_util::result::detail::IErrorDescription*/>
36  static const std::uint64_t error_code_bit = 1ull << 63;
38  static const std::uint64_t error_code_bitmask = ~error_code_bit;
40  static const std::uint64_t error_code_serialize_bitmask = 0x00000000FFFFFFFF;
42  static const std::uint64_t error_code_deserialize_bitmask = 0xFFFFFFFF00000000;
43 
47  ResultDescriptionTraits& operator=(const ResultDescriptionTraits&) = delete;
49  ResultDescriptionTraits& operator=(ResultDescriptionTraits&&) = delete;
50 
57  static bool isDetailedDescriptionSet(std::uint64_t value);
58 
65  static bool isErrorCodeSet(std::uint64_t value);
66 
72  constexpr static std::uint64_t toInternalErrorCode(std::int32_t error_code) noexcept;
73 
79  constexpr static std::int32_t toExternalErrorCode(std::uint64_t error_code) noexcept;
80 
87  std::uint64_t error_code) noexcept;
88 
89 private:
92 }; // struct ResultDescriptionTraits
93 
95 
110 template <typename DescriptionIntf /*e.g. a_util::result::detail::IErrorDescription*/>
113 
114 public:
116 
117 public:
124  ResultDescription(const ResultDescription& other);
143 
146 
167  template <typename DescriptionImpl, typename... Args>
168  static SelfType makeResultDescription(std::int32_t error_code, Args&&... args);
169 
178  template <typename T>
180  const ::a_util::result::ResultInfo<T>& result_info) noexcept;
181 
187  static SelfType makeResultDescription(std::int32_t error_code);
188 
195  DescriptionIntf const* getDetailedDescription() const;
196 
203  std::int32_t getErrorCode() const;
204 
205 private:
206  // On all systems, a 64Bit variable for storage
207  // the most significant bits are used for user flags
208  // size of pointer part is system dependent, lower bits
209  std::uint64_t _pointer_to_result_or_error_code;
210 
215  constexpr ResultDescription(std::int32_t error_code) noexcept;
216 
222  constexpr ResultDescription(
223  const ReferenceCountedObjectInterface<DescriptionIntf>& error_object) noexcept;
224 }; // struct ResultDescription
225 
233 template <typename T>
234 bool operator==(const ResultDescription<T>& lhs, const ResultDescription<T>& rhs);
235 
243 template <typename T>
244 bool operator!=(const ResultDescription<T>& lhs, const ResultDescription<T>& rhs);
245 
246 } // namespace detail
247 } // namespace result
248 } // namespace a_util
249 
254 #endif // A_UTIL_UTIL_RESULT_DETAIL_DESCRIPTION_DECL_HEADER_INCLUDED
Wrapper for either a pointer to a detailed description object or simply a numeric error code.
ResultDescriptionTraits< DescriptionIntf > TraitsType
Traits type abbreviation.
ResultDescription & operator=(const ResultDescription &other)
Copy assignment operator.
std::int32_t getErrorCode() const
Get the error code if only the error code was set.
DescriptionIntf const * getDetailedDescription() const
Get the detailed description if any was allocated.
static SelfType makeResultDescription(std::int32_t error_code, Args &&... args)
Allocate an object being able to store detailed error information.
ResultDescription< DescriptionIntf > SelfType
Self type.
bool operator==(const ResultDescription< T > &lhs, const ResultDescription< T > &rhs)
Compare two result description objects for equality.
bool operator!=(const ResultDescription< T > &lhs, const ResultDescription< T > &rhs)
Compare two result description objects for inequality.
Serves as the root component, with common functionality documented in core functionality.
Definition: base.h:24
Private implementation for ResultDescription type and functions.
Public API for ResultInfo type, functions and macros.
Traits type for the result description.
ResultDescriptionTraits()=delete
Must not be constructed/copied/moved.
constexpr static const ReferenceCountedDescriptionType * toInternalErrorPointer(std::uint64_t error_code) noexcept
Get the internal error pointer representation from the internal error code representation.
ReferenceCountedObjectInterface< DescriptionIntf > ReferenceCountedDescriptionType
Reference counted error description type.
static bool isDetailedDescriptionSet(std::uint64_t value)
Check whether the detailed description was allocated.
static const std::uint64_t error_code_bit
The error code bit indicating whether only the error code (1) was set or not (0)
constexpr static std::int32_t toExternalErrorCode(std::uint64_t error_code) noexcept
Get the external error code from the internal error code representation.
static const std::uint64_t error_code_bitmask
The error code bitmask to mask out the error code bit.
~ResultDescriptionTraits()
To implement various static checks.
static const std::uint64_t error_code_deserialize_bitmask
The bitmask to deserialize the internal error representation to its original value.
constexpr static std::uint64_t toInternalErrorCode(std::int32_t error_code) noexcept
Get the internal error code representation from the external error code.
static const std::uint64_t error_code_serialize_bitmask
The bitmask to serialize the error code to its internal representation.
static bool isErrorCodeSet(std::uint64_t value)
Check whether only the error code was set.
Private API for ReferenceCountedObjectInterface type.