Loading...
Searching...
No Matches
ForthOutputBuffer.h
Go to the documentation of this file.
1// BSD 3-Clause License; see https://github.com/scikit-hep/awkward/blob/main/LICENSE
2
3#ifndef AWKWARD_FORTHOUTPUTBUFFER_H_
4#define AWKWARD_FORTHOUTPUTBUFFER_H_
5
6#include "awkward/common.h"
7#include "awkward/util.h"
8
9
10namespace awkward {
11 #define NATIVELY_BIG_ENDIAN (*(uint16_t *)"\0\xff" < 0x100)
12
14 template <typename T>
15 void byteswap16(int64_t num_items, T& value);
16
18 template <typename T>
19 void byteswap32(int64_t num_items, T& value);
20
22 template <typename T>
23 void byteswap64(int64_t num_items, T& value);
24
26 template <typename T>
27 void byteswap_intp(int64_t num_items, T& value);
28
35 public:
36 ForthOutputBuffer(int64_t initial, double resize);
37
42
44 int64_t
45 len() const noexcept;
46
48 void
49 rewind(int64_t num_items, util::ForthError& err) noexcept;
50
52 void
53 reset() noexcept;
54
56 virtual void
57 dup(int64_t num_times, util::ForthError& err) noexcept = 0;
58
60 virtual const std::shared_ptr<void>
61 ptr() const noexcept = 0;
62
63 virtual util::dtype
64 dtype() const = 0;
65
67 virtual void
68 write_one_bool(bool value, bool byteswap) noexcept = 0;
69
71 virtual void
72 write_one_int8(int8_t value, bool byteswap) noexcept = 0;
73
75 virtual void
76 write_one_int16(int16_t value, bool byteswap) noexcept = 0;
77
79 virtual void
80 write_one_int32(int32_t value, bool byteswap) noexcept = 0;
81
83 virtual void
84 write_one_int64(int64_t value, bool byteswap) noexcept = 0;
85
87 virtual void
88 write_one_intp(ssize_t value, bool byteswap) noexcept = 0;
89
91 virtual void
92 write_one_uint8(uint8_t value, bool byteswap) noexcept = 0;
93
95 virtual void
96 write_one_uint16(uint16_t value, bool byteswap) noexcept = 0;
97
99 virtual void
100 write_one_uint32(uint32_t value, bool byteswap) noexcept = 0;
101
103 virtual void
104 write_one_uint64(uint64_t value, bool byteswap) noexcept = 0;
105
107 virtual void
108 write_one_uintp(size_t value, bool byteswap) noexcept = 0;
109
111 virtual void
112 write_one_float32(float value, bool byteswap) noexcept = 0;
113
115 virtual void
116 write_one_float64(double value, bool byteswap) noexcept = 0;
117
119 virtual void
120 write_one_string(char* string_buffer, int64_t length) noexcept = 0;
121
123 virtual void
124 write_bool(int64_t num_items, bool* values, bool byteswap) noexcept = 0;
125
127 virtual void
128 write_int8(int64_t num_items, int8_t* values, bool byteswap) noexcept = 0;
129
131 virtual void
132 write_int16(int64_t num_items, int16_t* values, bool byteswap) noexcept = 0;
133
135 virtual void
136 write_int32(int64_t num_items, int32_t* values, bool byteswap) noexcept = 0;
137
139 virtual void
140 write_int64(int64_t num_items, int64_t* values, bool byteswap) noexcept = 0;
141
143 virtual void
144 write_intp(int64_t num_items, ssize_t* values, bool byteswap) noexcept = 0;
145
147 virtual void
148 write_const_uint8(int64_t num_items, const uint8_t* values) noexcept = 0;
149
151 virtual void
152 write_uint8(int64_t num_items, uint8_t* values, bool byteswap) noexcept = 0;
153
155 virtual void
156 write_uint16(int64_t num_items, uint16_t* values, bool byteswap) noexcept = 0;
157
159 virtual void
160 write_uint32(int64_t num_items, uint32_t* values, bool byteswap) noexcept = 0;
161
163 virtual void
164 write_uint64(int64_t num_items, uint64_t* values, bool byteswap) noexcept = 0;
165
167 virtual void
168 write_uintp(int64_t num_items, size_t* values, bool byteswap) noexcept = 0;
169
171 virtual void
172 write_float32(int64_t num_items, float* values, bool byteswap) noexcept = 0;
173
175 virtual void
176 write_float64(int64_t num_items, double* values, bool byteswap) noexcept = 0;
177
179 virtual void
180 write_add_int32(int32_t value) noexcept = 0;
181
183 virtual void
184 write_add_int64(int64_t value) noexcept = 0;
185
186 virtual std::string
187 tostring() const = 0;
188
189 protected:
190 int64_t length_;
191 int64_t reserved_;
192 double resize_;
193 };
194
195 template <typename OUT>
197 public:
198 ForthOutputBufferOf(int64_t initial, double resize);
199
200 void
201 dup(int64_t num_times, util::ForthError& err) noexcept override;
202
203 const std::shared_ptr<void>
204 ptr() const noexcept override;
205
206 util::dtype
207 dtype() const override;
208
209 void
210 write_one_bool(bool value, bool byteswap) noexcept override;
211
212 void
213 write_one_int8(int8_t value, bool byteswap) noexcept override;
214
215 void
216 write_one_int16(int16_t value, bool byteswap) noexcept override;
217
218 void
219 write_one_int32(int32_t value, bool byteswap) noexcept override;
220
221 void
222 write_one_int64(int64_t value, bool byteswap) noexcept override;
223
224 void
225 write_one_intp(ssize_t value, bool byteswap) noexcept override;
226
227 void
228 write_one_uint8(uint8_t value, bool byteswap) noexcept override;
229
230 void
231 write_one_uint16(uint16_t value, bool byteswap) noexcept override;
232
233 void
234 write_one_uint32(uint32_t value, bool byteswap) noexcept override;
235
236 void
237 write_one_uint64(uint64_t value, bool byteswap) noexcept override;
238
239 void
240 write_one_uintp(size_t value, bool byteswap) noexcept override;
241
242 void
243 write_one_float32(float value, bool byteswap) noexcept override;
244
245 void
246 write_one_float64(double value, bool byteswap) noexcept override;
247
248 void
249 write_one_string(char* string_buffer, int64_t length) noexcept override;
250
251 void
252 write_bool(int64_t num_items, bool* values, bool byteswap) noexcept override;
253
254 void
255 write_int8(int64_t num_items, int8_t* values, bool byteswap) noexcept override;
256
257 void
258 write_int16(int64_t num_items, int16_t* values, bool byteswap) noexcept override;
259
260 void
261 write_int32(int64_t num_items, int32_t* values, bool byteswap) noexcept override;
262
263 void
264 write_int64(int64_t num_items, int64_t* values, bool byteswap) noexcept override;
265
266 void
267 write_intp(int64_t num_items, ssize_t* values, bool byteswap) noexcept override;
268
269 void
270 write_const_uint8(int64_t num_items, const uint8_t* values) noexcept override;
271
272 void
273 write_uint8(int64_t num_items, uint8_t* values, bool byteswap) noexcept override;
274
275 void
276 write_uint16(int64_t num_items, uint16_t* values, bool byteswap) noexcept override;
277
278 void
279 write_uint32(int64_t num_items, uint32_t* values, bool byteswap) noexcept override;
280
281 void
282 write_uint64(int64_t num_items, uint64_t* values, bool byteswap) noexcept override;
283
284 void
285 write_uintp(int64_t num_items, size_t* values, bool byteswap) noexcept override;
286
287 void
288 write_float32(int64_t num_items, float* values, bool byteswap) noexcept override;
289
290 void
291 write_float64(int64_t num_items, double* values, bool byteswap) noexcept override;
292
293 void
294 write_add_int32(int32_t value) noexcept override;
295
296 void
297 write_add_int64(int64_t value) noexcept override;
298
299 std::string tostring() const override;
300
301 private:
302
304 void
305 maybe_resize(int64_t next);
306
308 template <typename IN>
309 inline void write_one(IN value) noexcept {
310 length_++;
311 maybe_resize(length_);
312 ptr_.get()[length_ - 1] = (OUT)value;
313 }
314
316 template <typename IN>
317 inline void write_copy(int64_t num_items, const IN* values) noexcept {
318 int64_t next = length_ + num_items;
319 maybe_resize(next);
320 for (int64_t i = 0; i < num_items; i++) {
321 ptr_.get()[length_ + i] = (OUT)values[i];
322 }
323 length_ = next;
324 }
325
326 std::shared_ptr<OUT> ptr_;
327 };
328
329}
330
331#endif // AWKWARD_FORTHOUTPUTBUFFER_H_
Definition ForthOutputBuffer.h:196
void dup(int64_t num_times, util::ForthError &err) noexcept override
HERE.
ForthOutputBufferOf(int64_t initial, double resize)
const std::shared_ptr< void > ptr() const noexcept override
HERE.
HERE.
Definition ForthOutputBuffer.h:34
ForthOutputBuffer(int64_t initial, double resize)
int64_t len() const noexcept
HERE.
virtual ~ForthOutputBuffer()
Virtual destructor acts as a first non-inline virtual function that determines a specific translation...
#define EXPORT_SYMBOL
Definition common.h:25
Definition ArrayBuilder.h:14
void byteswap_intp(int64_t num_items, T &value)
HERE.
void byteswap64(int64_t num_items, T &value)
HERE.
void byteswap16(int64_t num_items, T &value)
HERE.
void byteswap32(int64_t num_items, T &value)
HERE.