-
Notifications
You must be signed in to change notification settings - Fork 0
/
array.cpp
executable file
·129 lines (101 loc) · 2.48 KB
/
array.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
#include "array.h"
#include "memoryManager.h"
#include "platter.h"
#include "jumpTable.h"
#include "nativeCode.h"
#include <boost/assert.hpp>
#include <boost/type_traits/alignment_of.hpp>
#include <cstring>
using namespace boost;
array::array(size_t size) throw()
: _size(size)
, _flags(0)
, _nativeCode(nullptr)
{ }
array::~array() throw()
{
BOOST_ASSERT(_nativeCode == nullptr);
}
array * array::create(memoryManager & mm, size_t size)
{
return createInt(mm, size, true);
}
void array::destroy(memoryManager & mm) throw()
{
if (_nativeCode)
{
_nativeCode->destroy(mm);
_nativeCode = nullptr;
}
array::~array();
mm.release(this);
}
array * array::clone(memoryManager & mm)
{
array * res = createInt(mm, _size, false);
memcpy(res->platters(), platters(), _size * sizeof(platter));
return res;
}
size_t array::size() const
{
return _size;
}
bool array::dirty() const
{
return (_flags & flag::dirty) != 0;
}
void array::dirty(bool v)
{
if (v)
_flags |= flag::dirty;
else
_flags &= ~flag::dirty;
}
const platter * array::platters() const
{
return reinterpret_cast<const platter *>
(reinterpret_cast<const char *>(this) + _plattersOffset);
}
platter * array::platters()
{
return reinterpret_cast<platter *>
(reinterpret_cast<char *>(this) + _plattersOffset);
}
const platter & array::operator[](size_t i) const
{
return platters()[i];
}
platter & array::operator[](size_t i)
{
return platters()[i];
}
jumpTable * array::jumpTable()
{
return _nativeCode ? _nativeCode->jumpTable() : nullptr;
}
const jumpTable * array::jumpTable() const
{
return _nativeCode ? _nativeCode->jumpTable() : nullptr;
}
const nativeCode * array::nativeCode() const
{
return _nativeCode;
}
nativeCode * array::nativeCode()
{
return _nativeCode;
}
array * array::createInt(memoryManager & mm, size_t size, bool zero)
{
size_t totalSize = _plattersOffset + size * sizeof(platter);
void * p = mm.alloc(totalSize, zero);
/*
* See nativeCode::craete(...) implementation for an exmplanation why
* explicit '::' is required here.
*/
return ::new(p) array(size);
}
const size_t array::_plattersOffset =
(sizeof(array) + alignment_of<platter>::value - 1)
/ alignment_of<platter>::value
* alignment_of<platter>::value;