51 static_assert(IsTriviallyCopyable<T>::value,
"T must be trivially copiable");
52 static_assert(IsTriviallyDefaultConstructible<T>::value,
"T must be trivially default-constructible");
55 assert(
reinterpret_cast<std::uintptr_t
>(storage) %
alignof(T) == 0);
57#if defined(ONIXS_CMEMDH_HAS_START_LIFETIME_AS)
58 return std::start_lifetime_as<T>(storage);
60 return static_cast<T*
>(storage);
68 static_assert(IsTriviallyCopyable<T>::value,
"T must be trivially copiable");
69 static_assert(IsTriviallyDefaultConstructible<T>::value,
"T must be trivially default-constructible");
72 assert(
reinterpret_cast<std::uintptr_t
>(storage) %
alignof(T) == 0);
74 return ::new (storage) T;
79template <
typename Type>
83 return static_cast<void*
>(ptr);
88template <
typename Type>
92 return static_cast<const void*
>(ptr);
96template <
typename Type>
100 return const_cast<void*
>(
static_cast<const void*
>(ptr));
104template <
typename Type>
108 return const_cast<Type*
>(ptr);
113template <
typename Type>
118 return static_cast<Byte*
>(toOpaquePtr(ptr));
123template <
typename Type>
128 return static_cast<const Byte*
>(toOpaquePtr(ptr));
133template <
typename Type>
138 return reinterpret_cast<Type*
>(toByteBlock(pointer) + distance);
143template <
typename Type>
148 return reinterpret_cast<const Type*
>(toByteBlock(pointer) + distance);
154template <
typename Type>
159 return reinterpret_cast<Type*
>(toByteBlock(pointer) - distance);
164template <
typename Left,
typename Right>
170 return (toByteBlock(left) - toByteBlock(right));
174template <
class Value>
183 std::memcpy(&result, location,
sizeof(Value));
189template <
unsigned ArgsCount>
190struct CompositeExtractor;
194struct CompositeExtractor<1>
196 template <
class Value>
198 static Value extract(
const void* location)
noexcept
200 static_assert(
noexcept(Value(std::declval<typename Value::MemberTraits::FirstArgType>())),
"must be noexcept");
204 return Value(extractValue<typename Value::MemberTraits::FirstArgType>(location));
210struct CompositeExtractor<2>
212 template <
class Value>
214 static Value extract(
const void* location)
noexcept
216 typedef typename Value::MemberTraits::FirstArgType FirstArgType;
217 typedef typename Value::MemberTraits::SecondArgType SecondArgType;
219 static_assert(
noexcept(Value(std::declval<FirstArgType>(), std::declval<SecondArgType>())),
"must be noexcept");
224 extractValue<FirstArgType>(location),
225 extractValue<SecondArgType>(advanceByBytes(location,
sizeof(FirstArgType)))
232struct CompositeExtractor<4>
234 template <
class Value>
236 static Value extract(
const void* location)
noexcept
238 typedef typename Value::MemberTraits::FirstArgType FirstArgType;
239 typedef typename Value::MemberTraits::SecondArgType SecondArgType;
240 typedef typename Value::MemberTraits::ThirdArgType ThirdArgType;
241 typedef typename Value::MemberTraits::FourthArgType FourthArgType;
245 std::declval<FirstArgType>(),
246 std::declval<SecondArgType>(),
247 std::declval<ThirdArgType>(),
248 std::declval<FourthArgType>()
256 extractValue<FirstArgType>(location),
257 extractValue<SecondArgType>(advanceByBytes(location,
sizeof(FirstArgType))),
258 extractValue<ThirdArgType>(advanceByBytes(location,
sizeof(FirstArgType) +
sizeof(SecondArgType))),
259 extractValue<FourthArgType>(
260 advanceByBytes(location,
sizeof(FirstArgType) +
sizeof(SecondArgType) +
sizeof(ThirdArgType))
267template <
class Value>
269getValue(
const void* location)
noexcept
272 return CompositeExtractor<Value::MemberTraits::Count>::template extract<Value>(location);
276template <
class Value>
278getValue(
const void* location)
noexcept
281 return extractValue<Value>(location);
285template <
class Value>
287constexpr typename std::enable_if<!details::HasMemberTraits<Value>::value,
size_t>::type size() noexcept
289 return sizeof(Value);
293template <
class Value>
295constexpr typename std::enable_if<details::HasMemberTraits<Value>::value,
size_t>::type size() noexcept
301template <
class Value>
303commitValue(
void* location, Value value)
noexcept
306 std::memcpy(location, &value,
sizeof(Value));
310template <
class Value>
312commitValue(
void* location, Value value)
noexcept
315 value.serialize(location);
319template <
class Value>
321setValue(
void* location, Value value)
noexcept
324 commitValue(location, value);
328template <
class Value>
330setValue(
void* location, Value)
noexcept
333 commitValue(location, Value::value());
#define ONIXS_CMEMDH_MESSAGING_NAMESPACE_BEGIN
#define ONIXS_CMEMDH_MESSAGING_NAMESPACE_END
#define ONIXS_CMEMDH_FORCEINLINE
#define ONIXS_CMEMDH_CHECK_TYPE_INTEGRAL(Type)
bool value(Number &number, const MultiContainer &container, Tag tag)
UInt16 Word
Alias for Word.
UInt64 QWord
Alias for Quad Word.
std::uint32_t UInt32
uInt32.
std::uint16_t UInt16
uInt16.
UInt32 DWord
Alias for Double Word.
std::uint64_t UInt64
uInt64.
UInt8 Byte
Alias for Byte.