8#if !defined(ALIB_C20_MODULES) || ((ALIB_C20_MODULES != 0) && (ALIB_C20_MODULES != 1))
9# error "Symbol ALIB_C20_MODULES has to be given to the compiler as either 0 or 1"
49#if ALIB_DEBUG && !DOXYGEN
54 extern long double LONGDOUBLE_WRITE_TEST_MEM[2];
55extern void LongDoubleTrueLengthSet();
56extern bool LongDoubleTrueLengthTest();
74bool FIsNotNull_Default(
const Box& box ) {
75 return !( (box.IsArray() && box.UnboxLength() == 0 )
76 || (box.IsPointer() && box.Data().PointerPair.P1 ==
nullptr )
80std::size_t FHashcode_Default(
const Box& self ) {
81 if( self.IsPointer() ) {
82 return size_t(0xa814e72cUL)
83 + size_t( self.TypeID().hash_code() )
84 + self.Data().Integrals.UArray[0] * 89047023;
88 return size_t(0x49a024efUL)
89 + size_t( self.TypeID().hash_code() )
90 + self.Data().Integrals.UArray[0] * 79204799;
93 if( self.IsArray() ) {
94 std::size_t result= 0xa925eb91L
95 + std::size_t( self.ElementTypeID().hash_code() );
98 auto size = self.ArrayElementSize();
99 auto length= self.UnboxLength();
100 if( size == 2 || size == 6 ) {
104 std::span<uint16_t> array= {self.Data().GetPointer<uint16_t>(),
size_t(length) };
105 for( uint16_t v : array )
106 result = 67 * result + v;
108 return size_t( result );
112 std::span<uint32_t> array= {self.Data().GetPointer<uint32_t>(),
size_t(length) };
113 for( uint32_t v : array )
114 result = 67*result + v;
116 return size_t( result );
120 std::span<uint64_t> array= {self.Data().GetPointer<uint64_t>(),
size_t(length) };
121 for( uint64_t v : array )
122 result = std::size_t( 67 * result + v );
124 return std::size_t( result );
130 std::span<unsigned char> array= {self.Data().GetPointer<
unsigned char>(),
size_t(length) };
131 for(
unsigned char v : array )
132 result = 67 * result + v;
134 return size_t( result );
138 size_t result= size_t(0xcf670957UL)
139 + size_t( self.TypeID().hash_code() );
141 unsigned usedLen= self.GetPlaceholderUsageLength();
147 return size_t( ( self.Data().Integrals.UArray[0]
148 & ((Bit1 << (usedLen * 8) )- 1) ) * 32194735 )
152 result+= self.Data().Integrals.UArray[0] * 32194735;
159 return size_t( ( self.Data().Integrals.UArray[1]
160 & ((Bit1 << ((usedLen -
sizeof(
uinteger)) * 8) )- 1) ) * 321947 )
164 return result + self.Data().Integrals.UArray[1] * 321947;
169bool FEquals_Default(
const Box& self,
const Box& rhs ) {
170 if( !self.IsSameType( rhs ) )
174 if( self.IsArray() ) {
176 if( self.UnboxLength() != rhs.UnboxLength()
177 || ( ( self.Data().GetPointer<
char>() ==
nullptr)
178 != ( rhs .Data().GetPointer<
char>() ==
nullptr ) ) )
181 return self.Data().GetPointer<
char>() ==
nullptr
182 || self.UnboxLength() == 0
183 || self.Data().GetPointer<
char>() == rhs.Data().GetPointer<
char>()
184 || memcmp( self.Data().GetPointer<
char>(),
185 rhs .Data().GetPointer<
char>(),
186 static_cast <size_t>( self.UnboxLength() ) * self.ArrayElementSize()
191 unsigned usedLen= self.GetPlaceholderUsageLength();
195 if( usedLen <
sizeof(
uinteger ) ) {
196 uinteger mask= (Bit1 << (usedLen * 8) )- 1;
197 return ( self.Data().Integrals.UArray[0] & mask )
198 == ( rhs .Data().Integrals.UArray[0] & mask );
202 if( self.Data().Integrals.UArray[0] != rhs.Data().Integrals.UArray[0] )
211 return ( self.Data().Integrals.UArray[1] & mask )
212 == ( rhs .Data().Integrals.UArray[1] & mask );
215 return self.Data().Integrals.UArray[1] == rhs.Data().Integrals.UArray[1];
219bool FEquals_double(
const Box& self,
const Box& rhsBox ) {
220 double lhs= self.UnboxFloatingPoint();
222 if( rhsBox.IsFloatingPoint () ) rhs= rhsBox.UnboxFloatingPoint () ;
223 else if( rhsBox.IsSignedIntegral () ) rhs= double( rhsBox.UnboxSignedIntegral () );
224 else if( rhsBox.IsUnsignedIntegral() ) rhs= double( rhsBox.UnboxUnsignedIntegral() );
228 #if defined(__clang__)
229 #pragma clang diagnostic push
230 #pragma clang diagnostic ignored "-Wfloat-equal"
236 || std::fabs( lhs - rhs ) <= double( 2.0f * std::numeric_limits<float>::epsilon() );
238 #if defined(__clang__)
239 #pragma clang diagnostic pop
243bool FEquals_integer(
const Box& self,
const Box& rhsBox ) {
244 if( rhsBox.IsFloatingPoint() )
245 return FEquals_double( rhsBox, self );
248 if( rhsBox.IsSignedIntegral () ) rhs= rhsBox.UnboxSignedIntegral () ;
249 else if( rhsBox.IsUnsignedIntegral() ) rhs=
static_cast< integer>( rhsBox.UnboxUnsignedIntegral() );
252 return self.UnboxSignedIntegral() == rhs;
255bool FEquals_uinteger(
const Box& self,
const Box& rhsBox ) {
256 if( rhsBox.IsFloatingPoint() )
257 return FEquals_double( rhsBox, self );
260 if( rhsBox.IsSignedIntegral () ) rhs=
uinteger( rhsBox.UnboxSignedIntegral () );
261 else if( rhsBox.IsUnsignedIntegral() ) rhs= rhsBox.UnboxUnsignedIntegral() ;
264 return self.UnboxUnsignedIntegral() == rhs;
267bool FEquals_char(
const Box& self,
const Box& rhs ) {
268 if( !rhs.IsCharacter() )
270 return self.UnboxCharacter() == rhs.UnboxCharacter();
274template<
typename TChar>
275bool FEquals_TChar_Arr(
const Box& lhs,
const Box& rhs ) {
276 if ( !rhs.IsArrayOf<TChar>() )
279 const TChar* compBuf= rhs.Data().GetPointer<TChar>();
280 const TChar* boxBuf= lhs.Data().GetPointer<TChar>();
281 if ( (boxBuf ==
nullptr) != (compBuf ==
nullptr) )
284 integer compLen= rhs.UnboxLength();
285 integer boxLen= lhs.UnboxLength();
286 if ( boxLen != compLen )
292bool FIsLess_Default(
const Box& box,
const Box& comp ) {
293 return std::type_index( box.TypeID() ) < std::type_index(comp.TypeID() )
294 || ( box.TypeID() == comp.TypeID()
295 &&box.Data().Integrals.UArray[0] < comp.Data().Integrals.UArray[0] );
299#if !ALIB_FEAT_BOXING_BIJECTIVE_INTEGRALS
300bool FIsLess_integer(
const Box& self,
const Box& rhs ) {
301 auto lhs= self.Data().Integrals.Array[0];
302 if( rhs.IsSameType( self ) )
return lhs < rhs.Unbox<
integer > ();
304 if( rhs.IsFloatingPoint() )
return double( lhs ) < rhs.UnboxFloatingPoint();
306 return std::type_index( self.TypeID() ) < std::type_index( rhs.TypeID() );
309bool FIsLess_uinteger(
const Box& self,
const Box& rhs ) {
310 auto lhs= self.Data().Integrals.UArray[0];
311 if( rhs.IsSameType( self ) )
return lhs < rhs.Data().Integrals.UArray[0] ;
313 if( rhs.IsFloatingPoint() )
return double ( lhs ) < rhs.UnboxFloatingPoint();
315 return std::type_index( self.TypeID() ) < std::type_index( rhs.TypeID() );
320bool helperBijectiveLessS(
integer selfVal,
const Box& selfType,
const Box& rhs )
322 if( rhs.IsSignedIntegral () )
return selfVal < rhs.UnboxSignedIntegral () ;
323 if( rhs.IsUnsignedIntegral() )
return selfVal <
integer(rhs.UnboxUnsignedIntegral());
324 if( rhs.IsFloatingPoint () )
return double( selfVal ) < rhs.UnboxFloatingPoint () ;
327 return std::type_index( selfType.TypeID() ) < std::type_index( rhs.TypeID() );
330bool helperBijectiveLessU(
uinteger selfVal,
const Box& selfType,
const Box& rhs )
332 if( rhs.IsSignedIntegral () )
return selfVal <
uinteger(rhs.UnboxSignedIntegral ());
333 if( rhs.IsUnsignedIntegral() )
return selfVal < rhs.UnboxUnsignedIntegral() ;
334 if( rhs.IsFloatingPoint () )
return double(selfVal) < rhs.UnboxFloatingPoint () ;
337 return std::type_index( selfType.TypeID() ) < std::type_index( rhs.TypeID() );
340bool FIsLess_int8_t (
const Box& self,
const Box& rhs ) {
return helperBijectiveLessS(
integer( self.Unbox< int8_t >() ), self, rhs ); }
341bool FIsLess_int16_t (
const Box& self,
const Box& rhs ) {
return helperBijectiveLessS(
integer( self.Unbox< int16_t >() ), self, rhs ); }
342bool FIsLess_int32_t (
const Box& self,
const Box& rhs ) {
return helperBijectiveLessS(
integer( self.Unbox< int32_t >() ), self, rhs ); }
343bool FIsLess_int64_t (
const Box& self,
const Box& rhs ) {
return helperBijectiveLessS(
integer( self.Unbox< int64_t >() ), self, rhs ); }
344bool FIsLess_intGap_t (
const Box& self,
const Box& rhs ) {
return helperBijectiveLessS(
integer( self.Unbox<
intGap_t>() ), self, rhs ); }
346bool FIsLess_uint8_t (
const Box& self,
const Box& rhs ) {
return helperBijectiveLessU(
uinteger( self.Unbox<uint8_t >() ), self, rhs ); }
347bool FIsLess_uint16_t (
const Box& self,
const Box& rhs ) {
return helperBijectiveLessU(
uinteger( self.Unbox<uint16_t >() ), self, rhs ); }
348bool FIsLess_uint32_t (
const Box& self,
const Box& rhs ) {
return helperBijectiveLessU(
uinteger( self.Unbox<uint32_t >() ), self, rhs ); }
349bool FIsLess_uint64_t (
const Box& self,
const Box& rhs ) {
return helperBijectiveLessU(
uinteger( self.Unbox<uint64_t >() ), self, rhs ); }
350bool FIsLess_uintGap_t(
const Box& self,
const Box& rhs ) {
return helperBijectiveLessU(
uinteger( self.Unbox<
uintGap_t>() ), self, rhs ); }
354bool FIsLess_char(
const Box& self,
const Box& rhs ) {
355 if( rhs.IsCharacter () )
356 return self.UnboxCharacter() < rhs.UnboxCharacter () ;
358 return std::type_index( self.TypeID() ) < std::type_index( rhs.TypeID() );
363bool FIsLess_double(
const Box& self,
const Box& rhs ) {
364 double lhs= self.Unbox<
double>();
365 if( rhs.IsFloatingPoint () )
return lhs < rhs.UnboxFloatingPoint () ;
366 if( rhs.IsSignedIntegral () )
return lhs < double( rhs.UnboxSignedIntegral () );
367 if( rhs.IsUnsignedIntegral() )
return lhs < double( rhs.UnboxUnsignedIntegral() );
369 return std::type_index( self.TypeID() ) < std::type_index( rhs.TypeID() );
372#if ALIB_FEAT_BOXING_BIJECTIVE_FLOATS
373 bool FIsLess_float(
const Box& self,
const Box& rhs )
375 float lhs= self.Unbox<
float>();
376 if( rhs.IsType<
float >() )
return lhs < rhs.Unbox<
float >() ;
377 if( rhs.IsType<
double >() )
return lhs < float( rhs.Unbox<
double>() );
378 if( rhs.IsSignedIntegral () )
return lhs < float( rhs.UnboxSignedIntegral () );
379 if( rhs.IsUnsignedIntegral() )
return lhs < float( rhs.UnboxUnsignedIntegral() );
381 return std::type_index( self.TypeID() ) < std::type_index( rhs.TypeID() );
390 if ( !self.IsArray() || self.UnboxLength() == 0)
395 if( src==
nullptr || placeHolder.Integrals.Array[1] < 0 )
398 size_t alignment= self.ArrayElementSize();
399 if( alignment >
sizeof(std::ptrdiff_t) )
400 alignment=
sizeof(std::ptrdiff_t);
403 placeHolder.SetPointer( memory().Alloc( self.ArrayElementSize() * placeHolder.Integrals.UArray[1],
405 memcpy( placeHolder.GetPointer<
char>(), src, self.ArrayElementSize() * placeHolder.Integrals.UArray[1] );
410bool FIsTrue_Default(
const Box& self ) {
412 return self.UnboxLength() != 0;
415 unsigned usedLen= self.GetPlaceholderUsageLength();
420 return ( self.Data().Integrals.UArray[0]
421 & ((Bit1 << (usedLen * 8) )- 1) ) != 0;
424 if( self.Data().Integrals.UArray[0] != 0 )
432 return ( self.Data().Integrals.UArray[1]
433 & ((Bit1 << (usedLen -
sizeof(
uinteger)) * 8 )- 1) ) != 0;
436 return self.Data().Integrals.UArray[1] != 0;
441template<
typename TChar>
442bool FIsLess_TChar_arr(
const Box& lhs,
const Box& rhs ) {
443 if( rhs.IsArrayOf<TChar>() )
444 return lhs.Unbox<strings::TString<TChar>>() < rhs.Unbox<strings::TString<TChar>>();
446 return std::type_index( lhs.TypeID() ) < std::type_index(rhs.TypeID() );
450template<
typename TChar,
typename TAllocator>
451void FAppend_Default(
const Box& self, strings::TAString<TChar,TAllocator>& target) {
452 if( self.IsPointer() ) {
455 << strings::THex<TChar>( self.Data().Integrals.UArray[0] )
460 if( self.IsEnum() ) {
461 target <<
ALIB_REL_DBG(
"EnumType", self.TypeID() ) <<
'(' << self.Data().Integrals.Array[0] <<
')';
465 if( self.IsArray() ) {
466 target <<
ALIB_REL_DBG(
"ArrayType", self.ElementTypeID() ) <<
'[' << self.UnboxLength() <<
']';
471 target <<
ALIB_REL_DBG(
"ValueType", self.TypeID() ) <<
"(Size: " << self.GetPlaceholderUsageLength() <<
" bytes)";
475template<
typename TCharSrc,
typename TChar,
typename TAllocator>
476void FAppend_TcharArr(
const Box& box, strings::TAString<TChar,TAllocator>& target )
477{ target.template Append<NC>( box.UnboxArray<TCharSrc>(), box.UnboxLength() ); }
491#if ALIB_DEBUG && !DOXYGEN
492namespace{
unsigned initFlag= 0; }
496 ALIB_ASSERT_ERROR( initFlag == 0x92A3EF61,
"BOXING",
"Not initialized when calling shutdown." )
503 ALIB_ASSERT_ERROR( initFlag == 0,
"BOXING",
"This method must not be invoked twice." )
510 debug::LongDoubleTrueLengthSet();
511 debug::LONGDOUBLE_WRITE_TEST_MEM[0]= 0.0L;
513 "Platform not supported. SizeTraits<long double> contains wrong size" )
525DOX_MARKER([DOX_BOXING_OPTIMIZE_REGISTER_1])
527DOX_MARKER([DOX_BOXING_OPTIMIZE_REGISTER_1])
529 #if !ALIB_FEAT_BOXING_BIJECTIVE_INTEGRALS
541 #if ALIB_SIZEOF_INTEGER == 8
548 #if ALIB_SIZEOF_LONGDOUBLE_REPORTED <= 2 * ALIB_SIZEOF_INTEGER
551 #if ALIB_FEAT_BOXING_BIJECTIVE_FLOATS
556 #if !ALIB_FEAT_BOXING_BIJECTIVE_CHARACTERS
566DOX_MARKER([DOX_BOXING_OPTIMIZE_REGISTER_2])
568DOX_MARKER([DOX_BOXING_OPTIMIZE_REGISTER_2])
606 #if !ALIB_SINGLE_THREADED
679 #if !ALIB_FEAT_BOXING_BIJECTIVE_INTEGRALS
695 #if !ALIB_FEAT_BOXING_BIJECTIVE_CHARACTERS
706 #if ALIB_FEAT_BOXING_BIJECTIVE_FLOATS
713 #if !ALIB_FEAT_BOXING_BIJECTIVE_INTEGRALS
729 #if !ALIB_FEAT_BOXING_BIJECTIVE_CHARACTERS
740 #if ALIB_FEAT_BOXING_BIJECTIVE_FLOATS
750 #if !ALIB_FEAT_BOXING_BIJECTIVE_INTEGRALS
766 #if ALIB_FEAT_BOXING_BIJECTIVE_FLOATS
773 #if !ALIB_FEAT_BOXING_BIJECTIVE_CHARACTERS
788 #if !ALIB_FEAT_BOXING_BIJECTIVE_INTEGRALS
804 #if ALIB_FEAT_BOXING_BIJECTIVE_FLOATS
810 #if !ALIB_FEAT_BOXING_BIJECTIVE_CHARACTERS
838 #if !ALIB_FEAT_BOXING_BIJECTIVE_CHARACTERS
850 #if !ALIB_FEAT_BOXING_BIJECTIVE_INTEGRALS
880 #if ALIB_FEAT_BOXING_BIJECTIVE_FLOATS
884 if constexpr (
sizeof(
long double) <=
sizeof(
Placeholder) ) {
956 #if ALIB_EXT_LIB_THREADS_AVAILABLE
974 #if ALIB_SYSTEM && ALIB_EXCEPTIONS
1005 #if !ALIB_SINGLE_THREADED
1008 #if ALIB_ENUMRECORDS
1022#if ALIB_DEBUG_BOXING
1030 assert( initFlag == 0x92A3EF61 );
1035 if( vtable==
nullptr)
1038 if( increaseUsageCounter )
1045 ALIB_ERROR(
"BOXING",
"Static VTable of mapped type <{}> not registered.\n"
1046 "Use Macro ALIB_BOXING_BOOTSTRAP_VTABLE_DBG_REGISTER with bootstrapping.",
1049 ALIB_ERROR(
"BOXING",
"Static VTable of mapped type <{}[]> not registered.\n"
1050 "Use Macro ALIB_BOXING_REGISTER_MAPPED_ARRAY_TYPE with bootstrapping.",
Qualities
Per-entry information about how a node was scanned.
#define ALIB_BOXING_BOOTSTRAP_REGISTER_FAPPEND_FOR_APPENDABLE_TYPE_X(TAppendable)
#define ALIB_ERROR(domain,...)
#define ALIB_BOXING_BOOTSTRAP_REGISTER_FAPPEND_FOR_APPENDABLE_TYPE(TAppendable)
#define ALIB_BOXING_BOOTSTRAP_VTABLE_DBG_REGISTER(Identifier)
#define ALIB_BOXING_BOOTSTRAP_REGISTER_FAPPEND_FOR_APPENDABLE_TYPE_N(TAppendable)
#define IF_ALIB_MONOMEM(...)
#define ALIB_ASSERT_ERROR(cond, domain,...)
#define ALIB_BOXING_BOOTSTRAP_REGISTER_FAPPEND_FOR_APPENDABLE_TYPE_W(TAppendable)
#define ALIB_REL_DBG(releaseCode,...)
This namespace exposes entities of module ALib Assert.
ALIB_DLL void DbgCheckIsInitialized()
ALIB_DLL void DbgCheckRegistration(detail::VTable *vtable, bool increaseUsageCounter)
void BootstrapRegisterDefault(typename TFDecl::Signature function)
void BootstrapRegister(typename TFDecl::Signature function)
constexpr unsigned SizeTraits
int Compare(const TChar *lhs, const TChar *rhs, integer cmpLength)
void FFormat_File(const Box &box, const String &formatSpec, NumberFormat &nf, AString &target)
SortOrder
Denotes sort order.
Side
Denotes if something is left or right.
SourceData
Denotes if the source data should be moved or copied.
Reach
Denotes the reach of something.
Recursive
Denotes whether recursion is performed/allowed or not.
Timing
Denotes if asynchronous tasks become synchronized.
Alignment
Denotes Alignments.
LineFeeds
Denotes line-feed encoding sequences "\n" and "\r\n".
ContainerOp
Denotes standard container operations.
Switch
Denotes if sth. is switched on or off.
Phase
Denotes a phase, e.g.,of a transaction.
CreateIfNotExists
Denotes whether something should be created if it does not exist.
Case
Denotes upper and lower case character treatment.
CreateDefaults
Denotes whether default entities should be created or not.
Whitespaces
Denotes whether a string is trimmed or not.
Caching
Denotes if a cache mechanism is enabled or disabled.
Propagation
Denotes whether a e.g a setting should be propagated.
ValueReference
Denotes if a value is interpreted as an absolute or relative number.
Safeness
Denotes whether something should be performed in a safe or unsafe fashion.
Initialization
Used, for example, with constructors that allow to suppress initialization of members.
Inclusion
Denotes how members of a set something should be taken into account.
Timezone
Denotes whether a time value represents local time or UTC.
strings::TAString< wchar, lang::HeapAllocator > WAString
Type alias in namespace alib.
lang::intGap_t intGap_t
Type alias in namespace alib.
characters::wchar wchar
Type alias in namespace alib.
lang::integer integer
Type alias in namespace alib.
strings::TAString< nchar, lang::HeapAllocator > NAString
Type alias in namespace alib.
monomem::TMonoAllocator< lang::HeapAllocator > MonoAllocator
lang::uintGap_t uintGap_t
Type alias in namespace alib.
boxing::Pair< T, U > Pair
Type alias in namespace alib.
characters::nchar nchar
Type alias in namespace alib.
characters::xchar xchar
Type alias in namespace alib.
strings::TAString< xchar, lang::HeapAllocator > XAString
Type alias in namespace alib.
lang::uinteger uinteger
Type alias in namespace alib.
static void Appendable(const Box &self, strings::TAString< TChar, TAllocator > &target)
static void WrappedAppendable(const Box &self, strings::TAString< TChar, TAllocator > &target)
static bool ComparableTypes(const Box &self, const Box &rhs)
static size_t UsePlaceholderBytes(const Box &self)
static ALIB_DLL bool ConstantTrue(const Box &)
static ALIB_DLL void Shutdown()
Needs to be called only in debug versions to shut down internal hashtables cleanly.
The custom function hash.
const std::type_info & ElementType
DbgFactoryType DbgProduction
Debug information.
@ Unregistered
Not registered, yet.
const std::type_info & Type
TReturn * GetPointer() const