ALib C++ Framework
by
Library Version: 2605 R0
Documentation generated by doxygen
Loading...
Searching...
No Matches
boxes.cpp
1
2//##################################################################################################
3// static assertions for the platform
4//##################################################################################################
5static_assert( sizeof(alib::integer ) == sizeof(alib::uinteger ), "Error in ALib type definitions" );
6static_assert( sizeof(alib::integer ) == sizeof(std::size_t ), "Error in ALib type definitions" );
7static_assert(std::is_signed< alib::integer>::value == std::is_signed<std::ptrdiff_t >::value, "Error in ALib type definitions" );
8static_assert(std::is_signed< alib::integer>::value != std::is_signed<std::size_t >::value, "Error in ALib type definitions" );
9static_assert(std::is_signed<alib::uinteger>::value == std::is_signed<std::size_t >::value, "Error in ALib type definitions" );
10static_assert(std::is_signed<alib::uinteger>::value != std::is_signed<std::ptrdiff_t >::value, "Error in ALib type definitions" );
11
12
13
14namespace alib { namespace boxing {
15
16#if ALIB_DEBUG && !DOXYGEN
17namespace detail {
18 // This is used by boxing::Bootstrap to do runtime-check for compatibility of boxing
19 // and long double values.
20 // It was put here to prevent the compiler to optimize and remove the code.
21 extern long double LONGDOUBLE_WRITE_TEST_MEM[2];
22extern void dbgLongDoubleTrueLengthSet();
23extern bool dbgLongDoubleTrueLengthTest();
24}
25#endif
26
27#if !DOXYGEN
28
29namespace {
30integer flattenCount(const Box* boxArray, integer length) {
31 integer ctdFlattened= 0;
32 for( integer i= 0; i < length ; ++i ) {
33 const Box& box= boxArray[i];
34
35 if( box.IsType<boxing::TBoxes<lang::HeapAllocator>*>() ) {
36 const auto* boxes= box.Unbox<boxing::TBoxes<lang::HeapAllocator>*>();
37 ctdFlattened+= flattenCount( boxes->data(), integer(boxes->size()) );
38 continue;
39 }
40 #if ALIB_MONOMEM
41 if( box.IsType<boxing::TBoxes<MonoAllocator>*>() ) {
42 const auto* boxes= box.Unbox<boxing::TBoxes<MonoAllocator>*>();
43 ctdFlattened+= flattenCount( boxes->data(), integer(boxes->size()) );
44 continue;
45 }
46 if( box.IsType<boxing::TBoxes<PoolAllocator>*>() ) {
47 const auto* boxes= box.Unbox<boxing::TBoxes<PoolAllocator>*>();
48 ctdFlattened+= flattenCount( boxes->data(), integer(boxes->size()) );
49 continue;
50 }
51 #endif
52
53 if( box.IsArrayOf<Box>() ) {
54 ctdFlattened+= flattenCount( box.UnboxArray<Box>(), box.UnboxLength() );
55 continue;
56 }
57
58 ++ctdFlattened;
59 }
60
61 return ctdFlattened;
62}
63
64template<typename TAllocator>
65void flattenInsert(typename TBoxes<TAllocator>::iterator& it, const Box* boxArray, integer length) {
66 for( integer i= 0; i < length ; ++i ) {
67 const Box& box= boxArray[i];
68
69 if( box.IsType<boxing::TBoxes<lang::HeapAllocator>*>() ) {
70 const auto* boxes= box.Unbox<boxing::TBoxes<lang::HeapAllocator>*>();
71 flattenInsert<TAllocator>( it, boxes->data(), integer(boxes->size()) );
72 continue;
73 }
74 #if ALIB_MONOMEM
75 if( box.IsType<boxing::TBoxes<MonoAllocator>*>() ) {
76 const auto* boxes= box.Unbox<boxing::TBoxes<MonoAllocator>*>();
77 flattenInsert<TAllocator>( it, boxes->data(), integer(boxes->size()) );
78 continue;
79 }
80 if( box.IsType<boxing::TBoxes<PoolAllocator>*>() ) {
81 const auto* boxes= box.Unbox<boxing::TBoxes<PoolAllocator>*>();
82 flattenInsert<TAllocator>( it, boxes->data(), integer(boxes->size()) );
83 continue;
84 }
85 #endif
86
87 if( box.IsArrayOf<Box>() ) {
88 flattenInsert<TAllocator>( it, box.UnboxArray<Box>(), box.UnboxLength() );
89 continue;
90 }
91
92 new( &*it ) Box( box );
93 ++it;
94} }
95
96} // anonymous namespace
97
98
99template<typename TAllocator>
100void TBoxes<TAllocator>::AddArray( const Box* boxArray, integer length ) {
101 // 1. Count the number of boxes if "recursively flattened"
102 integer ctdFlattened= flattenCount( boxArray, length );
103
104 // 2. create space in vector
105 auto it= vectorBase::insert(vectorBase::end(), size_t(ctdFlattened), Box() );
106
107 // 3. insert recursively all boxes found (flatten)
108 flattenInsert<TAllocator>( it, boxArray, length);
109
110 ALIB_ASSERT( it == vectorBase::end(), "BOXING" )
111}
112
113template ALIB_DLL void TBoxes< lang::HeapAllocator>::AddArray( const Box* boxArray, integer length );
114#if ALIB_MONOMEM
115template ALIB_DLL void TBoxes<MonoAllocator>::AddArray( const Box* boxArray, integer length );
116#endif
117
118
119#endif // #if DOXYGEN
120
121}} // namespace [alib::boxing]
#define ALIB_DLL
#define ALIB_ASSERT(cond, domain)
integer UnboxLength() const
Definition box.hpp:821
void AddArray(const Box *boxArray, integer length)
This namespace implements internals of namespace #"alib::boxing;2".
Definition vtable.cpp:1
DOXYGEN.
Definition box.cpp:17
Definition alox.cpp:14
lang::integer integer
Type alias in namespace #"%alib".
Definition integers.hpp:149
boxing::Box Box
Type alias in namespace #"%alib".
Definition box.hpp:1128
lang::uinteger uinteger
Type alias in namespace #"%alib".
Definition integers.hpp:152