ALib C++ Library
Library Version: 2510 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_DECLARE_NOEXPORT( TMapped, Identifier ) \
114namespace alib::boxing { namespace detail { \
115extern ALIB_DLL VTable SNGLTN_ ## Identifier; } \
116template<> struct VTableOptimizationTraits< TMapped, false > { \
117static constexpr detail::VTable* Get() { return &detail:: SNGLTN_ ## Identifier; } }; } \
118
119#define ALIB_BOXING_VTABLE_DECLARE_ARRAYTYPE_NOEXPORT( TMapped, Identifier ) \
120namespace alib::boxing { namespace detail { \
121extern ALIB_DLL VTable SNGLTN_ ## Identifier; } \
122template<> struct VTableOptimizationTraits< TMapped, true > { \
123static constexpr detail::VTable* Get() { return &detail:: SNGLTN_ ## Identifier;} }; } \
124
125
126#define ALIB_BOXING_VTABLE_DEFINE( TMapped, Identifier ) \
127alib::boxing::detail::VTable alib::boxing::detail::SNGLTN_ ## Identifier \
128( typeid(TMapped), typeid(void) , \
129 std::is_pointer<TMapped>::value \
130 ? VTable::MappingType::Pointer \
131 : std::is_enum<TMapped>::value \
132 ? VTable::MappingType::Enum \
133 : VTable::MappingType::Value , \
134 alib::boxing::SizeTraits<TMapped>); \
135
136#define ALIB_BOXING_VTABLE_DEFINE_ARRAYTYPE( TMapped, Identifier ) \
137alib::boxing::detail::VTable alib::boxing::detail::SNGLTN_ ## Identifier \
138(typeid(TMapped[1]) , typeid(TMapped), VTable::MappingType(sizeof(TMapped)), sizeof(Placeholder)); \
139
140
141#if ALIB_DEBUG_BOXING
142# define ALIB_BOXING_BOOTSTRAP_VTABLE_DBG_REGISTER( Identifier ) \
143alib::boxing::debug::DbgRegisterVTable( &alib::boxing::detail::SNGLTN_ ## Identifier, \
144 alib::boxing::detail::VTable::DbgFactoryType::Static );
145#else
146# define ALIB_BOXING_BOOTSTRAP_VTABLE_DBG_REGISTER( Identifier )
147#endif
148
149#define ALIB_BOXING_DEFINE_FEQUALS_FOR_COMPARABLE_TYPE( TComparable ) \
150alib::boxing::BootstrapRegister< alib::boxing::FEquals,TComparable>(FEquals::ComparableTypes<TComparable>);
151
152#define ALIB_BOXING_DEFINE_FISLESS_FOR_COMPARABLE_TYPE( TComparable ) \
153alib::boxing::BootstrapRegister< alib::boxing::FIsLess,TComparable>(FIsLess::ComparableTypes<TComparable>);
154
155#define ALIB_BOXING_BOOTSTRAP_REGISTER_FAPPEND_FOR_APPENDABLE_TYPE(TAppendable) \
156alib::boxing::BootstrapRegister<alib::boxing::FAppend<character, alib::lang::HeapAllocator>, TAppendable> \
157 (alib::boxing::FAppend<character, alib::lang::HeapAllocator>::Appendable<TAppendable>);
158
159#define ALIB_BOXING_BOOTSTRAP_REGISTER_FAPPEND_FOR_APPENDABLE_TYPE_N(TAppendable) \
160alib::boxing::BootstrapRegister<alib::boxing::FAppend<nchar , alib::lang::HeapAllocator>, TAppendable> \
161 (alib::boxing::FAppend<nchar , alib::lang::HeapAllocator>::Appendable<TAppendable>);
162
163#define ALIB_BOXING_BOOTSTRAP_REGISTER_FAPPEND_FOR_APPENDABLE_TYPE_W(TAppendable) \
164alib::boxing::BootstrapRegister<alib::boxing::FAppend<wchar , alib::lang::HeapAllocator>, TAppendable> \
165 (alib::boxing::FAppend<wchar , alib::lang::HeapAllocator>::Appendable<TAppendable>);
166
167#define ALIB_BOXING_BOOTSTRAP_REGISTER_FAPPEND_FOR_APPENDABLE_TYPE_X(TAppendable) \
168alib::boxing::BootstrapRegister<alib::boxing::FAppend<xchar , alib::lang::HeapAllocator>, TAppendable> \
169 (alib::boxing::FAppend<xchar , alib::lang::HeapAllocator>::Appendable<TAppendable>);
170
171
172
173
174#endif
175#endif // HPP_ALIB_BOXING_PP
176