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 {
77template<
typename TMapped>
105template<
typename TElement>
240template<
typename TBoxable,
typename TEnableIf=
void>
271 DOX_MARKER([DOX_ALIB_BOXING_T_BOXER_WRITE])
274 target.Write( value );
276 DOX_MARKER([DOX_ALIB_BOXING_T_BOXER_WRITE])
301 ATMP_IF_T_F( !std::is_abstract<TBoxable>::value, TBoxable, TBoxable& )
304DOX_MARKER([DOX_ALIB_BOXING_T_BOXER_READ])
305return src.Read<TBoxable>();
306DOX_MARKER([DOX_ALIB_BOXING_T_BOXER_READ])
312#if !defined(ALIB_DOX)
316template<
typename TBoxable>
struct T_Boxer<TBoxable,
319 using Mapping= TMappedTo<detail::TDefaultBoxing>;
320 static void Write( Placeholder& target, TBoxable& value );
321 static void Read (
const Placeholder& src);
325template<>
struct T_Boxer<void>
327 using Mapping= TMappedTo<detail::TDefaultBoxing>;
328 static void Write( Placeholder& target,
const void* value );
329 static void*
Read (
const Placeholder& src);
370 static constexpr unsigned int value=
sizeof(TMappedPlain);
373#if !defined(ALIB_DOX)
389template<
typename T,
typename TEnableIf=
void>
struct TT_IsCustomized : std::true_type {};
391#if !defined(ALIB_DOX)
401 )> : std::false_type {};
405 )> : std::false_type {};
433template<
typename T,
typename TEnableIf=
void>
struct TT_IsLocked : std::false_type {};
435#if !defined(ALIB_DOX)
439 > : std::true_type {};
461template<
typename T,
typename TEnableIf=
void>
struct TT_IsNotBoxable : std::false_type {};
463#if !defined(ALIB_DOX)
467 ATMP_EQ(detail::TNotBoxable, typename T_Boxer<T>::Mapping::Type)
468|| ( !TT_IsCustomized<T>::value
469 && ( ( !ATMP_IS_PTR(T)
470 && ATMP_EQ(detail::TNotBoxable , typename T_Boxer< T*>::Mapping::Type) )
472 && ATMP_EQ(detail::TNotBoxable , typename T_Boxer<ATMP_RP(T)>::Mapping::Type) )
475 >::type> : std::true_type {};
501template<
typename T,
typename TEnableIf=
void>
504#if !defined(ALIB_DOX)
510 !TT_IsCustomized<ATMP_RP(T) >::value
511&& !TT_IsCustomized<ATMP_RP(T)*>::value
512&& static_cast<bool>( ATMP_IS_PTR(T) )
513 == static_cast<bool>( ( sizeof(Placeholder) < sizeof(ATMP_RCVP(T)) )
514 || !std::is_copy_constructible <ATMP_RCVP(T)>::value
515 || !std::is_trivially_destructible<ATMP_RCVP(T)>::value )
517 >::type> : std::true_type {};
522struct TT_IsUnboxable<T, typename std::enable_if<
523 TT_IsCustomized<T>::value
524&& !TT_IsLocked <T>::value
525&& !TT_IsNotBoxable<T>::value
526 >::type> : std::true_type {};
537#define ALIB_BOXING_CUSTOMIZE(TSource, TTarget, ...) \
538namespace alib::boxing { \
539template<> struct T_Boxer<TSource> \
541 using Mapping= TMappedTo<TTarget>; \
545#define ALIB_BOXING_CUSTOMIZE_ARRAY_TYPE(TSource, TElement, ...) \
546namespace alib::boxing { \
547template<> struct T_Boxer<TSource> \
549 using Mapping= TMappedToArrayOf<TElement>; \
553#define ALIB_BOXING_CUSTOMIZE_TYPE_MAPPING(TSource, TTarget) \
554namespace alib::boxing { \
555template<> struct T_Boxer<TSource> \
556{ using Mapping= TMappedTo<TTarget>; \
557 static void Write( Placeholder& target, TSource const & value ) { target.Write( static_cast<TTarget>( value ) ); } \
558 static TSource Read (const Placeholder& src) { return static_cast<TSource>(src.Read<TTarget>()); } \
561#define ALIB_BOXING_CUSTOMIZE_TYPE_MAPPING_CONSTEXPR(TSource, TTarget) \
562namespace alib::boxing { \
563template<> struct T_Boxer<TSource> \
564{ using Mapping= TMappedTo<TTarget>; \
565 static constexpr Placeholder Write( TSource const & value ) { return Placeholder( static_cast<TTarget>( value ) );} \
566 static TSource Read (const Placeholder& src) { return static_cast<TSource>(src.Read<TTarget>() );} \
570#define ALIB_BOXING_CUSTOMIZE_NOT_UNBOXABLE(TSource, TTarget) \
571namespace alib::boxing { \
572template<> struct T_Boxer<TSource> \
573{ using Mapping= TMappedTo<TTarget>; \
574 static void Write( Placeholder& target, TSource const & value ) { target.Write( static_cast<typename Mapping::Type>( value ) ); } \
575 static void Read( const Placeholder& src); \
578#define ALIB_BOXING_CUSTOMIZE_NOT_UNBOXABLE_CONSTEXPR(TSource, TTarget) \
579namespace alib::boxing { \
580template<> struct T_Boxer<TSource> \
581{ using Mapping= TMappedTo<TTarget>; \
582 static constexpr Placeholder Write( TSource const & value ) { return Placeholder( static_cast<typename Mapping::Type>( value ) ); } \
583 static void Read( const Placeholder& src); \
587#define ALIB_BOXING_CUSTOMIZE_ARRAY_TYPE_NON_UNBOXABLE(TSource, TElement, ...) \
588namespace alib::boxing { \
589template<> struct T_Boxer<TSource> \
590{ using Mapping= TMappedToArrayOf<TElement>; \
592 static void Read( const Placeholder& src); \
596#define ALIB_BOXING_CUSTOMIZE_DENY_BOXING(TSource) \
597namespace alib::boxing { \
598template<> struct T_Boxer<TSource> \
599{ using Mapping= TMappedTo<detail::TNotBoxable>; \
600 static void Write( Placeholder& target, TSource const & value ); \
601 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
static Read(const Placeholder &src)
static void Write(Placeholder &target, const TBoxable &value)
TMappedTo< detail::TDefaultBoxing > Mapping
static constexpr unsigned int value