ALib C++ Library
Library Version: 2511 R0
Documentation generated by doxygen
Loading...
Searching...
No Matches
box.cpp
1//##################################################################################################
2// ALib C++ Library
3//
4// Copyright 2013-2025 A-Worx GmbH, Germany
5// Published under 'Boost Software License' (a free software license, see LICENSE.txt)
6//##################################################################################################
7#include "alib_precompile.hpp"
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"
10#endif
11#if ALIB_C20_MODULES
12 module;
13#endif
14//========================================= Global Fragment ========================================
16
17#include <cmath>
18#include <functional>
19#include <cstring>
20#include <typeindex>
21
22//============================================== Module ============================================
23#if ALIB_C20_MODULES
24 module ALib.Boxing;
25#else
26#if ALIB_MONOMEM && ALIB_CONTAINERS
27# include "ALib.Monomem.H"
28#endif
29# include "ALib.Boxing.H"
30#if ALIB_MONOMEM && ALIB_CONTAINERS
31# include "ALib.Monomem.H"
32#endif
33#endif
34# include "ALib.Lang.H"
35//========================================== Implementation ========================================
36#if ALIB_STRINGS
37ALIB_BOXING_VTABLE_DEFINE( std::reference_wrapper<alib::strings::TAString<nchar ALIB_COMMA lang::HeapAllocator>>, vt_alib_wrapped_tanstring )
38ALIB_BOXING_VTABLE_DEFINE( std::reference_wrapper<alib::strings::TAString<wchar ALIB_COMMA lang::HeapAllocator>>, vt_alib_wrapped_tawstring )
39ALIB_BOXING_VTABLE_DEFINE( std::reference_wrapper<alib::strings::TAString<xchar ALIB_COMMA lang::HeapAllocator>>, vt_alib_wrapped_taxstring )
41#endif
42
43namespace alib {
44
45//==================================================================================================
46/// This is the reference documentation of sub-namespace \b boxing of the \aliblink, which
47/// holds types of library module \alib_boxing.
48///
49/// Extensive documentation for this module is provided with
50/// \ref alib_mod_boxing "ALib Module Boxing - Programmer's Manual".
51//==================================================================================================
52namespace boxing {
53
54//##################################################################################################
55//##################################################################################################
56// class Box
57//##################################################################################################
58//##################################################################################################
59
60#if ALIB_FEAT_BOXING_BIJECTIVE_INTEGRALS
61 bool Box::IsSignedIntegral() const
62 {
63 #if ALIB_SIZEOF_INTEGER == 8
64 return IsType< int64_t >()
66 #else
67 return IsType< int32_t >()
69 #endif
73 }
74
75 bool Box::IsUnsignedIntegral() const
76 {
77 #if ALIB_SIZEOF_INTEGER == 8
78 return IsType<uint64_t >()
80 #else
81 return IsType<uint32_t >()
83 #endif
87 }
88
90 {
91 #if ALIB_SIZEOF_INTEGER == 8
92 return IsType< int64_t >() ? ( Unbox< int64_t >() )
93 : IsType< int32_t >() ? integer( Unbox< int32_t >() )
94 #else
95 return IsType< int32_t >() ? ( Unbox< int32_t >() )
96 : IsType< int64_t >() ? integer( Unbox< int64_t >() )
97 #endif
98 : IsType< int8_t >() ? integer( Unbox< int8_t >() )
99 : IsType< int16_t >() ? integer( Unbox< int16_t >() )
100 : integer( Unbox< intGap_t>() );
101 }
102
103
105 {
106 #if ALIB_SIZEOF_INTEGER == 8
107 return IsType<uint64_t >() ? ( Unbox<uint64_t >() )
108 : IsType<uint32_t >() ? uinteger( Unbox<uint32_t >() )
109 #else
110 return IsType<uint32_t >() ? ( Unbox<uint32_t >() )
111 : IsType<uint64_t >() ? uinteger( Unbox<uint64_t >() )
112 #endif
113 : IsType<uint8_t >() ? uinteger( Unbox<uint8_t >() )
114 : IsType<uint16_t >() ? uinteger( Unbox<uint16_t >() )
115 : uinteger( Unbox<uintGap_t>() );
116 }
117#endif
118
119#if ALIB_FEAT_BOXING_BIJECTIVE_CHARACTERS
120bool Box::IsCharacter() const
121{
122 return IsType<char >()
126 || IsType<char32_t>();
127}
128
130{
131 return IsType<char >() ? wchar( Unbox<char >() )
132 : IsType<char8_t >() ? wchar( Unbox<char >() )
133 : IsType<wchar_t >() ? wchar( Unbox<wchar_t >() )
134 : IsType<char16_t>() ? wchar( Unbox<char16_t>() )
135 : wchar( Unbox<char32_t>() );
136}
137#endif
138
140 return IsType< double>()
141 #if ALIB_FEAT_BOXING_BIJECTIVE_FLOATS
142 || IsType< float >()
143 #endif
144 #if ALIB_SIZEOF_LONGDOUBLE_REPORTED <= 2 * ALIB_SIZEOF_INTEGER
146 #endif
147 ;
148}
149
151 #if ALIB_FEAT_BOXING_BIJECTIVE_FLOATS
152 if( IsType< float >() ) return double( Unbox<float >() );
153 #endif
154
155 #if ALIB_SIZEOF_LONGDOUBLE_REPORTED <= 2 * ALIB_SIZEOF_INTEGER
156 if( IsType<long double>() ) return double( Unbox<long double>() );
157 #endif
158
159 return Unbox<double>();
160}
161
162#if !DOXYGEN
163 Box::operator bool() const { return Call<FIsTrue >(); }
164bool Box::IsNotNull () const { return Call<FIsNotNull >(); }
165size_t Box::Hashcode () const { return Call<FHashcode >(); }
167void Box::Clone( MonoAllocator& memory) { Call<FClone >( memory ); } )
168#endif
169
170//##################################################################################################
171// Non-anonymous functions
172//##################################################################################################
173bool FIsNotNull::ConstantTrue( const alib::Box & ) { return false; }
174
175}} // namespace [alib::boxing]
176
177using namespace alib::boxing;
178bool Box::operator==(const Box& rhs) const { return Call<FEquals>(rhs); }
179bool Box::operator< (const Box& rhs) const { return Call<FIsLess>(rhs); }
180bool Box::operator<=(const Box& rhs) const { return Call<FIsLess>(rhs) || Call<FEquals>(rhs); }
181bool Box::operator> (const Box& rhs) const { return !Call<FIsLess>(rhs) && !Call<FEquals>(rhs); }
ALIB_DLL bool operator>(Box const &rhs) const
Definition box.cpp:181
uinteger UnboxUnsignedIntegral() const
Definition box.inl:483
bool IsUnsignedIntegral() const
Definition box.inl:459
ALIB_DLL double UnboxFloatingPoint() const
Definition box.cpp:150
ALIB_DLL bool IsNotNull() const
integer UnboxSignedIntegral() const
Definition box.inl:471
bool IsFloatingPoint() const
Definition box.cpp:139
ALIB_DLL void Clone(MonoAllocator &memory)
decltype(std::declval< typename TFDecl::Signature >()(std::declval< Box & >(), std::declval< TArgs >()...)) Call(TArgs &&... args) const
Definition box.inl:985
bool IsType() const
TValue Unbox() const
Definition box.inl:595
ALIB_DLL bool operator<(Box const &rhs) const
Definition box.cpp:179
bool IsCharacter() const
Definition box.inl:503
ALIB_DLL bool operator==(Box const &rhs) const
Definition box.cpp:178
bool IsSignedIntegral() const
Definition box.inl:446
ALIB_DLL bool operator<=(Box const &rhs) const
Definition box.cpp:180
wchar UnboxCharacter() const
Definition box.inl:515
Box() noexcept
Definition box.inl:224
ALIB_DLL size_t Hashcode() const
#define ALIB_BOXING_VTABLE_DEFINE(TMapped, Identifier)
#define IF_ALIB_MONOMEM(...)
Definition alib.inl:361
lang::intGap_t intGap_t
Type alias in namespace alib.
Definition integers.inl:155
characters::wchar wchar
Type alias in namespace alib.
lang::integer integer
Type alias in namespace alib.
Definition integers.inl:149
monomem::TMonoAllocator< lang::HeapAllocator > MonoAllocator
lang::uintGap_t uintGap_t
Type alias in namespace alib.
Definition integers.inl:158
boxing::Box Box
Type alias in namespace alib.
Definition box.inl:1149
lang::uinteger uinteger
Type alias in namespace alib.
Definition integers.inl:152
static ALIB_DLL bool ConstantTrue(const Box &)
Definition box.cpp:173