ALib C++ Library
Library Version: 2402 R1
Documentation generated by doxygen
Loading...
Searching...
No Matches
placeholder.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_PLACEHOLDER
9#define HPP_ALIB_BOXING_PLACEHOLDER 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#if !defined (_GLIBCXX_CSTRING) && !defined(_CSTRING_)
16# include <cstring>
17#endif
18
19namespace alib { namespace boxing { namespace detail {
20/**
21* Inner struct providing a pointer and a length.<br>
22* A \c constexpr constructor is given (not shown in documentation).
23*/
25{
26 const void* Pointer; ///< The pointer to the array.
27 integer Length; ///< The length of the array.
28
29 // constexpr constructors
30 #if !defined(ALIB_DOX)
31 constexpr StructArray( const void* p, integer l) : Pointer( p ), Length ( l ) {}
32 #endif
33};
34
35/**
36 * Inner union with various \c constexpr constructors (not shown in documentation) to support
37 * the initialization of the outer union as \c constexpr.
38 *
39 * Collects scalar integrals and arrays of those.
40 */
42{
43 int8_t Int8 ; ///< 8-bit signed integral.
44 uint8_t UInt8 ; ///< 8-bit unsigned integral.
45 int16_t Int16 ; ///< 16-bit signed integral.
46 uint16_t UInt16 ; ///< 16-bit unsigned integral.
47
48 #if defined(ALIB_DOX)
49 int32_t Int32 ; ///< 32-bit signed integral. Available only if platform is not of 32-bit.
50 uint32_t UInt32 ; ///< 32-bit unsigned integral. Available only if platform is not of 32-bit.
51 int64_t Int64 ; ///< 64-bit signed integral. Available only if platform is not of 64-bit.
52 uint64_t UInt64 ; ///< 64-bit unsigned integral. Available only if platform is not of 64-bit.
53 #elif ALIB_SIZEOF_INTEGER != 4
54 int32_t Int32 ;
55 uint32_t UInt32 ;
56 #elif ALIB_SIZEOF_INTEGER != 8
57 int64_t Int64 ;
58 uint64_t UInt64 ;
59 #endif
60
61 integer Int ; ///< Signed integral of platform-dependent size.
62 uinteger UInt ; ///< Unsigned integral of platform-dependent size.
63
64 int8_t Array8 [2 * sizeof(uinteger) / sizeof( int8_t )]; ///< Array of 8-bit signed integrals of length 16 on 64-bit platform, 8 on a 32-bit platform.
65 int16_t Array16 [2 * sizeof(uinteger) / sizeof( int16_t )]; ///< Array of 16-bit signed integrals of length 8 on 64-bit platform, 4 on a 32-bit platform.
66
67 #if defined(ALIB_DOX)
68 int32_t Array32 [2 * sizeof(uinteger) / sizeof( int32_t )]; ///< Array of 32-bit signed integrals of length 4 on a 64-bit platform. Not available on 32-bit platforms.
69 int64_t Array64 [2 * sizeof(uinteger) / sizeof( int64_t )]; ///< Array of 64-bit signed integrals of length 1 on a 32-bit platform. Not available on 64-bit platforms.
70
71 #elif ALIB_SIZEOF_INTEGER != 4
72 int32_t Array32 [2 * sizeof(uinteger) / sizeof( int32_t )];
73 #elif ALIB_SIZEOF_INTEGER != 8
74 int64_t Array64 [2 * sizeof(uinteger) / sizeof( int64_t )];
75 #endif
76
77 integer Array [ 2 ]; ///< Array of 64-bit signed integrals of length 2 on 64-bit platform, 1 on a 32-bit platform.
78 uinteger UArray [ 2 ]; ///< Array of 64-bit unsigned integrals of length 2 on 64-bit platform, 1 on a 32-bit platform.
79
80
81 // constexpr constructors
82 #if !defined(ALIB_DOX)
83 constexpr UnionIntegrals ( integer v1, integer v2 ) : Array { v1, v2 } {}
84 constexpr UnionIntegrals ( int8_t value ) : Int8 { value } {}
85 constexpr UnionIntegrals ( uint8_t value ) : UInt8 { value } {}
86 constexpr UnionIntegrals ( int16_t value ) : Int16 { value } {}
87 constexpr UnionIntegrals ( uint16_t value ) : UInt16 { value } {}
88 #if ALIB_SIZEOF_INTEGER != 4
89 constexpr UnionIntegrals ( int32_t value ) : Int32 { value } {}
90 constexpr UnionIntegrals ( uint32_t value ) : UInt32 { value } {}
91 #elif ALIB_SIZEOF_INTEGER != 8
92 constexpr UnionIntegrals ( int64_t value ) : Int64 { value } {}
93 constexpr UnionIntegrals ( uint64_t value ) : UInt64 { value } {}
94 #endif
95 constexpr UnionIntegrals ( integer value ) : Int { value } {}
96 constexpr UnionIntegrals ( uinteger value ) : UInt { value } {}
97
98
99
100 #if ALIB_SIZEOF_INTGAP == 2
101 constexpr UnionIntegrals ( intGap_t value ) : Int16 { value } {}
102 constexpr UnionIntegrals ( uintGap_t value ) : UInt16 { value } {}
103 #elif ALIB_SIZEOF_INTGAP == 4
104 #if ALIB_SIZEOF_INTEGER != 4
105 constexpr UnionIntegrals ( intGap_t value ) : Int32 { value } {}
106 constexpr UnionIntegrals ( uintGap_t value ) : UInt32 { value } {}
107 #else
108 constexpr UnionIntegrals ( intGap_t value ) : Int { value } {}
109 constexpr UnionIntegrals ( uintGap_t value ) : UInt { value } {}
110 #endif
111 #elif ALIB_SIZEOF_INTGAP == 8
112 #if ALIB_SIZEOF_INTEGER != 8
113 constexpr UnionIntegrals ( intGap_t value ) : Int64 { value } {}
114 constexpr UnionIntegrals ( uintGap_t value ) : UInt64 { value } {}
115 #else
116 constexpr UnionIntegrals ( intGap_t value ) : Int { value } {}
117 constexpr UnionIntegrals ( uintGap_t value ) : UInt { value } {}
118 #endif
119 #else
120 #error "ALIB_SIZEOF_INTGAP not matched. Supported sizes are 2, 4 and 8."
121 #endif
122 #endif
123};
124
125/**
126 * Inner union with various \c constexpr constructors (not shown in documentation) to support
127 * the initialization of the outer union as \c constexpr.
128 *
129 * Collects scalar floating points and arrays of those.
130 */
132{
133 float Float ; ///< A \c float value.
134 double Double ; ///< A \c double value.
135#if (ALIB_SIZEOF_LONGDOUBLE_REPORTED <= 2 * ALIB_SIZEOF_INTEGER ) || defined(ALIB_DOX)
136 long double LDouble; ///< A <c>long double</c> value. Available only if sizeof(long double) is smaller or equal than 2 x sizeof(integer), which is for example not true with GCC on Linux 32 -bit.
137#endif
138
139 float FloatArray [2 * sizeof(uinteger) / sizeof(float )]; ///< Array of \c float. The Length is usually 4 on 64-bit platform, 2 on a 32-bit platform.
140 double DoubleArray [2 * sizeof(uinteger) / sizeof(double )]; ///< Array of \c double. The Length is usually 2 on 64-bit platform, 1 on a 32-bit platform.
141
142 #if !defined(ALIB_DOX)
143 constexpr UnionFloatingPoints( float value ) : Float { value } {}
144 constexpr UnionFloatingPoints( double value ) : Double { value } {}
145#if (ALIB_SIZEOF_LONGDOUBLE_REPORTED <= 2 * ALIB_SIZEOF_INTEGER ) || defined(ALIB_DOX)
146 constexpr UnionFloatingPoints( long double value ) : LDouble { value } {}
147#endif
148 #endif
149};
150
151
152/**
153 * Inner union with various \c constexpr constructors (not shown in documentation) to support
154 * the initialization of the outer union as \c constexpr.
155 *
156 * Collects a \c void and a \c char pointer and arrays of those.<br>
157 * In addition, non-pointer field #Memory (type \c char) is given, which can be be used to
158 * receive a pointer to the start of the placeholder by applying <c>operator&</c>.
159 * This \c char* then can be reinterpreted without braking the
160 * \https{strict-aliasing rule,stackoverflow.com/questions/98650/what-is-the-strict-aliasing-rule}
161 * when compiling the code with higher optimization levels.
162 */
164{
165 void* Void; ///< A \c void pointer.
166 const void* CVoid; ///< A constant \c void pointer.
167 char* Char; ///< A \c void pointer.
168 const char* CChar; ///< A constant \c void pointer.
169 wchar* WChar; ///< A \c wchar pointer.
170 const wchar* CWChar; ///< A constant \c wchar pointer.
171
172 void* VoidArray[2]; ///< Array of <c>void*</c> of length \c 2.
173 const void* CVoidArray[2]; ///< Array of <c>const void*</c> of length \c 2.
174 char* CharArray[2]; ///< Array of <c>char*</c> of length \c 2.
175 const char* CCharArray[2]; ///< Array of <c>const char*</c> of length \c 2.
176 wchar* WCharArray[2]; ///< Array of <c>wchar*</c> of length \c 2.
177 const wchar* CWCharArray[2]; ///< Array of <c>const wchar*</c> of length \c 2.
178
179 char Memory; ///< Not a pointer but becomes one with applying <c>operator&</c>.
180
181 #if !defined(ALIB_DOX)
182 constexpr UnionPointers( void* value ) : Void { value } {}
183 constexpr UnionPointers( const void* value ) : CVoid { value } {}
184 constexpr UnionPointers( char* value ) : Char { value } {}
185 constexpr UnionPointers( const char* value ) : CChar { value } {}
186 constexpr UnionPointers( wchar* value ) : WChar { value } {}
187 constexpr UnionPointers( const wchar* value ) : CWChar { value } {}
188
189 constexpr UnionPointers( const void* v1, const void* v2 ) : CVoidArray { v1, v2 } {}
190 constexpr UnionPointers( const char* v1, const char* v2 ) : CCharArray { v1, v2 } {}
191 constexpr UnionPointers( const wchar* v1, const wchar* v2 ) : CWCharArray { v1, v2 } {}
192 #endif
193};
194
195} // namespace alib::boxing[::detail]
196
197/** ************************************************************************************************
198 * A \alib{boxing;Box::data;protected member of this union} is contained in class
199 * \alib{boxing;Box} to store a boxed object.
200 * This member is passed as an argument to static methods \b Write and \b Read of type traits
201 * struct \alib{boxing;T_Boxer}, which implement boxing and unboxing.
202 *
203 * This union declares different inner structs and unions and contains one corresponding member of
204 * each. This sorts the union fields into different groups, which his also helpful when
205 * debugging instances of type box.
206 *
207 * The overall size of this union is two times the size of \c std::size_t, hence 16 bytes on a
208 * 64-bit and 8 bytes on a 32-bit system.
209 *
210 * Virtually any sort of data might be written into the union. With non-injective boxing, what means
211 * that two or more types are boxed to the same target type, the format that type uses has to be
212 * implemented by all \b Write and \b Read methods of any specialization of \alib{boxing;T_Boxer}.
213 * Otherwise, undefined behavior occurs.
214 *
215 * This type offers two sets of templated overloaded methods, named \b %Write and \b Read.
216 * In addition to be overloaded, the methods use TMP to be selected by the compiler only for
217 * certain template types.<br>
218 * The methods cover boxing and unboxing of the most frequent types like
219 * - fundamental types,
220 * - "fitting" value types that are copy assignable,
221 * - "fitting" value types that are not copy assignable,
222 * - pointers and
223 * - arrays (only boxing).
224 *
225 * For these type, the default implementation of \b T_Boxer::Write and \b Read, as given
226 * for example with macro \ref ALIB_BOXING_CUSTOMIZE_TYPE_MAPPING.
227 *
228 * ####Custom Boxing####
229 * Custom implementations of boxing and unboxing may read from and write to the union data
230 * directly.<br>
231 * In the latter case, a "continuous" use of the available data is suggested. Aat least, gaps
232 * in writing should be initialized with a value (e.g. \c 0). The rational for this is
233 * that the default implementations of box-functions \alib{boxing;FHashcode} and
234 * \alib{boxing;FEquals} use only the first \e N relevant bytes. If now, gaps are not written,
235 * they contain "random" data, what would cause a failure of these default functions.<br>
236 *
237 * On the same token, if a customization of a non-array type writes a different length then
238 * C++ operator \c sizeof reports for the mapped type, then also struct TMP
239 * \alib{boxing;T_SizeInPlaceholder} has to be specialized for that type, so that method
240 * \alib{boxing;Box::GetPlaceholderUsageLength} reports the right value.
241 * Not that also method #Clear, used when boxing \e nulled pointers, only clears as much
242 * data in this struct as reported by \alib{boxing;T_SizeInPlaceholder}.
243 *
244 * ####Constexpr Boxing####
245 * As explained in chapter \ref alib_boxing_more_opt_constexpr, method
246 * \alib{boxing;T_Boxer::Write} may be defined with a different signature that returns a
247 * value of this union, instead of receiving one to be filled. The aim is to allowing
248 * \c constexpr instances of class \b Box to be created from likewise \c constexpr values.
249 * The C++ language rules for \c constexpr constructors impose some restrictions. No reinterpret
250 * casts have to be performed. Furthermore, an union constructor must not initialize a field of an
251 * inner union by accessing it using the dot operator. Instead, the inner unions need to provide
252 * \c constexpr constructors that are called for the field of the outer union.
253 *
254 * While this library defines <c>constexpr</c>-boxing for all fundamental types and for most
255 * library types of other modules (if it provides customized boxing for), still such customization
256 * is considered "expert use" as the gain to do it for custom types is marginal.
257 * For this reason, the constructors of inner structs and unions, and all reflection of those
258 * with a corresponding constructor of this outer union are \b not documented.
259 * This is to keep the documentation lean and non-repetitive. Therefore, for reference
260 * of the \c constexpr constructors available for this union, please consult the
261 * source code, found in file \b alib/boxing/placeholder.inl.
262 *
263 * \note
264 * Unions
265 * \alib{boxing::detail;StructArray},
266 * \alib{boxing::detail;UnionIntegrals},
267 * \alib{boxing::detail;UnionFloatingPoints} and
268 * \alib{boxing::detail;UnionPointers} are defined in the \b detail namespace instead of being
269 * inner types. This is due to a restriction of the \b MSC compiler.
270 *
271 * \see
272 * Chapter \ref alib_boxing_customizing "7. Customizing Boxing" of the Programmer's Manual of
273 * \alib_boxing_nl.<br>
274 * Furthermore structs \alib{boxing;T_Boxer} and \alib{boxing;T_SizeInPlaceholder}.
275 * ************************************************************************************************/
277{
278 detail::UnionPointers Pointers; ///< Collection of \c void, \c char and \b character pointers.
279 detail::StructArray Array; ///< Used when storing C++ arrays.
280 detail::UnionIntegrals Integrals; ///< Collection of integrals of different sizes.
281 detail::UnionFloatingPoints FloatingPoints; ///< Collection of floating points of different sizes.
282
283 #if ALIB_DEBUG
284 character* Debugger_String; ///< This union field was inserted only for debug display.
285 integer Debugger_Integral; ///< This union field was inserted only for debug display.
286 #endif
287
288
289 // constexpr constructors
290 #if !defined(ALIB_DOX)
291
292 // This unnecessary default initialization with default constructor will be optimized out.
293 constexpr Placeholder() : Integrals(0) {}
294
295 // Pointer construction
296 constexpr Placeholder( void* p ) : Pointers( p ) {}
297 constexpr Placeholder( const void* p ) : Pointers( p ) {}
298 constexpr Placeholder( char* p ) : Pointers( p ) {}
299 constexpr Placeholder( const char* p ) : Pointers( p ) {}
300 constexpr Placeholder( wchar* p ) : Pointers( p ) {}
301 constexpr Placeholder( const wchar* p ) : Pointers( p ) {}
302 constexpr Placeholder( const void* p1, const void* p2 ) : Pointers( p1, p2 ) {}
303 constexpr Placeholder( char* p1, char* p2 ) : Pointers( p1, p2 ) {}
304 constexpr Placeholder( const char* p1, const char* p2 ) : Pointers( p1, p2 ) {}
305 constexpr Placeholder( wchar* p1, wchar* p2 ) : Pointers( p1, p2 ) {}
306 constexpr Placeholder( const wchar* p1, const wchar* p2 ) : Pointers( p1, p2 ) {}
307
308 template<typename TMapped>
309 constexpr Placeholder( const TMapped* p ) : Pointers( p ) {}
310
311 // Integral construction
312 constexpr Placeholder( int8_t value ) : Integrals ( value ) {}
313 constexpr Placeholder( int16_t value ) : Integrals ( value ) {}
314 constexpr Placeholder( int32_t value ) : Integrals ( value ) {}
315 constexpr Placeholder( int64_t value ) : Integrals ( value ) {}
316 constexpr Placeholder( intGap_t value ) : Integrals ( value ) {}
317 constexpr Placeholder( uint8_t value ) : Integrals ( value ) {}
318 constexpr Placeholder( uint16_t value ) : Integrals ( value ) {}
319 constexpr Placeholder( uint32_t value ) : Integrals ( value ) {}
320 constexpr Placeholder( uint64_t value ) : Integrals ( value ) {}
321 constexpr Placeholder( uintGap_t value ) : Integrals ( value ) {}
322 constexpr Placeholder( integer word1, integer word2 ) : Integrals( word1, word2 ) {}
323
324 // Float construction
325 constexpr Placeholder( float value ) : FloatingPoints ( value ) {}
326 constexpr Placeholder( double value ) : FloatingPoints ( value ) {}
327#if ALIB_SIZEOF_LONGDOUBLE_REPORTED <= 2 * ALIB_SIZEOF_INTEGER
328 constexpr Placeholder( long double value ) : FloatingPoints ( value ) {}
329#endif
330
331 // Array construction
332 template<typename TArray>
333 constexpr Placeholder( const TArray* tpointer, integer length ) : Array( tpointer, length ) {}
334
335 #endif
336
337 /**
338 * Returns a pointer of type \p{TReturn}.
339 * @tparam TReturn The requested pointer type
340 * @return The pointer stored.
341 */
342 template<typename TReturn>
343 constexpr TReturn* Pointer () const { return reinterpret_cast<TReturn*>( Pointers.Char); }
344
345 /**
346 * Returns a pointer of type \c void*.
347 * @return The pointer stored.
348 */
349 constexpr void* VoidPointer() const { return Pointers.Void; }
350
351 /**
352 * Sets a pointer of type \c char*.
353 * @param value The value to set.
354 */
355 constexpr
356 void Pointer ( const char* value ) { Pointers.CChar= value; }
357
358 /**
359 * Sets a pointer of type \c void*.
360 * @param value The value to set.
361 */
362 constexpr
363 void VoidPointer( const void* value ) { Pointers.CVoid= value; }
364
365 /**
366 * Returns the length of a stored array (the second word stored).
367 * @return The length stored.
368 */
369 constexpr integer Length () const { return GetInteger(1); }
370
371 /**
372 * Returns the length of a stored array (the second word stored).
373 * @return The length stored.
374 */
375 constexpr uinteger ULength () const { return GetUInteger(1); }
376
378 /**
379 * Returns the signed integral at index \p{idx}.
380 * @param idx The index requested. Only \c 0 and \c 1 is allowed.
381 * @return The integral value one or two.
382 */
383 constexpr integer GetInteger( int idx ) const { return Integrals.Array [idx]; }
384
385 /**
386 * Sets \p{value} at index \p{idx}.
387 * @param idx The index to store \p{value} in. Only \c 0 and \c 1 is allowed.
388 * @param value The value to set.
389 */
390 constexpr
391 void SetInteger( int idx, integer value )
392 {
393 Integrals.Array [idx]= value;
394 }
395
396 /**
397 * Returns the unsigned integral at index \p{idx}.
398 * @param idx The index requested. Only \c 0 and \c 1 is allowed.
399 * @return The integral value one or two.
400 */
401 constexpr uinteger GetUInteger( int idx ) const { return Integrals.UArray[idx]; }
402
403 /**
404 * Sets \p{value} at index \p{idx}.
405 * @param idx The index to store \p{value} in. Only \c 0 and \c 1 is allowed.
406 * @param value The value to set.
407 */
408 constexpr
409 void SetUInteger( int idx, uinteger value )
410 {
411 Integrals.UArray[idx]= value;
412 }
414
415
416 /** ********************************************************************************************
417 * Clears this box data.
418 *
419 * It has to be assured that all memory used by a mapped type are cleared.
420 * For example, the default implementations of box-functions \alib{boxing;FHashcode} and
421 * \alib{boxing;FEquals} are using the relevant bytes of this placeholder and those must
422 * not be of random value.
423 *
424 * For efficiency reasons, the rest should not be cleared.
425 *
426 * @tparam UsageLength The number of bytes to clear.
427 * ********************************************************************************************/
428 template<unsigned int UsageLength>
429 constexpr void Clear()
430 {
431 static_assert( UsageLength > 0 && ( UsageLength <= 2 * sizeof(uinteger) ),
432 "Invalid usage length given" );
433
434 Integrals.Array[0]= 0;
436 if constexpr( UsageLength > sizeof(integer) )
437 Integrals.Array[1]= 0;
439 }
440
441 // #############################################################################################
442 // ######################### Boxing #####################################
443 // #############################################################################################
444
445 #if defined(ALIB_DOX)
446
447 /** ********************************************************************************************
448 * This version of the overloaded methods is selected using TMP with most types, namly
449 * fundamental, pointers and those value types that are copy assignable.
450 *
451 * The type is stored at the start of the data, by reinterpreting the address of field
452 * \alib{boxing::detail;UnionPointers::Memory} to a pointer to \p{TMapped} and using the
453 * C++ assign operator on that dereferenced pointer.
454 *
455 * @tparam TMapped The mapped type to store.
456 * @param value The value of type \p{TMapped} to store.
457 * ********************************************************************************************/
458 template<typename TMapped>
459 inline void Write( const TMapped& value);
460 #else
461
462 template<typename TMapped>
464 ATMP_VOID_IF( std::is_copy_assignable<TMapped>::value
465 && (sizeof(TMapped) <= 2 * sizeof(uinteger)) )
466 Write( const TMapped& value)
467 {
468 *reinterpret_cast<TMapped*>( &Pointers ) = value;
469 }
470
471 #endif
472
473 #if defined(ALIB_DOX)
474 /** ********************************************************************************************
475 * This version of the overloaded methods is selected using TMP with types boxed as values
476 * that are not copy-assignbable.
477 *
478 * The copying is performed using \c memcpy.
479 * This is necessary to avoid de-referencing type-punned pointers which would
480 * break the strict-aliasing rule when compiling the code with higher optimization levels.
481 * Note that modern compilers like GCC usually optimize the invocation of \c memcpy out.<br>
482 *
483 * @tparam TMapped The mapped type to store.
484 * @param value The value of type \p{TMapped} to store.
485 * ********************************************************************************************/
486 template<typename TMapped>
487 inline void Write( const TMapped& value);
488 #else
489
490 template<typename TMapped>
492 ATMP_VOID_IF( !std::is_copy_assignable<TMapped>::value
493 && (sizeof(TMapped) <= 2 * sizeof(uinteger)) )
494 Write( const TMapped& value)
495 {
496 std::memcpy( &Pointers.Memory, &value, sizeof(TMapped) );
497 }
498
499 #endif
500
501
502 #if defined(ALIB_DOX)
503 /** ********************************************************************************************
504 * This version of the overloaded methods is used for boxing C++ array types.
505 * The type and length of the array is stored in field #Array of the data union.
506 *
507 * Note that for unboxing custom types from C++ array types, a custom implementation of
508 * \alib{boxing;T_Boxer::Read} is needed. Such implementation reads the pointer and length
509 * directly from this struct.
510 * (I.e. there is no overloaded method \b Read available for arrays.)
511 *
512 * @tparam TArray The templated pointer type.
513 * @param pointer The pointer to store.
514 * @param length The array's length to store.
515 * ********************************************************************************************/
516 template<typename TArray>
517 inline constexpr
518 void Write( const TArray* pointer, integer length );
519 #else
520
521 template<typename TArray>
522 ALIB_FORCE_INLINE constexpr
523 void Write( const TArray* pointer, integer length )
524 {
525 Array.Pointer = pointer;
526 Array.Length = length;
527 }
528 #endif
529
530
531 // #############################################################################################
532 // ######################### Unboxing #####################################
533 // #############################################################################################
534
535 /** ********************************************************************************************
536 * Templated read method for value types.
537 * The value is dereferenced from the start of the placeholder memory.
538 *
539 * @tparam TMapped The value type to unbox.
540 * @return The value stored.
541 * ********************************************************************************************/
542 template<typename TMapped>
543 ALIB_FORCE_INLINE constexpr
544 TMapped Read() const
545 {
546 return *reinterpret_cast<const TMapped*>( &Pointers.Memory );
547 }
548
549
550}; // union Placeholder
551
552static_assert( sizeof(Placeholder) == 2 * sizeof(std::size_t),
553 "Size of boxing::Placeholder is not two times the size of 'size_t'. "
554 "Compilation platform not supported." );
555
556}} // namespace [alib::boxing]
557
558#endif // HPP_ALIB_BOXING_PLACEHOLDER
#define ATMP_VOID_IF(Cond)
Definition tmp.hpp:52
#define ALIB_WARNINGS_RESTORE
Definition alib.hpp:715
#define ALIB_FORCE_INLINE
Definition alib.hpp:549
#define ALIB_WARNINGS_ALLOW_UNSAFE_BUFFER_USAGE
Definition alib.hpp:644
Definition alib.cpp:57
lang::uinteger uinteger
Type alias in namespace alib.
Definition integers.hpp:289
characters::wchar wchar
Type alias in namespace alib.
lang::intGap_t intGap_t
Type alias in namespace alib.
Definition integers.hpp:292
characters::character character
Type alias in namespace alib.
lang::uintGap_t uintGap_t
Type alias in namespace alib.
Definition integers.hpp:295
lang::integer integer
Type alias in namespace alib.
Definition integers.hpp:286
integer Length
The length of the array.
const void * Pointer
The pointer to the array.
constexpr TReturn * Pointer() const
constexpr void Pointer(const char *value)
character * Debugger_String
This union field was inserted only for debug display.
ALIB_WARNINGS_ALLOW_UNSAFE_BUFFER_USAGE constexpr integer GetInteger(int idx) const
constexpr uinteger ULength() const
detail::UnionIntegrals Integrals
Collection of integrals of different sizes.
constexpr void SetUInteger(int idx, uinteger value)
integer Debugger_Integral
This union field was inserted only for debug display.
constexpr integer Length() const
constexpr void SetInteger(int idx, integer value)
constexpr void VoidPointer(const void *value)
detail::UnionFloatingPoints FloatingPoints
Collection of floating points of different sizes.
constexpr uinteger GetUInteger(int idx) const
detail::UnionPointers Pointers
Collection of void, char and character pointers.
constexpr void Write(const TArray *pointer, integer length)
constexpr void * VoidPointer() const
ALIB_WARNINGS_RESTORE constexpr void Clear()
ALIB_FORCE_INLINE constexpr TMapped Read() const
detail::StructArray Array
Used when storing C++ arrays.
void Write(const TMapped &value)
float FloatArray[2 *sizeof(uinteger)/sizeof(float)]
Array of float. The Length is usually 4 on 64-bit platform, 2 on a 32-bit platform.
long double LDouble
A long double value. Available only if sizeof(long double) is smaller or equal than 2 x sizeof(intege...
double DoubleArray[2 *sizeof(uinteger)/sizeof(double)]
Array of double. The Length is usually 2 on 64-bit platform, 1 on a 32-bit platform.
int64_t Int64
64-bit signed integral. Available only if platform is not of 64-bit.
integer Int
Signed integral of platform-dependent size.
uint8_t UInt8
8-bit unsigned integral.
int8_t Int8
8-bit signed integral.
uinteger UInt
Unsigned integral of platform-dependent size.
int64_t Array64[2 *sizeof(uinteger)/sizeof(int64_t)]
Array of 64-bit signed integrals of length 1 on a 32-bit platform. Not available on 64-bit platforms.
int8_t Array8[2 *sizeof(uinteger)/sizeof(int8_t)]
Array of 8-bit signed integrals of length 16 on 64-bit platform, 8 on a 32-bit platform.
int32_t Int32
32-bit signed integral. Available only if platform is not of 32-bit.
uint16_t UInt16
16-bit unsigned integral.
integer Array[2]
Array of 64-bit signed integrals of length 2 on 64-bit platform, 1 on a 32-bit platform.
uinteger UArray[2]
Array of 64-bit unsigned integrals of length 2 on 64-bit platform, 1 on a 32-bit platform.
int16_t Int16
16-bit signed integral.
int32_t Array32[2 *sizeof(uinteger)/sizeof(int32_t)]
Array of 32-bit signed integrals of length 4 on a 64-bit platform. Not available on 32-bit platforms.
int16_t Array16[2 *sizeof(uinteger)/sizeof(int16_t)]
Array of 16-bit signed integrals of length 8 on 64-bit platform, 4 on a 32-bit platform.
uint32_t UInt32
32-bit unsigned integral. Available only if platform is not of 32-bit.
uint64_t UInt64
64-bit unsigned integral. Available only if platform is not of 64-bit.
const char * CChar
A constant void pointer.
void * VoidArray[2]
Array of void* of length 2.
wchar * WCharArray[2]
Array of wchar* of length 2.
char Memory
Not a pointer but becomes one with applying operator&.
const char * CCharArray[2]
Array of const char* of length 2.
const void * CVoid
A constant void pointer.
const wchar * CWCharArray[2]
Array of const wchar* of length 2.
const wchar * CWChar
A constant wchar pointer.
const void * CVoidArray[2]
Array of const void* of length 2.
char * CharArray[2]
Array of char* of length 2.