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-1.0/blob/main/LICENSE
2
3#ifndef AWKWARD_FORTHOUTPUTBUFFER_H_
4#define AWKWARD_FORTHOUTPUTBUFFER_H_
5
6// #include <cstring>
7
8#include "awkward/common.h"
9#include "awkward/Content.h"
10#include "awkward/Index.h"
11
12namespace awkward {
13 #define NATIVELY_BIG_ENDIAN (*(uint16_t *)"\0\xff" < 0x100)
14
16 template <typename T>
17 void byteswap16(int64_t num_items, T& value);
18
20 template <typename T>
21 void byteswap32(int64_t num_items, T& value);
22
24 template <typename T>
25 void byteswap64(int64_t num_items, T& value);
26
28 template <typename T>
30
37 public:
38 ForthOutputBuffer(int64_t initial, double resize);
39
44
48
50 void
51 rewind(int64_t num_items, util::ForthError& err) noexcept;
52
54 void
55 reset() noexcept;
56
58 virtual void
59 dup(int64_t num_times, util::ForthError& err) noexcept = 0;
60
62 virtual const std::shared_ptr<void>
63 ptr() const noexcept = 0;
64
67 toNumpyArray() const = 0;
68
71 toIndex8() const = 0;
72
75 toIndexU8() const = 0;
76
79 toIndex32() const = 0;
80
83 toIndexU32() const = 0;
84
87 toIndex64() const = 0;
88
90 virtual void
91 write_one_bool(bool value, bool byteswap) noexcept = 0;
92
94 virtual void
95 write_one_int8(int8_t value, bool byteswap) noexcept = 0;
96
98 virtual void
99 write_one_int16(int16_t value, bool byteswap) noexcept = 0;
100
102 virtual void
103 write_one_int32(int32_t value, bool byteswap) noexcept = 0;
104
106 virtual void
107 write_one_int64(int64_t value, bool byteswap) noexcept = 0;
108
110 virtual void
111 write_one_intp(ssize_t value, bool byteswap) noexcept = 0;
112
114 virtual void
115 write_one_uint8(uint8_t value, bool byteswap) noexcept = 0;
116
118 virtual void
119 write_one_uint16(uint16_t value, bool byteswap) noexcept = 0;
120
122 virtual void
123 write_one_uint32(uint32_t value, bool byteswap) noexcept = 0;
124
126 virtual void
127 write_one_uint64(uint64_t value, bool byteswap) noexcept = 0;
128
130 virtual void
131 write_one_uintp(size_t value, bool byteswap) noexcept = 0;
132
134 virtual void
135 write_one_float32(float value, bool byteswap) noexcept = 0;
136
138 virtual void
139 write_one_float64(double value, bool byteswap) noexcept = 0;
140
142 virtual void
143 write_one_string(char* string_buffer, int64_t length) noexcept = 0;
144
146 virtual void
147 write_bool(int64_t num_items, bool* values, bool byteswap) noexcept = 0;
148
150 virtual void
152
154 virtual void
156
158 virtual void
160
162 virtual void
164
166 virtual void
168
170 virtual void
171 write_const_uint8(int64_t num_items, const uint8_t* values) noexcept = 0;
172
174 virtual void
176
178 virtual void
180
182 virtual void
184
186 virtual void
188
190 virtual void
191 write_uintp(int64_t num_items, size_t* values, bool byteswap) noexcept = 0;
192
194 virtual void
195 write_float32(int64_t num_items, float* values, bool byteswap) noexcept = 0;
196
198 virtual void
199 write_float64(int64_t num_items, double* values, bool byteswap) noexcept = 0;
200
202 virtual void
203 write_add_int32(int32_t value) noexcept = 0;
204
206 virtual void
207 write_add_int64(int64_t value) noexcept = 0;
208
209 protected:
210 int64_t length_;
211 int64_t reserved_;
212 double resize_;
213 };
214
217 public:
218 ForthOutputBufferOf(int64_t initial, double resize);
219
220 void
222
223 const std::shared_ptr<void>
225
227 toNumpyArray() const override;
228
230 toIndex8() const override;
231
233 toIndexU8() const override;
234
236 toIndex32() const override;
237
239 toIndexU32() const override;
240
242 toIndex64() const override;
243
244 void
245 write_one_bool(bool value, bool byteswap) noexcept override;
246
247 void
248 write_one_int8(int8_t value, bool byteswap) noexcept override;
249
250 void
251 write_one_int16(int16_t value, bool byteswap) noexcept override;
252
253 void
254 write_one_int32(int32_t value, bool byteswap) noexcept override;
255
256 void
257 write_one_int64(int64_t value, bool byteswap) noexcept override;
258
259 void
260 write_one_intp(ssize_t value, bool byteswap) noexcept override;
261
262 void
263 write_one_uint8(uint8_t value, bool byteswap) noexcept override;
264
265 void
266 write_one_uint16(uint16_t value, bool byteswap) noexcept override;
267
268 void
269 write_one_uint32(uint32_t value, bool byteswap) noexcept override;
270
271 void
272 write_one_uint64(uint64_t value, bool byteswap) noexcept override;
273
274 void
275 write_one_uintp(size_t value, bool byteswap) noexcept override;
276
277 void
278 write_one_float32(float value, bool byteswap) noexcept override;
279
280 void
281 write_one_float64(double value, bool byteswap) noexcept override;
282
283 void
284 write_one_string(char* string_buffer, int64_t length) noexcept override;
285
286 void
288
289 void
291
292 void
294
295 void
297
298 void
300
301 void
303
304 void
306
307 void
309
310 void
312
313 void
315
316 void
318
319 void
320 write_uintp(int64_t num_items, size_t* values, bool byteswap) noexcept override;
321
322 void
323 write_float32(int64_t num_items, float* values, bool byteswap) noexcept override;
324
325 void
326 write_float64(int64_t num_items, double* values, bool byteswap) noexcept override;
327
328 void
329 write_add_int32(int32_t value) noexcept override;
330
331 void
332 write_add_int64(int64_t value) noexcept override;
333
334 private:
335
337 void
338 maybe_resize(int64_t next);
339
342 inline void write_one(IN value) noexcept {
343 length_++;
344 maybe_resize(length_);
345 ptr_.get()[length_ - 1] = (OUT)value;
346 }
347
349 template <typename IN>
350 inline void write_copy(int64_t num_items, const IN* values) noexcept {
351 int64_t next = length_ + num_items;
352 maybe_resize(next);
353 for (int64_t i = 0; i < num_items; i++) {
354 ptr_.get()[length_ + i] = (OUT)values[i];
355 }
356 length_ = next;
357 }
358
359 std::shared_ptr<OUT> ptr_;
360 };
361
362}
363
364#endif // AWKWARD_FORTHOUTPUTBUFFER_H_
Definition ForthOutputBuffer.h:216
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:36
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...
A contiguous, one-dimensional array of integers used to represent data structures,...
Definition Index.h:82
Filters, rearranges, and/or duplicates items in its content through an index, which has the same effe...
Definition IndexedArray.h:204
#define LIBAWKWARD_EXPORT_SYMBOL
Definition common.h:45
ForthError
Exhaustive list of runtime errors possible in the ForthMachine.
Definition util.h:224
Definition BitMaskedArray.h:15
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.
std::shared_ptr< Content > ContentPtr
Definition Content.h:15