ALib C++ Library
Library Version: 2511 R0
Documentation generated by doxygen
Loading...
Searching...
No Matches
functiondefs.inl.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-2025 A-Worx GmbH, Germany.
6/// Published under \ref mainpage_license "Boost Software License".
7//==================================================================================================
8ALIB_EXPORT namespace alib { namespace boxing {
9
10#if !DOXYGEN
11
13
14template<typename TComparable>
15requires (!std::is_pointer_v<TComparable> )
16bool FEquals::ComparableTypes( const Box& self, const Box& rhsBox ) {
17 if( !rhsBox.IsType<TComparable >() )
18 return false;
19
20 return self.Unbox<TComparable>() == rhsBox.Unbox<TComparable>();
21}
22
23template<typename TComparableP>
24requires (std::is_pointer_v<TComparableP>)
25bool FEquals::ComparableTypes( const Box& self, const Box& rhsBox ) {
26 if( !rhsBox.IsType<TComparableP>() )
27 return false;
28
29 auto lhs= self .Unbox<TComparableP>();
30 auto rhs= rhsBox.Unbox<TComparableP>();
31 if( lhs == nullptr )
32 return rhs == nullptr;
33 if( rhs == nullptr )
34 return false;
35
36 return *lhs == *rhs;
37}
38
39
40template<typename TComparable>
41requires (!std::is_pointer_v<TComparable>)
42bool FIsLess::ComparableTypes( const Box& self, const Box& rhsBox ) {
43 if( !rhsBox.IsType<TComparable >() )
44 return std::type_index( self.TypeID() ) < std::type_index( rhsBox.TypeID() );
45
46 return self.Unbox<TComparable>() < rhsBox.Unbox<TComparable>();
47}
48
49template<typename TComparableP>
50requires (std::is_pointer_v<TComparableP>)
51bool FIsLess::ComparableTypes( const Box& self, const Box& rhsBox ) {
52 if( !rhsBox.IsType<TComparableP>() )
53 return false;
54
55 auto lhs= self .Unbox<TComparableP>();
56 auto rhs= rhsBox.Unbox<TComparableP>();
57 if( lhs == nullptr )
58 return rhs != nullptr;
59 if( rhs == nullptr )
60 return false;
61
62 return *lhs < *rhs;
63}
64
65template<size_t N>
66size_t FHashcode::UsePlaceholderBytes( const Box& self ) {
68 ALIB_ASSERT_ERROR(N == self.GetPlaceholderUsageLength(), "BOXING",
69 "Hash function registered with type of wrong usage length")
70
71 size_t result= std::size_t(0x52a6937UL) - (N * 0x387e)
72 + std::size_t( self.TypeID().hash_code() );
73
74 constexpr uinteger Bit1= uinteger( 1 );
75
76 // smaller than first "word"
77 if constexpr( N < sizeof( uinteger ) )
78 return size_t( ( self.Data().Integrals.UArray[0]
79 & ((Bit1 << (N * 8) )- 1) ) * 92334534 )
80 + result;
81
82 // add first word
83 result+= self.Data().Integrals.UArray[0] * 52424735;
84
85 if constexpr ( N == sizeof(uinteger) )
86 return result;
87
88 // tests if smaller than second "word"
89 else if constexpr ( N - sizeof( uinteger ) < sizeof( uinteger ) ) {
90 return size_t( ( self.Data().Integrals.UArray[1]
91 & ((Bit1 << ((N - sizeof(uinteger)) * 8) )- 1) ) * 892112 )
92 + result;
93 }
94 else
95 return result + self.Data().Integrals.UArray[1] * 485923;
97}
98
99#if ALIB_STRINGS
100template<typename TChar, typename TAllocator>
101template<typename TAppendable>
102requires( !std::is_pointer_v<TAppendable> )
104 strings::TAString<TChar, TAllocator>& target ) {
105 target.template Append<NC>( self.Unbox<TAppendable>() );
106}
107
108template<typename TChar, typename TAllocator>
109template<typename TAppendable>
110requires( std::is_pointer_v<TAppendable> )
112 strings::TAString<TChar, TAllocator>& target ) {
113 auto pointer= self.Unbox<TAppendable>();
114 if( pointer )
115 target.template Append<NC>( *pointer );
116 else {
117 #if ALIB_DEBUG
118 target << self.TypeID() <<"(nullptr)";
119 #endif
120 target << "(nullptr)";
121} }
122
123// Definition of FAppend::WrappedAppendable()
124template<typename TChar, typename TAllocator>
125template<typename TAppendable>
127 strings::TAString<TChar, TAllocator>& target) {
128 target.template _<NC>( self.Unbox<std::reference_wrapper<TAppendable>>().get() );
129}
130
131#if !ALIB_SINGLE_THREADED
132inline void FAppend_thread( const boxing::Box& self,
133 strings::TAString<character,lang::HeapAllocator>& target ) {
134 const Thread* src= self.Unbox<Thread*>();
135 if ( src ) target << *src;
136 else target << "nullptr";
137}
138#endif // !ALIB_SINGLE_THREADED
139#endif // ALIB_STRINGS
140
141
142}} // namespace [alib::boxing]
143
144#include "ALib.Lang.CIMethods.H"
145
146#endif // !DOXYGEN
#define ALIB_WARNINGS_IGNORE_INTEGRAL_CONSTANT_OVERFLOW
Definition alib.inl:699
#define ALIB_WARNINGS_RESTORE
Definition alib.inl:719
#define ALIB_EXPORT
Definition alib.inl:497
#define ALIB_ASSERT_ERROR(cond, domain,...)
Definition alib.inl:1066
threads::Thread Thread
Type alias in namespace alib.
Definition thread.inl:387
lang::uinteger uinteger
Type alias in namespace alib.
Definition integers.inl:152
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 bool ComparableTypes(const Box &self, const Box &rhs)