Loading...
Searching...
No Matches
ArrayBuilder.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_ARRAYBUILDER_H_
4#define AWKWARD_ARRAYBUILDER_H_
5
6#include <complex>
7#include <string>
8#include <vector>
9
10#include "awkward/common.h"
13
14namespace awkward {
15 class Builder;
16 using BuilderPtr = std::shared_ptr<Builder>;
17
24 public:
30
33 const std::string
34 to_buffers(BuffersContainer& container, int64_t& form_key_id) const;
35
37 int64_t
38 length() const;
39
42 void
44
46 void
48
50 void
51 boolean(bool x);
52
54 void
55 integer(int64_t x);
56
58 void
59 real(double x);
60
62 void
63 complex(std::complex<double> x);
64
66 void
67 datetime(int64_t x, const std::string& unit);
68
70 void
71 timedelta(int64_t x, const std::string& unit);
72
75 void
76 bytestring(const char* x);
77
82 void
83 bytestring(const char* x, int64_t length);
84
87 void
88 bytestring(const std::string& x);
89
92 void
93 string(const char* x);
94
99 void
100 string(const char* x, int64_t length);
101
104 void
105 string(const std::string& x);
106
108 void
110
112 void
114
116 void
117 begintuple(int64_t numfields);
118
121 void
122 index(int64_t index);
123
125 void
127
131 void
133
147 void
148 beginrecord_fast(const char* name);
149
163 void
164 beginrecord_check(const char* name);
165
179 void
180 beginrecord_check(const std::string& name);
181
192 void
193 field_fast(const char* key);
194
205 void
206 field_check(const char* key);
207
218 void
219 field_check(const std::string& key);
220
222 void
224
225 // @brief Root node of the Builder tree.
226 const BuilderPtr builder() const { return builder_; }
227
228 void builder_update(BuilderPtr builder) { builder_ = builder; }
229
232 void
233 maybeupdate(const BuilderPtr builder);
234
235private:
237 static const char* no_encoding;
239 static const char* utf8_encoding;
241 BuilderPtr builder_;
242 };
243}
244
245extern "C" {
247 EXPORT_SYMBOL uint8_t
248 awkward_ArrayBuilder_length(void* arraybuilder,
249 int64_t* result);
251 EXPORT_SYMBOL uint8_t
252 awkward_ArrayBuilder_clear(void* arraybuilder);
253
255 EXPORT_SYMBOL uint8_t
256 awkward_ArrayBuilder_null(void* arraybuilder);
257
259 EXPORT_SYMBOL uint8_t
261 bool x);
262
264 EXPORT_SYMBOL uint8_t
266 int64_t x);
267
269 EXPORT_SYMBOL uint8_t
270 awkward_ArrayBuilder_real(void* arraybuilder,
271 double x);
272
274 EXPORT_SYMBOL uint8_t
276 double real,
277 double imag);
278
280 EXPORT_SYMBOL uint8_t
282 int64_t x,
283 const char* unit);
284
286 EXPORT_SYMBOL uint8_t
288 int64_t x,
289 const char* unit);
290
293 EXPORT_SYMBOL uint8_t
295 const char* x);
296
299 EXPORT_SYMBOL uint8_t
301 const char* x,
302 int64_t length);
303
305 EXPORT_SYMBOL uint8_t
306 awkward_ArrayBuilder_string(void* arraybuilder,
307 const char* x);
308
310 EXPORT_SYMBOL uint8_t
312 const char* x,
313 int64_t length);
314
317 EXPORT_SYMBOL uint8_t
319
321 EXPORT_SYMBOL uint8_t
322 awkward_ArrayBuilder_endlist(void* arraybuilder);
323
326 EXPORT_SYMBOL uint8_t
328 int64_t numfields);
329
331 EXPORT_SYMBOL uint8_t
332 awkward_ArrayBuilder_index(void* arraybuilder,
333 int64_t index);
334
337 EXPORT_SYMBOL uint8_t
338 awkward_ArrayBuilder_endtuple(void* arraybuilder);
339
342 EXPORT_SYMBOL uint8_t
344
347 EXPORT_SYMBOL uint8_t
349 const char* name);
350
353 EXPORT_SYMBOL uint8_t
355 const char* name);
356
359 EXPORT_SYMBOL uint8_t
361 const char* key);
362
365 EXPORT_SYMBOL uint8_t
367 const char* key);
368
371 EXPORT_SYMBOL uint8_t
373}
374
375#endif // AWKWARD_ARRAYBUILDER_H_
EXPORT_SYMBOL uint8_t awkward_ArrayBuilder_boolean(void *arraybuilder, bool x)
C interface to ArrayBuilder::boolean.
EXPORT_SYMBOL uint8_t awkward_ArrayBuilder_beginrecord(void *arraybuilder)
C interface to ArrayBuilder::beginrecord.
EXPORT_SYMBOL uint8_t awkward_ArrayBuilder_field_check(void *arraybuilder, const char *key)
C interface to ArrayBuilder::field_check.
EXPORT_SYMBOL uint8_t awkward_ArrayBuilder_string(void *arraybuilder, const char *x)
C interface to ArrayBuilder::string.
EXPORT_SYMBOL uint8_t awkward_ArrayBuilder_begintuple(void *arraybuilder, int64_t numfields)
C interface to ArrayBuilder::begintuple.
EXPORT_SYMBOL uint8_t awkward_ArrayBuilder_bytestring_length(void *arraybuilder, const char *x, int64_t length)
C interface to ArrayBuilder::bytestring.
EXPORT_SYMBOL uint8_t awkward_ArrayBuilder_complex(void *arraybuilder, double real, double imag)
C interface to ArrayBuilder::complex.
EXPORT_SYMBOL uint8_t awkward_ArrayBuilder_clear(void *arraybuilder)
C interface to ArrayBuilder::clear.
EXPORT_SYMBOL uint8_t awkward_ArrayBuilder_timedelta(void *arraybuilder, int64_t x, const char *unit)
C interface to ArrayBuilder::timedelta.
EXPORT_SYMBOL uint8_t awkward_ArrayBuilder_endtuple(void *arraybuilder)
C interface to ArrayBuilder::endtuple.
EXPORT_SYMBOL uint8_t awkward_ArrayBuilder_datetime(void *arraybuilder, int64_t x, const char *unit)
C interface to ArrayBuilder::datetime.
EXPORT_SYMBOL uint8_t awkward_ArrayBuilder_beginrecord_fast(void *arraybuilder, const char *name)
C interface to ArrayBuilder::beginrecord_fast.
EXPORT_SYMBOL uint8_t awkward_ArrayBuilder_string_length(void *arraybuilder, const char *x, int64_t length)
C interface to ArrayBuilder::string.
EXPORT_SYMBOL uint8_t awkward_ArrayBuilder_endlist(void *arraybuilder)
C interface to ArrayBuilder::endlist.
EXPORT_SYMBOL uint8_t awkward_ArrayBuilder_integer(void *arraybuilder, int64_t x)
C interface to ArrayBuilder::integer.
EXPORT_SYMBOL uint8_t awkward_ArrayBuilder_real(void *arraybuilder, double x)
C interface to ArrayBuilder::real.
EXPORT_SYMBOL uint8_t awkward_ArrayBuilder_field_fast(void *arraybuilder, const char *key)
C interface to ArrayBuilder::field_fast.
EXPORT_SYMBOL uint8_t awkward_ArrayBuilder_length(void *arraybuilder, int64_t *result)
C interface to ArrayBuilder::length.
EXPORT_SYMBOL uint8_t awkward_ArrayBuilder_null(void *arraybuilder)
C interface to ArrayBuilder::null.
EXPORT_SYMBOL uint8_t awkward_ArrayBuilder_beginrecord_check(void *arraybuilder, const char *name)
C interface to ArrayBuilder::beginrecord_check.
EXPORT_SYMBOL uint8_t awkward_ArrayBuilder_bytestring(void *arraybuilder, const char *x)
C interface to ArrayBuilder::bytestring.
EXPORT_SYMBOL uint8_t awkward_ArrayBuilder_endrecord(void *arraybuilder)
C interface to ArrayBuilder::endrecord.
EXPORT_SYMBOL uint8_t awkward_ArrayBuilder_index(void *arraybuilder, int64_t index)
C interface to ArrayBuilder::index.
EXPORT_SYMBOL uint8_t awkward_ArrayBuilder_beginlist(void *arraybuilder)
C interface to ArrayBuilder::beginlist.
User interface to the Builder system: the ArrayBuilder is a fixed reference while the Builder subclas...
Definition ArrayBuilder.h:23
void builder_update(BuilderPtr builder)
Definition ArrayBuilder.h:228
void beginrecord()
Begins building a record without a name.
void boolean(bool x)
Adds a boolean value x to the accumulated data.
void beginrecord_check(const char *name)
Begins building a record with a name.
ArrayBuilder(const BuilderOptions &options)
Creates an ArrayBuilder from a full set of parameters.
void complex(std::complex< double > x)
Adds a complex value x to the accumulated data.
void bytestring(const std::string &x)
Adds an unencoded bytestring x in STL format to the accumulated data.
void endlist()
Ends a nested list.
void string(const char *x)
Adds a UTF-8 encoded, null-terminated bytestring value x to the accumulated data.
void timedelta(int64_t x, const std::string &unit)
Adds a timedelta value x to the accumulated data.
void endrecord()
Ends a record.
void real(double x)
Adds a real value x to the accumulated data.
void beginlist()
Begins building a nested list.
void integer(int64_t x)
Adds an integer value x to the accumulated data.
void field_check(const char *key)
Sets the pointer to a given record field key; the next command will fill that slot.
void endtuple()
Ends a tuple.
void maybeupdate(const BuilderPtr builder)
Internal function to replace the root node of the ArrayBuilder's Builder tree with a new root.
void field_fast(const char *key)
Sets the pointer to a given record field key; the next command will fill that slot.
void field_check(const std::string &key)
Sets the pointer to a given record field key; the next command will fill that slot.
const BuilderPtr builder() const
Definition ArrayBuilder.h:226
const std::string to_buffers(BuffersContainer &container, int64_t &form_key_id) const
Copy the current snapshot into the BuffersContainer and return a Form as a std::string (JSON).
void begintuple(int64_t numfields)
Begins building a tuple with a fixed number of fields.
void null()
Adds a null value to the accumulated data.
void clear()
Removes all accumulated data without resetting the type knowledge.
void string(const std::string &x)
Adds a UTF-8 encoded bytestring x in STL format to the accumulated data.
void string(const char *x, int64_t length)
Adds a UTF-8 encoded bytestring value x with a given length to the accumulated data.
void datetime(int64_t x, const std::string &unit)
Adds a datetime value x to the accumulated data.
void index(int64_t index)
Sets the pointer to a given tuple field index; the next command will fill that slot.
int64_t length() const
Current length of the accumulated array.
void bytestring(const char *x)
Adds an unencoded, null-terminated bytestring value x to the accumulated data.
void beginrecord_fast(const char *name)
Begins building a record with a name.
void bytestring(const char *x, int64_t length)
Adds an unencoded bytestring value x with a given length to the accumulated data.
void beginrecord_check(const std::string &name)
Begins building a record with a name.
Abstract class to represent the output of ak.to_buffers. In Python, this would be a dict of NumPy arr...
Definition Builder.h:20
Abstract base class for nodes within an ArrayBuilder that cumulatively discover an array's type and f...
Definition Builder.h:41
#define EXPORT_SYMBOL
Definition common.h:25
Definition ArrayBuilder.h:14
std::shared_ptr< Builder > BuilderPtr
Definition ArrayBuilder.h:16
Container for all configuration options needed by ArrayBuilder, GrowableBuffer, LayoutBuilder and the...
Definition BuilderOptions.h:20