8#ifndef HPP_ALIB_BOXING_TYPETRAITS
9#define HPP_ALIB_BOXING_TYPETRAITS 1
11#if !defined(HPP_ALIB_BOXING_BOXING)
12# error "ALib sources with ending '.inl' must not be included from outside."
15namespace alib {
namespace boxing {
66template<
typename TMapped>
88template<
typename TElement>
219template<
typename TBoxable,
typename TEnableIf=
void>
246 DOX_MARKER([DOX_BOXING_T_BOXER_WRITE])
249 target.Write( value );
251 DOX_MARKER([DOX_BOXING_T_BOXER_WRITE])
274 ATMP_IF_T_F( !std::is_abstract<TBoxable>::value, TBoxable, TBoxable& )
277DOX_MARKER([DOX_BOXING_T_BOXER_READ])
278return src.Read<TBoxable>();
279DOX_MARKER([DOX_BOXING_T_BOXER_READ])
289template<
typename TBoxable>
struct T_Boxer<TBoxable,
292 using Mapping= TMappedTo<detail::TDefaultBoxing>;
293 static void Write( Placeholder& target, TBoxable& value );
294 static void Read (
const Placeholder& src);
298template<>
struct T_Boxer<void>
300 using Mapping= TMappedTo<detail::TDefaultBoxing>;
301 static void Write( Placeholder& target,
const void* value );
302 static void*
Read (
const Placeholder& src);
343 static constexpr unsigned int value=
sizeof(TMappedPlain);
362template<
typename T,
typename TEnableIf=
void>
struct TT_IsCustomized : std::true_type {};
374 )> : std::false_type {};
378 )> : std::false_type {};
406template<
typename T,
typename TEnableIf=
void>
struct TT_IsLocked : std::false_type {};
412 > : std::true_type {};
434template<
typename T,
typename TEnableIf=
void>
struct TT_IsNotBoxable : std::false_type {};
440 ATMP_EQ(detail::TNotBoxable, typename T_Boxer<T>::Mapping::Type)
441|| ( !TT_IsCustomized<T>::value
442 && ( ( !ATMP_IS_PTR(T)
443 && ATMP_EQ(detail::TNotBoxable , typename T_Boxer< T*>::Mapping::Type) )
445 && ATMP_EQ(detail::TNotBoxable , typename T_Boxer<ATMP_RP(T)>::Mapping::Type) )
448 >::type> : std::true_type {};
474template<
typename T,
typename TEnableIf=
void>
483 !TT_IsCustomized<ATMP_RP(T) >::value
484&& !TT_IsCustomized<ATMP_RP(T)*>::value
485&& static_cast<bool>( ATMP_IS_PTR(T) )
486 == static_cast<bool>( ( sizeof(Placeholder) < sizeof(ATMP_RCVP(T)) )
487 || !std::is_copy_constructible <ATMP_RCVP(T)>::value
488 || !std::is_trivially_destructible<ATMP_RCVP(T)>::value )
490 >::type> : std::true_type {};
495struct TT_IsUnboxable<T, typename std::enable_if<
496 TT_IsCustomized<T>::value
497&& !TT_IsLocked <T>::value
498&& !TT_IsNotBoxable<T>::value
499 >::type> : std::true_type {};
510#define ALIB_BOXING_CUSTOMIZE(TSource, TTarget, ...) \
511namespace alib::boxing { \
512template<> struct T_Boxer<TSource> \
514 using Mapping= TMappedTo<TTarget>; \
518#define ALIB_BOXING_CUSTOMIZE_ARRAY_TYPE(TSource, TElement, ...) \
519namespace alib::boxing { \
520template<> struct T_Boxer<TSource> \
522 using Mapping= TMappedToArrayOf<TElement>; \
526#define ALIB_BOXING_CUSTOMIZE_TYPE_MAPPING(TSource, TTarget) \
527namespace alib::boxing { \
528template<> struct T_Boxer<TSource> \
529{ using Mapping= TMappedTo<TTarget>; \
530 static void Write( Placeholder& target, TSource const & value ) { target.Write( static_cast<TTarget>( value ) ); } \
531 static TSource Read (const Placeholder& src) { return static_cast<TSource>(src.Read<TTarget>()); } \
534#define ALIB_BOXING_CUSTOMIZE_TYPE_MAPPING_CONSTEXPR(TSource, TTarget) \
535namespace alib::boxing { \
536template<> struct T_Boxer<TSource> \
537{ using Mapping= TMappedTo<TTarget>; \
538 static constexpr Placeholder Write( TSource const & value ) { return Placeholder( static_cast<TTarget>( value ) );} \
539 static TSource Read (const Placeholder& src) { return static_cast<TSource>(src.Read<TTarget>() );} \
543#define ALIB_BOXING_CUSTOMIZE_NOT_UNBOXABLE(TSource, TTarget) \
544namespace alib::boxing { \
545template<> struct T_Boxer<TSource> \
546{ using Mapping= TMappedTo<TTarget>; \
547 static void Write( Placeholder& target, TSource const & value ) { target.Write( static_cast<typename Mapping::Type>( value ) ); } \
548 static void Read( const Placeholder& src); \
551#define ALIB_BOXING_CUSTOMIZE_NOT_UNBOXABLE_CONSTEXPR(TSource, TTarget) \
552namespace alib::boxing { \
553template<> struct T_Boxer<TSource> \
554{ using Mapping= TMappedTo<TTarget>; \
555 static constexpr Placeholder Write( TSource const & value ) { return Placeholder( static_cast<typename Mapping::Type>( value ) ); } \
556 static void Read( const Placeholder& src); \
560#define ALIB_BOXING_CUSTOMIZE_ARRAY_TYPE_NON_UNBOXABLE(TSource, TElement, ...) \
561namespace alib::boxing { \
562template<> struct T_Boxer<TSource> \
563{ using Mapping= TMappedToArrayOf<TElement>; \
565 static void Read( const Placeholder& src); \
569#define ALIB_BOXING_CUSTOMIZE_DENY_BOXING(TSource) \
570namespace alib::boxing { \
571template<> struct T_Boxer<TSource> \
572{ using Mapping= TMappedTo<detail::TNotBoxable>; \
573 static void Write( Placeholder& target, TSource const & value ); \
574 static void Read ( const Placeholder& src); \
#define ATMP_IF_T_F( Cond, T, F)
#define ATMP_VOID_IF(Cond)
#define ATMP_EQ( T, TEqual)
#define ALIB_SIZEOF_LONGDOUBLE_WRITTEN
TElement Type
The element type given as TElement.
TMapped Type
The given type TMapped.
static Read(const Placeholder &src)
static void Write(Placeholder &target, const TBoxable &value)
TMappedTo< detail::TDefaultBoxing > Mapping
static constexpr unsigned int value
The size used with the placeholder.