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];
55 extern void LongDoubleTrueLengthSet();
56 extern bool LongDoubleTrueLengthTest();
74bool FIsNotNull_Default(
const Box& box )
76 return !( (box.IsArray() && box.UnboxLength() == 0 )
77 || (box.IsPointer() && box.Data().PointerPair.P1 ==
nullptr )
81std::size_t FHashcode_Default(
const Box& self )
83 if( self.IsPointer() )
85 return size_t(0xa814e72cUL)
86 + size_t( self.TypeID().hash_code() )
87 + self.Data().Integrals.UArray[0] * 89047023;
92 return size_t(0x49a024efUL)
93 + size_t( self.TypeID().hash_code() )
94 + self.Data().Integrals.UArray[0] * 79204799;
99 std::size_t result= 0xa925eb91L
100 + std::size_t( self.ElementTypeID().hash_code() );
103 auto size = self.ArrayElementSize();
104 auto length= self.UnboxLength();
105 if( size == 2 || size == 6 )
110 std::span<uint16_t> array= {self.Data().GetPointer<uint16_t>(),
size_t(length) };
111 for( uint16_t v : array )
112 result = 67 * result + v;
114 return size_t( result );
119 std::span<uint32_t> array= {self.Data().GetPointer<uint32_t>(),
size_t(length) };
120 for( uint32_t v : array )
121 result = 67*result + v;
123 return size_t( result );
128 std::span<uint64_t> array= {self.Data().GetPointer<uint64_t>(),
size_t(length) };
129 for( uint64_t v : array )
130 result = std::size_t( 67 * result + v );
132 return std::size_t( result );
138 std::span<unsigned char> array= {self.Data().GetPointer<
unsigned char>(),
size_t(length) };
139 for(
unsigned char v : array )
140 result = 67 * result + v;
142 return size_t( result );
147 size_t result= size_t(0xcf670957UL)
148 + size_t( self.TypeID().hash_code() );
150 unsigned int usedLen= self.GetPlaceholderUsageLength();
156 return size_t( ( self.Data().Integrals.UArray[0]
157 & ((Bit1 << (usedLen * 8) )- 1) ) * 32194735 )
161 result+= self.Data().Integrals.UArray[0] * 32194735;
169 return size_t( ( self.Data().Integrals.UArray[1]
170 & ((Bit1 << ((usedLen -
sizeof(
uinteger)) * 8) )- 1) ) * 321947 )
174 return result + self.Data().Integrals.UArray[1] * 321947;
179bool FEquals_Default(
const Box& self,
const Box& rhs )
181 if( !self.IsSameType( rhs ) )
188 if( self.UnboxLength() != rhs.UnboxLength()
189 || ( ( self.Data().GetPointer<
char>() ==
nullptr)
190 != ( rhs .Data().GetPointer<
char>() ==
nullptr ) ) )
193 return self.Data().GetPointer<
char>() ==
nullptr
194 || self.UnboxLength() == 0
195 || self.Data().GetPointer<
char>() == rhs.Data().GetPointer<
char>()
196 || memcmp( self.Data().GetPointer<
char>(),
197 rhs .Data().GetPointer<
char>(),
198 static_cast <size_t>( self.UnboxLength() ) * self.ArrayElementSize()
203 unsigned int usedLen= self.GetPlaceholderUsageLength();
209 uinteger mask= (Bit1 << (usedLen * 8) )- 1;
210 return ( self.Data().Integrals.UArray[0] & mask )
211 == ( rhs .Data().Integrals.UArray[0] & mask );
215 if( self.Data().Integrals.UArray[0] != rhs.Data().Integrals.UArray[0] )
225 return ( self.Data().Integrals.UArray[1] & mask )
226 == ( rhs .Data().Integrals.UArray[1] & mask );
229 return self.Data().Integrals.UArray[1] == rhs.Data().Integrals.UArray[1];
233bool FEquals_double(
const Box& self,
const Box& rhsBox )
235 double lhs= self.UnboxFloatingPoint();
237 if( rhsBox.IsFloatingPoint () ) rhs= rhsBox.UnboxFloatingPoint () ;
238 else if( rhsBox.IsSignedIntegral () ) rhs= double( rhsBox.UnboxSignedIntegral () );
239 else if( rhsBox.IsUnsignedIntegral() ) rhs= double( rhsBox.UnboxUnsignedIntegral() );
243 #if defined(__clang__)
244 #pragma clang diagnostic push
245 #pragma clang diagnostic ignored "-Wfloat-equal"
251 || std::fabs( lhs - rhs ) <= double( 2.0f * std::numeric_limits<float>::epsilon() );
253 #if defined(__clang__)
254 #pragma clang diagnostic pop
258bool FEquals_integer(
const Box& self,
const Box& rhsBox )
260 if( rhsBox.IsFloatingPoint() )
261 return FEquals_double( rhsBox, self );
264 if( rhsBox.IsSignedIntegral () ) rhs= rhsBox.UnboxSignedIntegral () ;
265 else if( rhsBox.IsUnsignedIntegral() ) rhs=
static_cast< integer>( rhsBox.UnboxUnsignedIntegral() );
268 return self.UnboxSignedIntegral() == rhs;
271bool FEquals_uinteger(
const Box& self,
const Box& rhsBox )
273 if( rhsBox.IsFloatingPoint() )
274 return FEquals_double( rhsBox, self );
277 if( rhsBox.IsSignedIntegral () ) rhs=
uinteger( rhsBox.UnboxSignedIntegral () );
278 else if( rhsBox.IsUnsignedIntegral() ) rhs= rhsBox.UnboxUnsignedIntegral() ;
281 return self.UnboxUnsignedIntegral() == rhs;
284bool FEquals_char(
const Box& self,
const Box& rhs )
286 if( !rhs.IsCharacter() )
288 return self.UnboxCharacter() == rhs.UnboxCharacter();
292template<
typename TChar>
293bool FEquals_TChar_Arr(
const Box& lhs,
const Box& rhs )
295 if ( !rhs.IsArrayOf<TChar>() )
298 const TChar* compBuf= rhs.Data().GetPointer<TChar>();
299 const TChar* boxBuf= lhs.Data().GetPointer<TChar>();
300 if ( (boxBuf ==
nullptr) != (compBuf ==
nullptr) )
303 integer compLen= rhs.UnboxLength();
304 integer boxLen= lhs.UnboxLength();
305 if ( boxLen != compLen )
311bool FIsLess_Default(
const Box& box,
const Box& comp )
313 return std::type_index( box.TypeID() ) < std::type_index(comp.TypeID() )
314 || ( box.TypeID() == comp.TypeID()
315 &&box.Data().Integrals.UArray[0] < comp.Data().Integrals.UArray[0] );
319#if !ALIB_FEAT_BOXING_BIJECTIVE_INTEGRALS
320bool FIsLess_integer(
const Box& self,
const Box& rhs )
322 auto lhs= self.Data().Integrals.Array[0];
323 if( rhs.IsSameType( self ) )
return lhs < rhs.Unbox<
integer > ();
325 if( rhs.IsFloatingPoint() )
return double( lhs ) < rhs.UnboxFloatingPoint();
327 return std::type_index( self.TypeID() ) < std::type_index( rhs.TypeID() );
330bool FIsLess_uinteger(
const Box& self,
const Box& rhs )
332 auto lhs= self.Data().Integrals.UArray[0];
333 if( rhs.IsSameType( self ) )
return lhs < rhs.Data().Integrals.UArray[0] ;
335 if( rhs.IsFloatingPoint() )
return double ( lhs ) < rhs.UnboxFloatingPoint();
337 return std::type_index( self.TypeID() ) < std::type_index( rhs.TypeID() );
342bool helperBijectiveLessS(
integer selfVal,
const Box& selfType,
const Box& rhs )
344 if( rhs.IsSignedIntegral () )
return selfVal < rhs.UnboxSignedIntegral () ;
345 if( rhs.IsUnsignedIntegral() )
return selfVal <
integer(rhs.UnboxUnsignedIntegral());
346 if( rhs.IsFloatingPoint () )
return double( selfVal ) < rhs.UnboxFloatingPoint () ;
349 return std::type_index( selfType.TypeID() ) < std::type_index( rhs.TypeID() );
352bool helperBijectiveLessU(
uinteger selfVal,
const Box& selfType,
const Box& rhs )
354 if( rhs.IsSignedIntegral () )
return selfVal <
uinteger(rhs.UnboxSignedIntegral ());
355 if( rhs.IsUnsignedIntegral() )
return selfVal < rhs.UnboxUnsignedIntegral() ;
356 if( rhs.IsFloatingPoint () )
return double(selfVal) < rhs.UnboxFloatingPoint () ;
359 return std::type_index( selfType.TypeID() ) < std::type_index( rhs.TypeID() );
362bool FIsLess_int8_t (
const Box& self,
const Box& rhs ) {
return helperBijectiveLessS(
integer( self.Unbox< int8_t >() ), self, rhs ); }
363bool FIsLess_int16_t (
const Box& self,
const Box& rhs ) {
return helperBijectiveLessS(
integer( self.Unbox< int16_t >() ), self, rhs ); }
364bool FIsLess_int32_t (
const Box& self,
const Box& rhs ) {
return helperBijectiveLessS(
integer( self.Unbox< int32_t >() ), self, rhs ); }
365bool FIsLess_int64_t (
const Box& self,
const Box& rhs ) {
return helperBijectiveLessS(
integer( self.Unbox< int64_t >() ), self, rhs ); }
366bool FIsLess_intGap_t (
const Box& self,
const Box& rhs ) {
return helperBijectiveLessS(
integer( self.Unbox<
intGap_t>() ), self, rhs ); }
368bool FIsLess_uint8_t (
const Box& self,
const Box& rhs ) {
return helperBijectiveLessU(
uinteger( self.Unbox<uint8_t >() ), self, rhs ); }
369bool FIsLess_uint16_t (
const Box& self,
const Box& rhs ) {
return helperBijectiveLessU(
uinteger( self.Unbox<uint16_t >() ), self, rhs ); }
370bool FIsLess_uint32_t (
const Box& self,
const Box& rhs ) {
return helperBijectiveLessU(
uinteger( self.Unbox<uint32_t >() ), self, rhs ); }
371bool FIsLess_uint64_t (
const Box& self,
const Box& rhs ) {
return helperBijectiveLessU(
uinteger( self.Unbox<uint64_t >() ), self, rhs ); }
372bool FIsLess_uintGap_t(
const Box& self,
const Box& rhs ) {
return helperBijectiveLessU(
uinteger( self.Unbox<
uintGap_t>() ), self, rhs ); }
376bool FIsLess_char(
const Box& self,
const Box& rhs )
378 if( rhs.IsCharacter () )
379 return self.UnboxCharacter() < rhs.UnboxCharacter () ;
381 return std::type_index( self.TypeID() ) < std::type_index( rhs.TypeID() );
386bool FIsLess_double(
const Box& self,
const Box& rhs )
388 double lhs= self.Unbox<
double>();
389 if( rhs.IsFloatingPoint () )
return lhs < rhs.UnboxFloatingPoint () ;
390 if( rhs.IsSignedIntegral () )
return lhs < double( rhs.UnboxSignedIntegral () );
391 if( rhs.IsUnsignedIntegral() )
return lhs < double( rhs.UnboxUnsignedIntegral() );
393 return std::type_index( self.TypeID() ) < std::type_index( rhs.TypeID() );
396#if ALIB_FEAT_BOXING_BIJECTIVE_FLOATS
397 bool FIsLess_float(
const Box& self,
const Box& rhs )
399 float lhs= self.Unbox<
float>();
400 if( rhs.IsType<
float >() )
return lhs < rhs.Unbox<
float >() ;
401 if( rhs.IsType<
double >() )
return lhs < float( rhs.Unbox<
double>() );
402 if( rhs.IsSignedIntegral () )
return lhs < float( rhs.UnboxSignedIntegral () );
403 if( rhs.IsUnsignedIntegral() )
return lhs < float( rhs.UnboxUnsignedIntegral() );
405 return std::type_index( self.TypeID() ) < std::type_index( rhs.TypeID() );
415 if ( !self.IsArray() || self.UnboxLength() == 0)
420 if( src==
nullptr || placeHolder.Integrals.Array[1] < 0 )
423 size_t alignment= self.ArrayElementSize();
424 if( alignment >
sizeof(std::ptrdiff_t) )
425 alignment=
sizeof(std::ptrdiff_t);
428 placeHolder.SetPointer( memory().Alloc( self.ArrayElementSize() * placeHolder.Integrals.UArray[1],
430 memcpy( placeHolder.GetPointer<
char>(), src, self.ArrayElementSize() * placeHolder.Integrals.UArray[1] );
435bool FIsTrue_Default(
const Box& self )
438 return self.UnboxLength() != 0;
441 unsigned int usedLen= self.GetPlaceholderUsageLength();
446 return ( self.Data().Integrals.UArray[0]
447 & ((Bit1 << (usedLen * 8) )- 1) ) != 0;
450 if( self.Data().Integrals.UArray[0] != 0 )
459 return ( self.Data().Integrals.UArray[1]
460 & ((Bit1 << (usedLen -
sizeof(
uinteger)) * 8 )- 1) ) != 0;
463 return self.Data().Integrals.UArray[1] != 0;
468template<
typename TChar>
469bool FIsLess_TChar_arr(
const Box& lhs,
const Box& rhs )
471 if( rhs.IsArrayOf<TChar>() )
472 return lhs.Unbox<strings::TString<TChar>>() < rhs.Unbox<strings::TString<TChar>>();
474 return std::type_index( lhs.TypeID() ) < std::type_index(rhs.TypeID() );
478template<
typename TChar,
typename TAllocator>
479void FAppend_Default(
const Box& self, strings::TAString<TChar,TAllocator>& target)
481 if( self.IsPointer() )
485 << strings::THex<TChar>( self.Data().Integrals.UArray[0] )
492 target <<
ALIB_REL_DBG(
"EnumType", self.TypeID() ) <<
'(' << self.Data().Integrals.Array[0] <<
')';
498 target <<
ALIB_REL_DBG(
"ArrayType", self.ElementTypeID() ) <<
'[' << self.UnboxLength() <<
']';
503 target <<
ALIB_REL_DBG(
"ValueType", self.TypeID() ) <<
"(Size: " << self.GetPlaceholderUsageLength() <<
" bytes)";
507template<
typename TCharSrc,
typename TChar,
typename TAllocator>
508void FAppend_TcharArr(
const Box& box, strings::TAString<TChar,TAllocator>& target )
510 target.template Append<NC>( box.UnboxArray<TCharSrc>(), box.UnboxLength() );
525#if ALIB_DEBUG && !DOXYGEN
526namespace{
unsigned int initFlag= 0; }
530 ALIB_ASSERT_ERROR( initFlag == 0x92A3EF61,
"BOXING",
"Not initialized when calling shutdown." )
538 ALIB_ASSERT_ERROR( initFlag == 0,
"BOXING",
"This method must not be invoked twice." )
545 debug::LongDoubleTrueLengthSet();
546 debug::LONGDOUBLE_WRITE_TEST_MEM[0]= 0.0L;
548 "Platform not supported. SizeTraits<long double> contains wrong size" )
560DOX_MARKER([DOX_BOXING_OPTIMIZE_REGISTER_1])
562DOX_MARKER([DOX_BOXING_OPTIMIZE_REGISTER_1])
564 #if !ALIB_FEAT_BOXING_BIJECTIVE_INTEGRALS
576 #if ALIB_SIZEOF_INTEGER == 8
583 #if ALIB_SIZEOF_LONGDOUBLE_REPORTED <= 2 * ALIB_SIZEOF_INTEGER
586 #if ALIB_FEAT_BOXING_BIJECTIVE_FLOATS
591 #if !ALIB_FEAT_BOXING_BIJECTIVE_CHARACTERS
601DOX_MARKER([DOX_BOXING_OPTIMIZE_REGISTER_2])
603DOX_MARKER([DOX_BOXING_OPTIMIZE_REGISTER_2])
640 #if !ALIB_SINGLE_THREADED
713 #if !ALIB_FEAT_BOXING_BIJECTIVE_INTEGRALS
729 #if !ALIB_FEAT_BOXING_BIJECTIVE_CHARACTERS
740 #if ALIB_FEAT_BOXING_BIJECTIVE_FLOATS
747 #if !ALIB_FEAT_BOXING_BIJECTIVE_INTEGRALS
763 #if !ALIB_FEAT_BOXING_BIJECTIVE_CHARACTERS
774 #if ALIB_FEAT_BOXING_BIJECTIVE_FLOATS
784 #if !ALIB_FEAT_BOXING_BIJECTIVE_INTEGRALS
800 #if ALIB_FEAT_BOXING_BIJECTIVE_FLOATS
807 #if !ALIB_FEAT_BOXING_BIJECTIVE_CHARACTERS
822 #if !ALIB_FEAT_BOXING_BIJECTIVE_INTEGRALS
838 #if ALIB_FEAT_BOXING_BIJECTIVE_FLOATS
844 #if !ALIB_FEAT_BOXING_BIJECTIVE_CHARACTERS
872 #if !ALIB_FEAT_BOXING_BIJECTIVE_CHARACTERS
884 #if !ALIB_FEAT_BOXING_BIJECTIVE_INTEGRALS
914 #if ALIB_FEAT_BOXING_BIJECTIVE_FLOATS
918 if constexpr (
sizeof(
long double) <=
sizeof(
Placeholder) )
990 #if ALIB_EXT_LIB_THREADS_AVAILABLE
1008 #if ALIB_SYSTEM && ALIB_EXCEPTIONS
1023 #if ALIB_EXPRESSIONS
1039 #if !ALIB_SINGLE_THREADED
1042 #if ALIB_ENUMRECORDS
1056#if ALIB_DEBUG_BOXING
1064 assert( initFlag == 0x92A3EF61 );
1069 if( vtable==
nullptr)
1072 if( increaseUsageCounter )
1079 ALIB_ERROR(
"BOXING",
"Static VTable of mapped type <{}> not registered.\n"
1080 "Use Macro ALIB_BOXING_BOOTSTRAP_VTABLE_DBG_REGISTER with bootstrapping.",
1083 ALIB_ERROR(
"BOXING",
"Static VTable of mapped type <{}[]> not registered.\n"
1084 "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)
constexpr unsigned int SizeTraits
void BootstrapRegister(typename TFDecl::Signature function)
int Compare(const TChar *lhs, const TChar *rhs, integer cmpLength)
void FFormat_File(const alib::Box &box, const alib::String &formatSpec, alib::NumberFormat &nf, alib::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.
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