ALib C++ Library
Library Version: 2510 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{
141 return IsType< double>()
142 #if ALIB_FEAT_BOXING_BIJECTIVE_FLOATS
143 || IsType< float >()
144 #endif
145 #if ALIB_SIZEOF_LONGDOUBLE_REPORTED <= 2 * ALIB_SIZEOF_INTEGER
147 #endif
148 ;
149}
150
152{
153 #if ALIB_FEAT_BOXING_BIJECTIVE_FLOATS
154 if( IsType< float >() ) return double( Unbox<float >() );
155 #endif
156
157 #if ALIB_SIZEOF_LONGDOUBLE_REPORTED <= 2 * ALIB_SIZEOF_INTEGER
158 if( IsType<long double>() ) return double( Unbox<long double>() );
159 #endif
160
161 return Unbox<double>();
162}
163
164#if !DOXYGEN
165 Box::operator bool() const { return Call<FIsTrue >(); }
166bool Box::IsNotNull () const { return Call<FIsNotNull >(); }
167size_t Box::Hashcode () const { return Call<FHashcode >(); }
169void Box::Clone( MonoAllocator& memory) { Call<FClone >( memory ); } )
170#endif
171
172// #################################################################################################
173// Non-anonymous functions
174// #################################################################################################
176{
177 return false;
178}
179
180}} // namespace [alib::boxing]
181
182using namespace alib::boxing;
183bool Box::operator==(const Box& rhs) const { return Call<FEquals>( rhs ); }
184bool Box::operator< (const Box& rhs) const { return Call<FIsLess>( rhs ); }
185bool Box::operator<=(const Box& rhs) const { return Call<FIsLess>( rhs ) || Call<FEquals>( rhs ); }
186bool Box::operator> (const Box& rhs) const { return !Call<FIsLess>( rhs ) && !Call<FEquals>( rhs ); }
187
188
ALIB_DLL bool operator>(Box const &rhs) const
Definition box.cpp:186
uinteger UnboxUnsignedIntegral() const
Definition box.inl:501
bool IsUnsignedIntegral() const
Definition box.inl:470
ALIB_DLL double UnboxFloatingPoint() const
Definition box.cpp:151
ALIB_DLL bool IsNotNull() const
integer UnboxSignedIntegral() const
Definition box.inl:484
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:1039
bool IsType() const
TValue Unbox() const
Definition box.inl:635
ALIB_DLL bool operator<(Box const &rhs) const
Definition box.cpp:184
bool IsCharacter() const
Definition box.inl:524
ALIB_DLL bool operator==(Box const &rhs) const
Definition box.cpp:183
bool IsSignedIntegral() const
Definition box.inl:455
ALIB_DLL bool operator<=(Box const &rhs) const
Definition box.cpp:185
wchar UnboxCharacter() const
Definition box.inl:539
Box() noexcept
Definition box.inl:225
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:1216
lang::uinteger uinteger
Type alias in namespace alib.
Definition integers.inl:152
static ALIB_DLL bool ConstantTrue(const Box &)
Definition box.cpp:175