ALib C++ Library
Library Version: 2412 R0
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#pragma once
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 !DOXYGEN
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( BoxesHA*, vt_boxes )
34#if ALIB_MONOMEM
35ALIB_BOXING_VTABLE_DECLARE( BoxesMA*, vt_boxesma )
36#endif
37ALIB_BOXING_VTABLE_DECLARE_ARRAYTYPE( Box , vt_boxarray )
38
39
40// #################################################################################################
41// Enums
42// #################################################################################################
43namespace alib { namespace boxing {
44template<typename TEnum> struct T_Boxer<TEnum, ATMP_VOID_IF( std::is_enum<TEnum>::value )>
45{
46 using Mapping= TMappedTo<TEnum>;
47
48 static constexpr Placeholder Write( TEnum const & enumElement )
49 {
50 return Placeholder( static_cast<integer>( enumElement ) );
51 }
52
53 static TEnum Read( const Placeholder& src)
54 {
55 return TEnum( static_cast<typename std::underlying_type<TEnum>::type>( src.GetInteger(0)) );
56 }
57};
58}}
59
60
61// #################################################################################################
62// Boolean
63// #################################################################################################
64DOX_MARKER([DOX_BOXING_OPTIMIZE_DECLARE_1])
65ALIB_BOXING_VTABLE_DECLARE( bool, vt_bool )
66DOX_MARKER([DOX_BOXING_OPTIMIZE_DECLARE_1])
67
69
70
71// #################################################################################################
72// Integrals
73// #################################################################################################
74#if !ALIB_FEAT_BOXING_BIJECTIVE_INTEGRALS
75
76 ALIB_BOXING_VTABLE_DECLARE( integer, vt_integer )
77 ALIB_BOXING_VTABLE_DECLARE( uinteger, vt_uinteger )
78
81
84 //ALIB_BOXING_CUSTOMIZE_NOT_UNBOXABLE_CONSTEXPR( int16_t, integer ) // done in dox sample below
88
89 #if ALIB_SIZEOF_INTEGER == 8
92 #endif
93
94
95DOX_MARKER([DOX_BOXING_CUSTOM_MANUAL])
96namespace alib { namespace boxing {
97
98template<> struct T_Boxer<int16_t>
99{
100 using Mapping= TMappedTo<integer>;
101
102 static constexpr
103 Placeholder Write( int16_t const & value )
104 {
105 return Placeholder( static_cast<integer>( value ) );
106 }
107
108 static void Read( const Placeholder& src); // no implementation given, never called
109};
110
111}}
112DOX_MARKER([DOX_BOXING_CUSTOM_MANUAL])
113
114//--------- documentation sample of Programmer's Manual --------
115
116#else // ALIB_FEAT_BOXING_BIJECTIVE_INTEGRALS
117 ALIB_BOXING_VTABLE_DECLARE( int8_t , vt_int8_t )
118 ALIB_BOXING_VTABLE_DECLARE( uint8_t , vt_uint8_t )
119 ALIB_BOXING_VTABLE_DECLARE( int16_t , vt_int16_t )
120 ALIB_BOXING_VTABLE_DECLARE( uint16_t , vt_uint16_t )
121 ALIB_BOXING_VTABLE_DECLARE( int32_t , vt_int32_t )
122 ALIB_BOXING_VTABLE_DECLARE( uint32_t , vt_uint32_t )
123 ALIB_BOXING_VTABLE_DECLARE( intGap_t , vt_intGap_t )
124 ALIB_BOXING_VTABLE_DECLARE( uintGap_t , vt_uintGap_t )
125 #if ALIB_SIZEOF_INTEGER == 8
126 ALIB_BOXING_VTABLE_DECLARE( int64_t , vt_int64_t )
127 ALIB_BOXING_VTABLE_DECLARE( uint64_t , vt_uint64_t )
128 #endif
129
138
139 #if ALIB_SIZEOF_INTEGER == 8
142 #endif
143
144#endif // ALIB_FEAT_BOXING_BIJECTIVE_INTEGRALS
145
146
147
148// #################################################################################################
149// Floating point
150// #################################################################################################
151#if !ALIB_FEAT_BOXING_BIJECTIVE_FLOATS
153#else
154 ALIB_BOXING_VTABLE_DECLARE( float, vt_float )
156#endif
157
158 ALIB_BOXING_VTABLE_DECLARE( double , vt_double )
160
161#if ALIB_SIZEOF_LONGDOUBLE_REPORTED <= 2 * ALIB_SIZEOF_INTEGER
162 ALIB_BOXING_VTABLE_DECLARE( long double, vt_long_double )
163// ALIB_BOXING_CUSTOMIZE_TYPE_MAPPING_CONSTEXPR( long double, long double )
164
165namespace alib::boxing {
166template<> struct T_Boxer<long double>
167{
168 using Mapping= TMappedTo<long double>;
169 static Placeholder Write( long double const & value )
170 {
172 Placeholder target;
173 const char* src = reinterpret_cast<const char*>( &value );
174 char* dest= reinterpret_cast< char*>( &target );
175 for (int i = 0; i < ALIB_SIZEOF_LONGDOUBLE_WRITTEN; ++i)
176 *dest++= *src++;
178 return target;
179 }
180
181 static long double Read (const Placeholder& placeholder)
182 {
184 long double target;
185 const char* src = reinterpret_cast<const char*>( &placeholder );
186 char* dest= reinterpret_cast< char*>( &target );
187 for (int i = 0; i < ALIB_SIZEOF_LONGDOUBLE_WRITTEN; ++i)
188 *dest++= *src++;
190 return target;
191 }
192}; }
193
194#endif
195
196
197// #################################################################################################
198// Characters
199// #################################################################################################
200
201#if !ALIB_FEAT_BOXING_BIJECTIVE_CHARACTERS
202 ALIB_BOXING_VTABLE_DECLARE( wchar, vt_wchar )
203
205
206 #if ALIB_CHARACTERS_NATIVE_WCHAR
210 #else
212 # if ALIB_CHARACTERS_SIZEOF_WCHAR == 4
215 # else
218 # endif
219 #endif
220#else
221 ALIB_BOXING_VTABLE_DECLARE( char , vt_char )
222 ALIB_BOXING_VTABLE_DECLARE( wchar_t , vt_wchar_t )
223 ALIB_BOXING_VTABLE_DECLARE( char16_t , vt_char16_t )
224 ALIB_BOXING_VTABLE_DECLARE( char32_t , vt_char32_t )
225
230#endif
231
232
233// #################################################################################################
234// Character Arrays (Types with T_CharArray specializations)
235// #################################################################################################
236
237// vtables
238DOX_MARKER([DOX_BOXING_OPTIMIZE_DECLARE_2])
239ALIB_BOXING_VTABLE_DECLARE_ARRAYTYPE( char, vt_arr_char )
240DOX_MARKER([DOX_BOXING_OPTIMIZE_DECLARE_2])
241ALIB_BOXING_VTABLE_DECLARE_ARRAYTYPE( wchar_t , vt_arr_wchar_t )
242ALIB_BOXING_VTABLE_DECLARE_ARRAYTYPE( char16_t , vt_arr_char16_t)
243ALIB_BOXING_VTABLE_DECLARE_ARRAYTYPE( char32_t , vt_arr_char32_t)
244
245
246#endif // !DOXYGEN
247namespace alib { namespace boxing {
248/// This type-traits struct by default inherits \c std::false_type. If specialized for
249/// template type \p{TCharArray} to inherit \c std::true_type, then boxing that type will not be
250/// customized automatically with a corresponding specialization of \alib{characters;T_CharArray}.
251/// This keeps the customization of boxing open to be performed in a different way.
252///
253/// \see
254/// See manual chapter \ref alib_boxing_strings "10. Boxing Character Strings" of the
255/// Programmer's Manual of module \alib_boxing_nl.
256///
257/// @tparam TCharArray The type that \alib{characters;T_CharArray} is specialized for but still no
258/// character array boxing should be performed.
259template<typename TCharArray> struct T_SuppressCharArrayBoxing : std::false_type {};
260}}
261#if !DOXYGEN
262namespace alib { namespace boxing {
263
264
265#define ALIBTMP_BOXER_WITHOUT_UNBOXING(TC) \
266template<typename TStringLike> struct T_Boxer<TStringLike, \
267ATMP_VOID_IF( \
268 !T_SuppressCharArrayBoxing<TStringLike>::value \
269&& characters::T_CharArray<TStringLike ALIB_COMMA TC>::Access \
270 == characters::AccessType ::Implicit \
271&& characters::T_CharArray<TStringLike ALIB_COMMA TC>::Construction \
272 != characters::ConstructionType::Implicit ) > \
273{ \
274 using Mapping= TMappedToArrayOf<TC>; \
275 static constexpr Placeholder Write( TStringLike const & value ) \
276 { \
277 return Placeholder( characters::T_CharArray<TStringLike, TC>::Buffer( value ), \
278 characters::T_CharArray<TStringLike, TC>::Length( value ) ); \
279 } \
280 static void Read( const Placeholder& src); }; \
281
282
283#define ALIBTMP_BOXER_WITH_UNBOXING(TC) \
284template<typename TStringLike> struct T_Boxer<TStringLike, \
285ATMP_VOID_IF( \
286 !T_SuppressCharArrayBoxing<TStringLike>::value \
287&& characters::T_CharArray<TStringLike ALIB_COMMA TC>::Access \
288 == characters::AccessType ::Implicit \
289&& characters::T_CharArray<TStringLike ALIB_COMMA TC>::Construction \
290 == characters::ConstructionType::Implicit ) > \
291{ \
292 using Mapping= TMappedToArrayOf<TC>; \
293 static constexpr Placeholder Write( TStringLike const & value ) \
294 { \
295 return Placeholder( characters::T_CharArray<TStringLike, TC>::Buffer( value ), \
296 characters::T_CharArray<TStringLike, TC>::Length( value ) ); \
297 } \
298 static TStringLike Read( const Placeholder& src) \
299 { \
300 return characters::T_CharArray<TStringLike, TC>::Construct( src.Pointer<TC>(), \
301 src.Length() ); \
302 } }; \
303
304
305ALIBTMP_BOXER_WITHOUT_UNBOXING(nchar) ALIBTMP_BOXER_WITH_UNBOXING(nchar)
306ALIBTMP_BOXER_WITHOUT_UNBOXING(wchar) ALIBTMP_BOXER_WITH_UNBOXING(wchar)
307ALIBTMP_BOXER_WITHOUT_UNBOXING(xchar) ALIBTMP_BOXER_WITH_UNBOXING(xchar)
308
309#undef ALIBTMP_BOXER_WITHOUT_UNBOXING
310#undef ALIBTMP_BOXER_WITH_UNBOXING
311}}
312
313// #################################################################################################
314// Static VTables for standard types
315// #################################################################################################
316ALIB_BOXING_VTABLE_DECLARE( std::type_info* , vt_std_type_info )
317
318// #################################################################################################
319// Static VTables for low-level ALib types
320// #################################################################################################
321// CodeMarker_CommonEnums
346
348// #################################################################################################
349// Static VTables for wrapped string-types
350// #################################################################################################
351#if ALIB_STRINGS
352 ALIB_BOXING_VTABLE_DECLARE( std::reference_wrapper<alib::strings::TAString<nchar ALIB_COMMA lang::HeapAllocator>>, vt_alib_wrapped_tanstring )
353 ALIB_BOXING_VTABLE_DECLARE( std::reference_wrapper<alib::strings::TAString<wchar ALIB_COMMA lang::HeapAllocator>>, vt_alib_wrapped_tawstring )
354 ALIB_BOXING_VTABLE_DECLARE( std::reference_wrapper<alib::strings::TAString<xchar ALIB_COMMA lang::HeapAllocator>>, vt_alib_wrapped_taxstring )
355#endif
356
357#endif //ALIB_DOX
358
359#endif // HPP_ALIB_BOXING_CUSTOMIZATIONS
360
#define ALIB_BOXING_VTABLE_DECLARE_ARRAYTYPE(TMapped, Identifier)
Definition vtable.inl:466
#define ATMP_VOID_IF(Cond)
Definition tmp.hpp:47
#define ALIB_WARNINGS_RESTORE
Definition alib.hpp:849
#define ALIB_BOXING_CUSTOMIZE_TYPE_MAPPING_CONSTEXPR(TSource, TTarget)
#define ALIB_BOXING_VTABLE_DECLARE(TMapped, Identifier)
Definition vtable.inl:460
#define ALIB_BOXING_CUSTOMIZE_NOT_UNBOXABLE_CONSTEXPR(TSource, TTarget)
#define ALIB_WARNINGS_ALLOW_UNSAFE_BUFFER_USAGE
Definition alib.hpp:760
#define ALIB_SIZEOF_LONGDOUBLE_WRITTEN
Definition prepro.md:30
Recursive
Denotes whether recursion is performed/allowed or not.
Inclusion
Denotes how members of a set something should be taken into account.
ValueReference
Denotes if a value is interpreted as an absolute or relative number.
Whitespaces
Denotes whether a string is trimmed or not.
CreateDefaults
Denotes whether default entities should be created or not.
Caching
Denotes if a cache mechanism is enabled or disabled.
Side
Denotes if something is left or right.
Propagation
Denotes whether a e.g a setting should be propagated.
Switch
Denotes if sth. is switched on or off.
Initialization
Used for example with constructors that allow to suppress initialization of members.
Safeness
Denotes whether something should be performed in a safe or unsafe fashion.
SortOrder
Denotes sort order.
Reach
Denotes the reach of something.
SourceData
Denotes if the source data should be moved or copied.
Timezone
Denotes whether a time value represents local time or UTC.
Case
Denotes upper and lower case character treatment.
Alignment
Denotes Alignments.
Timing
Denotes if asynchronous tasks become synchronized.
CreateIfNotExists
Denotes whether something should be created if it does not exist.
Phase
Denotes a phase, e.g.,of a transaction.
ContainerOp
Denotes standard container operations.
Definition alib.cpp:69
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:273
static Read(const Placeholder &src)
static void Write(Placeholder &target, const TBoxable &value)
TMappedTo< detail::TDefaultBoxing > Mapping