Interface Documentation
Version: invalid
flecsi
topo
array_buffer.hh
Go to the documentation of this file.
1
/*
2
@@@@@@@@ @@ @@@@@@ @@@@@@@@ @@
3
/@@///// /@@ @@////@@ @@////// /@@
4
/@@ /@@ @@@@@ @@ // /@@ /@@
5
/@@@@@@@ /@@ @@///@@/@@ /@@@@@@@@@/@@
6
/@@//// /@@/@@@@@@@/@@ ////////@@/@@
7
/@@ /@@/@@//// //@@ @@ /@@/@@
8
/@@ @@@//@@@@@@ //@@@@@@ @@@@@@@@ /@@
9
// /// ////// ////// //////// //
10
11
Copyright (c) 2016, Los Alamos National Security, LLC
12
All rights reserved.
13
*/
14
#pragma once
15
18
#include "
flecsi/util/id.hh
"
19
20
namespace
flecsi
{
21
namespace
topo {
22
23
template
<
size_t
,
typename
>
24
class
domain_entity
;
25
26
template
<
typename
item_t>
27
struct
array_buffer_type
{
28
using
type = item_t *;
29
};
30
31
template
<
size_t
M,
typename
E>
32
struct
array_buffer_type
<
domain_entity
<M, E>> {
33
using
type = E *;
34
};
35
36
template
<
typename
item_t>
37
struct
array_buffer_type
<item_t *> {
38
using
type = item_t *;
39
};
40
41
template
<
typename
T>
42
struct
array_buf_ref_type
{
43
using
type = T &;
44
};
45
46
template
<
typename
S>
47
struct
array_buf_ref_type
<S *> {
48
using
type = S *;
49
};
50
51
template
<
size_t
M,
class
E>
52
struct
array_buf_ref_type
<
domain_entity
<M, E>> {
53
using
type = E *;
54
};
55
56
template
<
typename
T,
bool
B>
57
struct
array_buf_ref_get
{
58
static
T
get
(T a,
size_t
i) {
59
return
&a[i];
60
}
61
};
62
63
template
<
typename
T>
64
struct
array_buf_ref_get
<T, false> {
65
static
auto
get
(T a,
size_t
i) -> decltype(a[i]) {
66
return
a[i];
67
}
68
};
69
70
template
<
typename
T>
71
class
array_buffer
72
{
73
public
:
74
using
item_t =
typename
array_buffer_type<T>::type
;
75
76
using
iterator = item_t;
77
78
using
const_iterator = item_t;
79
80
using
ref_t =
typename
array_buf_ref_type<T>::type;
81
82
array_buffer
() : buf_(
nullptr
), size_(0), capacity_(0) {}
83
84
ref_t operator[](
size_t
index
) {
85
return
array_buf_ref_get<item_t, std::is_pointer<ref_t>::value
>::get(
86
buf_, index);
87
}
88
89
const
ref_t operator[](
size_t
index)
const
{
90
return
array_buf_ref_get<const item_t, std::is_pointer<ref_t>::value
>::get(
91
buf_, index);
92
}
93
94
ref_t back() {
95
return
array_buf_ref_get<item_t, std::is_pointer<ref_t>::value
>::get(
96
buf_, size_ - 1);
97
}
98
99
const
ref_t back()
const
{
100
return
array_buf_ref_get<item_t, std::is_pointer<ref_t>::value
>::get(
101
buf_, size_ - 1);
102
}
103
104
size_t
size()
const
{
105
return
size_;
106
}
// size
107
108
size_t
capacity()
const
{
109
return
capacity_;
110
}
// capacity
111
112
item_t begin() {
113
return
buf_;
114
}
115
116
item_t end() {
117
return
buf_ + size_;
118
}
119
120
const
item_t begin()
const
{
121
return
buf_;
122
}
123
124
const
item_t end()
const
{
125
return
buf_ + size_;
126
}
127
128
template
<
typename
... Args>
129
void
insert(Args &&...) {}
130
131
void
push_back(
const
ref_t x) {
132
assert(size_ < capacity_ &&
"array buffer capacity exceeded"
);
133
buf_[size_++] = x;
134
}
135
136
void
pushed() {
137
++size_;
138
}
139
140
void
clear() {
141
size_ = 0;
142
}
143
144
bool
empty()
const
{
145
return
size_ == 0;
146
}
147
148
void
resize(
size_t
n) {
149
assert(n <= capacity_);
150
size_ = n;
151
}
152
153
void
set_buffer(item_t buf,
size_t
size) {
154
buf_ = buf;
155
size_ = size;
156
capacity_ = size;
157
}
158
159
void
set_buffer(item_t buf,
size_t
capacity,
bool
initialized) {
160
buf_ = buf;
161
capacity_ = capacity;
162
size_ = initialized ? capacity_ : 0;
163
}
164
165
void
set_buffer(item_t buf,
size_t
capacity,
size_t
size) {
166
buf_ = buf;
167
capacity_ = capacity;
168
size_ = size;
169
}
170
171
item_t buffer() {
172
return
buf_;
173
}
174
175
const
item_t buffer()
const
{
176
return
buf_;
177
}
178
179
item_t data() {
180
return
buf_;
181
}
182
183
const
item_t data()
const
{
184
return
buf_;
185
}
186
187
template
<
typename
... Args>
188
void
assign(Args &&...) {
189
assert(
false
&&
"unimplemented"
);
190
}
191
192
void
reserve(
size_t
) {
193
assert(
false
&&
"unimplemented"
);
194
}
195
196
private
:
197
item_t buf_;
198
size_t
size_;
199
size_t
capacity_;
200
};
201
202
}
// namespace topo
203
}
// namespace flecsi
flecsi::topo::array_buf_ref_type
Definition:
array_buffer.hh:42
flecsi::topo::array_buffer
Definition:
array_buffer.hh:71
flecsi::topo::array_buffer_type
Definition:
array_buffer.hh:27
flecsi::topo::index
Definition:
index.hh:64
flecsi::topo::array_buf_ref_get
Definition:
array_buffer.hh:57
flecsi::topo::domain_entity
domain_entity is a simple wrapper to mesh entity that associates with its a domain id ...
Definition:
array_buffer.hh:24
id.hh
flecsi
Definition:
control.hh:31
Generated by
1.8.13