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