ALib C++ Library
Library Version: 2402 R1
Documentation generated by doxygen
Loading...
Searching...
No Matches
functiondefs.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_FUNCTIONDEFS
9#define HPP_ALIB_BOXING_FUNCTIONDEFS 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
15namespace alib { namespace boxing {
16
17#if !defined(ALIB_DOX)
18
19 template<typename TComparable>
20ATMP_T_IF(bool, !ATMP_IS_PTR(TComparable) ) FEquals::ComparableTypes( const Box& self, const Box& rhsBox )
21{
22 if( !rhsBox.IsType<TComparable >() )
23 return false;
24
25 return self.Unbox<TComparable>() == rhsBox.Unbox<TComparable>();
26}
27
28template<typename TComparableP>
29ATMP_T_IF(bool, ATMP_IS_PTR(TComparableP) ) FEquals::ComparableTypes( const Box& self, const Box& rhsBox )
30{
31 if( !rhsBox.IsType<TComparableP>() )
32 return false;
33
34 auto lhs= self .Unbox<TComparableP>();
35 auto rhs= rhsBox.Unbox<TComparableP>();
36 if( lhs == nullptr )
37 return rhs == nullptr;
38 if( rhs == nullptr )
39 return false;
40
41 return *lhs == *rhs;
42}
43
44
45template<typename TComparable>
46ATMP_T_IF(bool, !ATMP_IS_PTR(TComparable) ) FIsLess::ComparableTypes( const Box& self, const Box& rhsBox )
47{
48 if( !rhsBox.IsType<TComparable >() )
49 return std::type_index( self.TypeID() ) < std::type_index( rhsBox.TypeID() );
50
51 return self.Unbox<TComparable>() < rhsBox.Unbox<TComparable>();
52}
53
54template<typename TComparableP>
55ATMP_T_IF(bool, ATMP_IS_PTR(TComparableP) ) FIsLess::ComparableTypes( const Box& self, const Box& rhsBox )
56{
57 if( !rhsBox.IsType<TComparableP>() )
58 return false;
59
60 auto lhs= self .Unbox<TComparableP>();
61 auto rhs= rhsBox.Unbox<TComparableP>();
62 if( lhs == nullptr )
63 return rhs != nullptr;
64 if( rhs == nullptr )
65 return false;
66
67 return *lhs < *rhs;
68}
69
70#endif // !defined(ALIB_DOX)
71
72template<size_t N>
74{
76 ALIB_ASSERT_ERROR(N == self.GetPlaceholderUsageLength(), "BOXING",
77 "Hash function registered with type of wrong usage length")
78
79 size_t result= std::size_t(0x52a6937UL) - (N * 0x387e)
80 + std::size_t( self.TypeID().hash_code() );
81
82 constexpr uinteger Bit1= static_cast<uinteger>( 1 );
83
84 // smaller than first "word"
85 if constexpr( N < sizeof( uinteger ) )
86 return static_cast<size_t>( ( self.Data().GetUInteger(0)
87 & ((Bit1 << (N * 8) )- 1) ) * 92334534 )
88 + result;
89
90 // add first word
91 result+= self.Data().GetUInteger(0) * 52424735;
92
93 if constexpr ( N == sizeof(uinteger) )
94 return result;
95
96 // tests if smaller than second "word"
97 else if constexpr ( N - sizeof( uinteger ) < sizeof( uinteger ) )
98 {
99 return static_cast<size_t>( ( self.Data().GetUInteger(1)
100 & ((Bit1 << ((N - sizeof(uinteger)) * 8) )- 1) ) * 892112 )
101 + result;
102 }
103 else
104 return result + self.Data().GetUInteger(1) * 485923;
106}
107
108#if ALIB_STRINGS && !defined(ALIB_DOX)
109template<typename TChar>
110template<typename TAppendable>
111ATMP_VOID_IF( !ATMP_IS_PTR(TAppendable) )
113{
114 target.template Append<false>( self.Unbox<TAppendable>() );
115}
116
117template<typename TChar>
118template<typename TAppendable>
119ATMP_VOID_IF( ATMP_IS_PTR(TAppendable) )
121{
122 auto pointer= self.Unbox<TAppendable>();
123 if( pointer )
124 target.template Append<false>( *pointer );
125 else
126 {
127 #if ALIB_DEBUG
128 target << self.TypeID() <<"(nullptr)";
129 #endif
130 target << "(nullptr)";
131 }
132
133}
134
135template<typename TChar>
136template<typename TAppendable>
137void FAppend<TChar>::WrappedAppendable( const Box& self, strings::TAString<TChar>& target)
138{
139 target.template _<false>( self.Unbox<std::reference_wrapper<TAppendable>>().get() );
140}
141#endif // defined(ALIB_DOX)
142}} // namespace [alib::boxing]
143
144#endif // HPP_ALIB_BOXING_FUNCTIONDEFS
unsigned int GetPlaceholderUsageLength() const
Definition box.inl:878
const std::type_info & TypeID() const
Definition box.inl:902
const Placeholder & Data() const
Definition box.inl:843
const TUnboxable Unbox() const
#define ALIB_WARNINGS_IGNORE_INTEGRAL_CONSTANT_OVERFLOW
Definition alib.hpp:699
#define ATMP_VOID_IF(Cond)
Definition tmp.hpp:52
#define ALIB_WARNINGS_RESTORE
Definition alib.hpp:715
#define ATMP_IS_PTR(T)
Definition tmp.hpp:27
#define ALIB_ASSERT_ERROR(cond,...)
Definition alib.hpp:984
#define ATMP_T_IF(T, Cond)
Definition tmp.hpp:53
Definition alib.cpp:57
lang::uinteger uinteger
Type alias in namespace alib.
Definition integers.hpp:289
boxing::Box Box
Type alias in namespace alib.
static void WrappedAppendable(const Box &self, strings::TAString< TChar > &target)
static void Appendable(const Box &self, strings::TAString< TChar > &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)
constexpr uinteger GetUInteger(int idx) const