16#ifndef A_UTIL_UTIL_RESULT_DETAIL_DESCRIPTION_IMPL_HEADER_INCLUDED
17#define A_UTIL_UTIL_RESULT_DETAIL_DESCRIPTION_IMPL_HEADER_INCLUDED
31template <
typename DescriptionIntf>
33 const std::uint64_t value)
40template <
typename DescriptionIntf>
47template <
typename DescriptionIntf>
49 const std::int32_t error_code)
noexcept
59template <
typename DescriptionIntf>
61 const std::uint64_t error_code)
noexcept
63 return static_cast<std::int32_t
>(
70template <
typename DescriptionIntf>
77template <
typename DescriptionIntf>
78inline ResultDescriptionTraits<DescriptionIntf>::~ResultDescriptionTraits()
83 constexpr auto minus_one_representation = toInternalErrorCode(-1);
84 constexpr auto plus_one_representation = toInternalErrorCode(1);
86#if defined(__GNUC__) && ((__GNUC__ == 5) && (__GNUC_MINOR__ == 2))
87#pragma GCC diagnostic push
88#pragma GCC diagnostic ignored "-Wattributes"
90 constexpr auto min_val_representation =
91 toInternalErrorCode((numeric_limits<std::int32_t>::min)());
92 constexpr auto max_val_representation =
93 toInternalErrorCode((numeric_limits<std::int32_t>::max)());
94#if defined(__GNUC__) && ((__GNUC__ == 5) && (__GNUC_MINOR__ == 2))
95#pragma GCC diagnostic pop
101 static_assert(0x8000000000000000 == error_code_bit,
"error_code_bit must not be changed!");
102 static_assert(~0x8000000000000000 == error_code_bitmask,
103 "error_code_bitmask must not be changed!");
104 static_assert(0xFFFFFFFF00000000 == error_code_deserialize_bitmask,
105 "error_code_deserialize_bitmask must not be changed!");
106 static_assert(0xFFFFFFFF == error_code_serialize_bitmask,
107 "error_code_serialize_bitmask must not be changed!");
108 static_assert(0x80000000ffffffff == minus_one_representation,
109 "Calculation of internal error code representation must not be changed!");
110 static_assert(0x8000000000000001 == plus_one_representation,
111 "Calculation of internal error code representation must not be changed!");
112 static_assert(0x8000000080000000 == min_val_representation,
113 "Calculation of internal error code representation must not be changed!");
114 static_assert(0x800000007fffffff == max_val_representation,
115 "Calculation of internal error code representation must not be changed!");
118template <
typename DescriptionIntf>
123template <
typename DescriptionIntf>
125 : _pointer_to_result_or_error_code{}
130template <
typename DescriptionIntf>
134 if (&other !=
this) {
139 _pointer_to_result_or_error_code = other._pointer_to_result_or_error_code;
140 if (TraitsType::isDetailedDescriptionSet(_pointer_to_result_or_error_code)) {
141 TraitsType::toInternalErrorPointer(_pointer_to_result_or_error_code)->addReference();
147template <
typename DescriptionIntf>
149 : _pointer_to_result_or_error_code{}
151 std::swap(other._pointer_to_result_or_error_code, _pointer_to_result_or_error_code);
154template <
typename DescriptionIntf>
158 if (&other !=
this) {
163 _pointer_to_result_or_error_code = {};
164 std::swap(other._pointer_to_result_or_error_code, _pointer_to_result_or_error_code);
169template <
typename DescriptionIntf>
176 static_assert(
sizeof(std::uintptr_t) <= 8,
177 "ResultDescription pointers must always have a size of 8 Byte or less!");
180template <
typename DescriptionIntf>
181template <
typename DescriptionImpl,
typename... Args>
189 const auto reference_counted_error_object =
190 new ReferenceCountedErrorType(error_code, std::forward<Args>(args)...);
191 SelfType result_description(*reference_counted_error_object);
194 reference_counted_error_object->removeReference();
195 assert((
false) &&
"The MSB of the pointer to the heap allocated memory is set to 1, "
196 "but it is reserved for the error code bit. This is inplausible and "
200 return result_description;
203 catch (
const std::bad_alloc&) {
207 return SelfType::makeResultDescription(error_code);
210template <
typename DescriptionIntf>
216 SelfType result_description(uncounted_error);
221 return result_description;
227template <
typename DescriptionIntf>
229 std::int32_t error_code)
236template <
typename DescriptionIntf>
246template <
typename DescriptionIntf>
256template <
typename DescriptionIntf>
258 std::int32_t error_code) noexcept
259 : _pointer_to_result_or_error_code(TraitsType::toInternalErrorCode(error_code))
263template <
typename DescriptionIntf>
265 const ReferenceCountedObjectInterface<DescriptionIntf>& error_object) noexcept
266 : _pointer_to_result_or_error_code(
reinterpret_cast<std::uintptr_t
>(&error_object))
268 static_assert(
sizeof(std::uintptr_t) ==
sizeof(
decltype(&error_object)),
269 "ResultDescription pointers must match the size of std::uintptr_t!");
270 assert((!TraitsType::isErrorCodeSet(_pointer_to_result_or_error_code)) &&
271 "The cast of the pointer to the internal error code set the MSB to 1, but it is "
272 "reserved for the error code bit. This is inplausible and must not happen.");
273 error_object.addReference();
289 return !(lhs == rhs);
Definition reference_counted_object_intf.h:29
Default implementation of a reference counter.
Definition reference_counted_object.h:33
Wrapper for either a pointer to a detailed description object or simply a numeric error code.
Definition result_description_decl.h:111
std::int32_t getErrorCode() const
Definition result_description_impl.h:247
ResultDescription & operator=(const ResultDescription &other)
Definition result_description_impl.h:131
static SelfType makeResultDescription(std::int32_t error_code, Args &&... args)
Definition result_description_impl.h:183
ResultDescription()
CTOR.
Definition result_description_impl.h:119
~ResultDescription()
DTOR.
Definition result_description_impl.h:170
DescriptionIntf const * getDetailedDescription() const
Definition result_description_impl.h:237
ResultDescription< DescriptionIntf > SelfType
Self type.
Definition result_description_decl.h:115
Default implementation of a non-counting reference counter.
Definition reference_counted_object.h:104
Serves as namespace for result implementation details.
Definition result.h:22
bool operator==(const ResultDescription< T > &lhs, const ResultDescription< T > &rhs)
Definition result_description_impl.h:277
bool operator!=(const ResultDescription< T > &lhs, const ResultDescription< T > &rhs)
Definition result_description_impl.h:287
Serves as component for functionality handling error and return types.
Definition result.h:20
Serves as the root component, with common functionality documented in core functionality.
Definition base.h:24
static std::int32_t getCode()
Definition result_info_impl.h:42
Definition result_description_decl.h:32
static bool isDetailedDescriptionSet(std::uint64_t value)
Definition result_description_impl.h:32
static const std::uint64_t error_code_bit
The error code bit indicating whether only the error code (1) was set or not (0)
Definition result_description_decl.h:36
static constexpr std::uint64_t toInternalErrorCode(std::int32_t error_code) noexcept
Definition result_description_impl.h:48
static const std::uint64_t error_code_bitmask
The error code bitmask to mask out the error code bit.
Definition result_description_decl.h:38
static constexpr const ReferenceCountedDescriptionType * toInternalErrorPointer(std::uint64_t error_code) noexcept
Definition result_description_impl.h:72
ReferenceCountedObjectInterface< DescriptionIntf > ReferenceCountedDescriptionType
Reference counted error description type.
Definition result_description_decl.h:34
static constexpr std::int32_t toExternalErrorCode(std::uint64_t error_code) noexcept
Definition result_description_impl.h:60
static const std::uint64_t error_code_serialize_bitmask
The bitmask to serialize the error code to its internal representation.
Definition result_description_decl.h:40
static const std::uint64_t error_code_deserialize_bitmask
The bitmask to deserialize the internal error representation to its original value.
Definition result_description_decl.h:42
static bool isErrorCodeSet(std::uint64_t value)
Definition result_description_impl.h:41