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