ALib C++ Library
Library Version: 2402 R1
Documentation generated by doxygen
Loading...
Searching...
No Matches
customizations.inl
Go to the documentation of this file.
1/** ************************************************************************************************
2 * \file
3 * This header file is part of module \alib_boxing of the \aliblong.
4 *
5 * \emoji :copyright: 2013-2024 A-Worx GmbH, Germany.
6 * Published under \ref mainpage_license "Boost Software License".
7 **************************************************************************************************/
8#ifndef HPP_ALIB_BOXING_CUSTOMIZATIONS
9#define HPP_ALIB_BOXING_CUSTOMIZATIONS 1
10
11#if !defined(HPP_ALIB_BOXING_BOXING)
12# error "ALib sources with ending '.inl' must not be included from outside."
13#endif
14
15
16// ######### Switch off documentation parser for (almost) the whole header #####
17#if !defined(ALIB_DOX)
18
19// #################################################################################################
20// void*, Boxes*, Box[]
21// #################################################################################################
22ALIB_BOXING_VTABLE_DECLARE( void*, vt_voidP )
23
24namespace alib { namespace boxing {
25template<> struct T_Boxer<void*>
26{
27 using Mapping= TMappedTo<void*>;
28 static constexpr Placeholder Write( const void* value ) { return Placeholder( value ); }
29 static void* Read ( const Placeholder& src) { return const_cast<void*>( src.VoidPointer() ); }
30};
31}}
32
33ALIB_BOXING_VTABLE_DECLARE( Boxes*, vt_boxes )
34ALIB_BOXING_VTABLE_DECLARE_ARRAYTYPE( Box , vt_boxarray )
35
36
37// #################################################################################################
38// Enums
39// #################################################################################################
40namespace alib { namespace boxing {
41template<typename TEnum> struct T_Boxer<TEnum, ATMP_VOID_IF( std::is_enum<TEnum>::value )>
42{
43 using Mapping= TMappedTo<TEnum>;
44
45 static constexpr Placeholder Write( TEnum const & enumElement )
46 {
47 return Placeholder( static_cast<integer>( enumElement ) );
48 }
49
50 static TEnum Read( const Placeholder& src)
51 {
52 return TEnum( static_cast<typename std::underlying_type<TEnum>::type>( src.GetInteger(0)) );
53 }
54};
55}}
56
57
58// #################################################################################################
59// Boolean
60// #################################################################################################
61DOX_MARKER([DOX_ALIB_BOXING_OPTIMIZE_DECLARE_1])
62ALIB_BOXING_VTABLE_DECLARE( bool, vt_bool )
63DOX_MARKER([DOX_ALIB_BOXING_OPTIMIZE_DECLARE_1])
64
66
67
68// #################################################################################################
69// Integrals
70// #################################################################################################
71#if !ALIB_FEAT_BOXING_BIJECTIVE_INTEGRALS
72
73 ALIB_BOXING_VTABLE_DECLARE( integer, vt_integer )
74 ALIB_BOXING_VTABLE_DECLARE( uinteger, vt_uinteger )
75
78
81 //ALIB_BOXING_CUSTOMIZE_NOT_UNBOXABLE_CONSTEXPR( int16_t, integer ) // done in dox sample below
85
86 #if ALIB_SIZEOF_INTEGER == 8
89 #endif
90
91
92DOX_MARKER([DOX_ALIB_BOXING_CUSTOM_MANUAL])
93namespace alib { namespace boxing {
94
95template<> struct T_Boxer<int16_t>
96{
97 using Mapping= TMappedTo<integer>;
98
99 static constexpr
100 Placeholder Write( int16_t const & value )
101 {
102 return Placeholder( static_cast<integer>( value ) );
103 }
104
105 static void Read( const Placeholder& src); // no implementation given, never called
106};
107
108}}
109DOX_MARKER([DOX_ALIB_BOXING_CUSTOM_MANUAL])
110
111//--------- documentation sample of Programmer's Manual --------
112
113#else // ALIB_FEAT_BOXING_BIJECTIVE_INTEGRALS
114 ALIB_BOXING_VTABLE_DECLARE( int8_t , vt_int8_t )
115 ALIB_BOXING_VTABLE_DECLARE( uint8_t , vt_uint8_t )
116 ALIB_BOXING_VTABLE_DECLARE( int16_t , vt_int16_t )
117 ALIB_BOXING_VTABLE_DECLARE( uint16_t , vt_uint16_t )
118 ALIB_BOXING_VTABLE_DECLARE( int32_t , vt_int32_t )
119 ALIB_BOXING_VTABLE_DECLARE( uint32_t , vt_uint32_t )
120 ALIB_BOXING_VTABLE_DECLARE( intGap_t , vt_intGap_t )
121 ALIB_BOXING_VTABLE_DECLARE( uintGap_t , vt_uintGap_t )
122 #if ALIB_SIZEOF_INTEGER == 8
123 ALIB_BOXING_VTABLE_DECLARE( int64_t , vt_int64_t )
124 ALIB_BOXING_VTABLE_DECLARE( uint64_t , vt_uint64_t )
125 #endif
126
135
136 #if ALIB_SIZEOF_INTEGER == 8
139 #endif
140
141#endif // ALIB_FEAT_BOXING_BIJECTIVE_INTEGRALS
142
143
144
145// #################################################################################################
146// Floating point
147// #################################################################################################
148#if !ALIB_FEAT_BOXING_BIJECTIVE_FLOATS
150#else
151 ALIB_BOXING_VTABLE_DECLARE( float, vt_float )
153#endif
154
155 ALIB_BOXING_VTABLE_DECLARE( double , vt_double )
157
158#if ALIB_SIZEOF_LONGDOUBLE_REPORTED <= 2 * ALIB_SIZEOF_INTEGER
159 ALIB_BOXING_VTABLE_DECLARE( long double, vt_long_double )
160 ALIB_BOXING_CUSTOMIZE_TYPE_MAPPING_CONSTEXPR( long double, long double )
161#endif
162
163
164// #################################################################################################
165// Characters
166// #################################################################################################
167
168#if !ALIB_FEAT_BOXING_BIJECTIVE_CHARACTERS
169 ALIB_BOXING_VTABLE_DECLARE( wchar, vt_wchar )
170
172
173 #if ALIB_CHARACTERS_NATIVE_WCHAR
177 #else
179 # if ALIB_CHARACTERS_SIZEOF_WCHAR == 4
182 # else
185 # endif
186 #endif
187#else
188 ALIB_BOXING_VTABLE_DECLARE( char , vt_char )
189 ALIB_BOXING_VTABLE_DECLARE( wchar_t , vt_wchar_t )
190 ALIB_BOXING_VTABLE_DECLARE( char16_t , vt_char16_t )
191 ALIB_BOXING_VTABLE_DECLARE( char32_t , vt_char32_t )
192
197#endif
198
199
200// #################################################################################################
201// Character Arrays (Types with T_CharArray specializations)
202// #################################################################################################
203
204// vtables
205DOX_MARKER([DOX_ALIB_BOXING_OPTIMIZE_DECLARE_2])
206ALIB_BOXING_VTABLE_DECLARE_ARRAYTYPE( char, vt_arr_char )
207DOX_MARKER([DOX_ALIB_BOXING_OPTIMIZE_DECLARE_2])
208ALIB_BOXING_VTABLE_DECLARE_ARRAYTYPE( wchar_t , vt_arr_wchar_t )
209ALIB_BOXING_VTABLE_DECLARE_ARRAYTYPE( char16_t , vt_arr_char16_t)
210ALIB_BOXING_VTABLE_DECLARE_ARRAYTYPE( char32_t , vt_arr_char32_t)
211
212
213#endif // !defined(ALIB_DOX)
214namespace alib { namespace boxing {
215/**
216 * This type-traits struct by default inherits \c std::false_type. If specialized for
217 * template type \p{TCharArray} to inherit \c std::true_type, then boxing that type will not be
218 * customized automatically with a corresponding specialization of \alib{characters;T_CharArray}.
219 * This keeps the customization of boxing open to be performed in a different way.
220 *
221 * \see
222 * See manual chapter \ref alib_boxing_strings "10. Boxing Character Strings" of the
223 * Programmer's Manual of module \alib_boxing_nl.
224 *
225 * @tparam TCharArray The type that \alib{characters;T_CharArray} is specialized for but still no
226 * character array boxing should be performed.
227 */
228template<typename TCharArray> struct T_SuppressCharArrayBoxing : std::false_type {};
229}}
230#if !defined(ALIB_DOX)
231namespace alib { namespace boxing {
232
233
234#define ALIBTMP_BOXER_WITHOUT_UNBOXING(TC) \
235template<typename TStringLike> struct T_Boxer<TStringLike, \
236ATMP_VOID_IF( \
237 !T_SuppressCharArrayBoxing<TStringLike>::value \
238&& characters::T_CharArray<TStringLike ALIB_COMMA TC>::Access \
239 == characters::AccessType ::Implicit \
240&& characters::T_CharArray<TStringLike ALIB_COMMA TC>::Construction \
241 != characters::ConstructionType::Implicit ) > \
242{ \
243 using Mapping= TMappedToArrayOf<TC>; \
244 static constexpr Placeholder Write( TStringLike const & value ) \
245 { \
246 return Placeholder( characters::T_CharArray<TStringLike, TC>::Buffer( value ), \
247 characters::T_CharArray<TStringLike, TC>::Length( value ) ); \
248 } \
249 static void Read( const Placeholder& src); }; \
250
251
252#define ALIBTMP_BOXER_WITH_UNBOXING(TC) \
253template<typename TStringLike> struct T_Boxer<TStringLike, \
254ATMP_VOID_IF( \
255 !T_SuppressCharArrayBoxing<TStringLike>::value \
256&& characters::T_CharArray<TStringLike ALIB_COMMA TC>::Access \
257 == characters::AccessType ::Implicit \
258&& characters::T_CharArray<TStringLike ALIB_COMMA TC>::Construction \
259 == characters::ConstructionType::Implicit ) > \
260{ \
261 using Mapping= TMappedToArrayOf<TC>; \
262 static constexpr Placeholder Write( TStringLike const & value ) \
263 { \
264 return Placeholder( characters::T_CharArray<TStringLike, TC>::Buffer( value ), \
265 characters::T_CharArray<TStringLike, TC>::Length( value ) ); \
266 } \
267 static TStringLike Read( const Placeholder& src) \
268 { \
269 return characters::T_CharArray<TStringLike, TC>::Construct( src.Pointer<TC>(), \
270 src.Length() ); \
271 } }; \
272
273
274ALIBTMP_BOXER_WITHOUT_UNBOXING(nchar) ALIBTMP_BOXER_WITH_UNBOXING(nchar)
275ALIBTMP_BOXER_WITHOUT_UNBOXING(wchar) ALIBTMP_BOXER_WITH_UNBOXING(wchar)
276ALIBTMP_BOXER_WITHOUT_UNBOXING(xchar) ALIBTMP_BOXER_WITH_UNBOXING(xchar)
277
278#undef ALIBTMP_BOXER_WITHOUT_UNBOXING
279#undef ALIBTMP_BOXER_WITH_UNBOXING
280}}
281
282// #################################################################################################
283// Static VTables for standard types
284// #################################################################################################
285ALIB_BOXING_VTABLE_DECLARE( std::type_info* , vt_std_type_info )
286
287// #################################################################################################
288// Static VTables for low-level ALib types
289// #################################################################################################
290// CodeMarker_CommonEnums
315
316// #################################################################################################
317// Static VTables for wrapped string types
318// #################################################################################################
319#if ALIB_STRINGS
320 ALIB_BOXING_VTABLE_DECLARE( std::reference_wrapper<alib::strings::TAString<nchar>>, vt_alib_wrapped_tanstring )
321 ALIB_BOXING_VTABLE_DECLARE( std::reference_wrapper<alib::strings::TAString<wchar>>, vt_alib_wrapped_tawstring )
322 ALIB_BOXING_VTABLE_DECLARE( std::reference_wrapper<alib::strings::TAString<xchar>>, vt_alib_wrapped_taxstring )
323#endif
324
325#endif //ALIB_DOX
326
327#endif // HPP_ALIB_BOXING_CUSTOMIZATIONS
#define ALIB_BOXING_VTABLE_DECLARE_ARRAYTYPE(TMapped, Identifier)
Definition vtable.inl:483
#define ATMP_VOID_IF(Cond)
Definition tmp.hpp:52
#define ALIB_BOXING_CUSTOMIZE_TYPE_MAPPING_CONSTEXPR(TSource, TTarget)
#define ALIB_BOXING_VTABLE_DECLARE(TMapped, Identifier)
Definition vtable.inl:477
#define ALIB_BOXING_CUSTOMIZE_NOT_UNBOXABLE_CONSTEXPR(TSource, TTarget)
Definition alib.cpp:57
characters::wchar wchar
Type alias in namespace alib.
characters::xchar xchar
Type alias in namespace alib.
characters::nchar nchar
Type alias in namespace alib.
lang::integer integer
Type alias in namespace alib.
Definition integers.hpp:286
static Read(const Placeholder &src)
static void Write(Placeholder &target, const TBoxable &value)
TMappedTo< detail::TDefaultBoxing > Mapping