-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathpz_array.h
More file actions
61 lines (50 loc) · 1.16 KB
/
pz_array.h
File metadata and controls
61 lines (50 loc) · 1.16 KB
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
/*
* Plasma GC-compatible bounds-checked array
* vim: ts=4 sw=4 et
*
* Copyright (C) Plasma Team
* Distributed under the terms of the MIT license, see ../LICENSE.code
*/
#ifndef PZ_ARRAY_H
#define PZ_ARRAY_H
#include "string.h"
#include "pz_gc_util.h"
namespace pz {
template <typename T>
class Array : public GCNew
{
private:
/*
* The array data is stored seperately. Array types can be
* passed-by-value and easilly embeded within other values.
*/
size_t m_len;
T * m_data;
public:
Array(NoGCScope & gc, size_t len) : m_len(len)
{
assert(m_len > 0);
m_data = new (gc) T[len];
}
const T & operator[](size_t offset) const
{
assert(offset < m_len);
return m_data[offset];
}
T & operator[](size_t offset)
{
assert(offset < m_len);
return m_data[offset];
}
void zerofill()
{
memset(m_data, 0, sizeof(T) * m_len);
}
/*
* These are deleted until they're needed (and can be tested) later.
*/
Array(const Array &) = delete;
void operator=(const Array &) = delete;
};
} // namespace pz
#endif /* ! PZ_ARRAY_H */