ALib C++ Library
Library Version: 2511 R0
Documentation generated by doxygen
Loading...
Searching...
No Matches
boxing.prepro.hpp
Go to the documentation of this file.
1//==================================================================================================
2/// \file
3/// This header-file is part of the \aliblong.
4///
5/// \emoji :copyright: 2013-2025 A-Worx GmbH, Germany.
6/// Published under \ref mainpage_license "Boost Software License".
7//==================================================================================================
8#ifndef HPP_ALIB_BOXING_PP
9#define HPP_ALIB_BOXING_PP
10#pragma once
11#ifndef INL_ALIB
12# include "alib/alib.inl"
13#endif
14
15//##################################################################################################
16// Symbols/macros introduced by module ALib.Boxing
17//##################################################################################################
18#if !defined(ALIB_FEAT_BOXING_BIJECTIVE_INTEGRALS)
19# define ALIB_FEAT_BOXING_BIJECTIVE_INTEGRALS 0
20#endif
21
22#if !defined(ALIB_FEAT_BOXING_BIJECTIVE_CHARACTERS)
23# define ALIB_FEAT_BOXING_BIJECTIVE_CHARACTERS 0
24#endif
25
26#if !defined(ALIB_FEAT_BOXING_BIJECTIVE_FLOATS)
27# define ALIB_FEAT_BOXING_BIJECTIVE_FLOATS 0
28#endif
29
30#if !ALIB_BOXING
31# define ALIB_DEBUG_BOXING 0
32#else
33# if !defined(ALIB_DEBUG_BOXING)
34# define ALIB_DEBUG_BOXING 0
35# elif !ALIB_DEBUG && ALIB_DEBUG_BOXING
36# undef ALIB_DEBUG_BOXING
37# define ALIB_DEBUG_BOXING 0
38# pragma message "Symbol ALIB_DEBUG_BOXING set (from outside!) while ALIB_DEBUG is not. The symbol got disabled."
39# endif
40
41
42#define ALIB_BOXING_CUSTOMIZE(TSource, TMapped, ...) \
43namespace alib::boxing { \
44template<> struct BoxTraits<TSource> \
45{ \
46 using Mapping= TMapped; \
47 static constexpr bool IsArray= false; \
48 __VA_ARGS__ \
49}; } \
50
51#define ALIB_BOXING_CUSTOMIZE_ARRAY_TYPE(TSource, TElement, ...) \
52namespace alib::boxing { \
53template<> struct BoxTraits<TSource> \
54{ \
55 using Mapping= TElement; \
56 static constexpr bool IsArray= true; \
57 __VA_ARGS__ \
58}; }
59
60
61#define ALIB_BOXING_CUSTOMIZE_TYPE_MAPPING(TSource, TMapped) \
62namespace alib::boxing { \
63template<> struct BoxTraits<TSource> \
64{ using Mapping= TMapped; \
65 static constexpr bool IsArray= false; \
66 static constexpr void Write( Placeholder& box, TSource const & value ) { box.Write( static_cast<TMapped>( value ) ); } \
67 static constexpr TSource Read (const Placeholder& box) { return static_cast<TSource>(box.Read<TMapped>()); } \
68}; }
69
70
71#define ALIB_BOXING_CUSTOMIZE_NOT_UNBOXABLE(TSource, TMapped) \
72namespace alib::boxing { \
73template<> struct BoxTraits<TSource> \
74{ using Mapping= TMapped; \
75 static constexpr bool IsArray= false; \
76 static constexpr void Write( Placeholder& box, TSource const & value ) { box.Write( static_cast<TMapped>( value ) ); } \
77 static constexpr void Read( const Placeholder& box); \
78}; }
79
80
81#define ALIB_BOXING_CUSTOMIZE_ARRAY_TYPE_NON_UNBOXABLE(TSource, TElement, ...) \
82namespace alib::boxing { \
83template<> struct BoxTraits<TSource> \
84{ using Mapping= TElement; \
85 static constexpr bool IsArray= true; \
86 __VA_ARGS__ \
87 static constexpr void Read( const Placeholder& box); \
88}; }
89
90
91#define ALIB_BOXING_CUSTOMIZE_DENY_BOXING(TSource) \
92namespace alib::boxing { \
93template<> struct BoxTraits<TSource> \
94{ using Mapping= NotBoxableTag; \
95 static constexpr bool IsArray= false; \
96 static constexpr void Write( Placeholder& box, TSource const & value ); \
97 static constexpr void Read ( const Placeholder& box); \
98}; }
99
100
101#define ALIB_BOXING_VTABLE_DECLARE( TMapped, Identifier ) \
102ALIB_EXPORT namespace alib::boxing { namespace detail { \
103extern ALIB_DLL VTable SNGLTN_ ## Identifier; } \
104template<> struct VTableOptimizationTraits< TMapped, false > { \
105static constexpr detail::VTable* Get() { return &detail:: SNGLTN_ ## Identifier; } }; } \
106
107#define ALIB_BOXING_VTABLE_DECLARE_ARRAYTYPE( TMapped, Identifier ) \
108ALIB_EXPORT namespace alib::boxing { namespace detail { \
109extern ALIB_DLL VTable SNGLTN_ ## Identifier; } \
110template<> struct VTableOptimizationTraits< TMapped, true > { \
111static constexpr detail::VTable* Get() { return &detail:: SNGLTN_ ## Identifier;} }; } \
112
113#define ALIB_BOXING_VTABLE_DEFINE( TMapped, Identifier ) \
114alib::boxing::detail::VTable alib::boxing::detail::SNGLTN_ ## Identifier \
115( typeid(TMapped), typeid(void) , \
116 std::is_pointer<TMapped>::value \
117 ? VTable::MappingType::Pointer \
118 : std::is_enum<TMapped>::value \
119 ? VTable::MappingType::Enum \
120 : VTable::MappingType::Value , \
121 alib::boxing::SizeTraits<TMapped>); \
122
123#define ALIB_BOXING_VTABLE_DEFINE_ARRAYTYPE( TMapped, Identifier ) \
124alib::boxing::detail::VTable alib::boxing::detail::SNGLTN_ ## Identifier \
125(typeid(TMapped[1]) , typeid(TMapped), VTable::MappingType(sizeof(TMapped)), sizeof(Placeholder)); \
126
127
128#if ALIB_DEBUG_BOXING
129# define ALIB_BOXING_BOOTSTRAP_VTABLE_DBG_REGISTER( Identifier ) \
130alib::boxing::debug::DbgRegisterVTable( &alib::boxing::detail::SNGLTN_ ## Identifier, \
131 alib::boxing::detail::VTable::DbgFactoryType::Static );
132#else
133# define ALIB_BOXING_BOOTSTRAP_VTABLE_DBG_REGISTER( Identifier )
134#endif
135
136#define ALIB_BOXING_DEFINE_FEQUALS_FOR_COMPARABLE_TYPE( TComparable ) \
137alib::boxing::BootstrapRegister< alib::boxing::FEquals,TComparable>(FEquals::ComparableTypes<TComparable>);
138
139#define ALIB_BOXING_DEFINE_FISLESS_FOR_COMPARABLE_TYPE( TComparable ) \
140alib::boxing::BootstrapRegister< alib::boxing::FIsLess,TComparable>(FIsLess::ComparableTypes<TComparable>);
141
142#define ALIB_BOXING_BOOTSTRAP_REGISTER_FAPPEND_FOR_APPENDABLE_TYPE(TAppendable) \
143alib::boxing::BootstrapRegister<alib::boxing::FAppend<character, alib::lang::HeapAllocator>, TAppendable> \
144 (alib::boxing::FAppend<character, alib::lang::HeapAllocator>::Appendable<TAppendable>);
145
146#define ALIB_BOXING_BOOTSTRAP_REGISTER_FAPPEND_FOR_APPENDABLE_TYPE_N(TAppendable) \
147alib::boxing::BootstrapRegister<alib::boxing::FAppend<nchar , alib::lang::HeapAllocator>, TAppendable> \
148 (alib::boxing::FAppend<nchar , alib::lang::HeapAllocator>::Appendable<TAppendable>);
149
150#define ALIB_BOXING_BOOTSTRAP_REGISTER_FAPPEND_FOR_APPENDABLE_TYPE_W(TAppendable) \
151alib::boxing::BootstrapRegister<alib::boxing::FAppend<wchar , alib::lang::HeapAllocator>, TAppendable> \
152 (alib::boxing::FAppend<wchar , alib::lang::HeapAllocator>::Appendable<TAppendable>);
153
154#define ALIB_BOXING_BOOTSTRAP_REGISTER_FAPPEND_FOR_APPENDABLE_TYPE_X(TAppendable) \
155alib::boxing::BootstrapRegister<alib::boxing::FAppend<xchar , alib::lang::HeapAllocator>, TAppendable> \
156 (alib::boxing::FAppend<xchar , alib::lang::HeapAllocator>::Appendable<TAppendable>);
157
158
159
160
161#endif
162#endif // HPP_ALIB_BOXING_PP