Awkward Array: include/awkward/builder/ArrayBuilder.h Source File

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-1.0/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"
11#include "awkward/builder/Builder.h"
12#include "awkward/BuilderOptions.h"
13
14namespace awkward {
15 class Builder;
16 using BuilderPtr = std::shared_ptr<Builder>;
17
23 class LIBAWKWARD_EXPORT_SYMBOL ArrayBuilder {
24 public:
29 ArrayBuilder(const BuilderOptions& options);
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
43 clear();
44
46 void
47 null();
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
109 beginlist();
110
112 void
113 endlist();
114
116 void
117 begintuple(int64_t numfields);
118
121 void
122 index(int64_t index);
123
125 void
126 endtuple();
127
131 void
132 beginrecord();
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
223 endrecord();
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 LIBAWKWARD_EXPORT_SYMBOL uint8_t
248 awkward_ArrayBuilder_length(void* arraybuilder,
249 int64_t* result);
251 LIBAWKWARD_EXPORT_SYMBOL uint8_t
252 awkward_ArrayBuilder_clear(void* arraybuilder);
253
255 LIBAWKWARD_EXPORT_SYMBOL uint8_t
256 awkward_ArrayBuilder_null(void* arraybuilder);
257
259 LIBAWKWARD_EXPORT_SYMBOL uint8_t
260 awkward_ArrayBuilder_boolean(void* arraybuilder,
261 bool x);
262
264 LIBAWKWARD_EXPORT_SYMBOL uint8_t
265 awkward_ArrayBuilder_integer(void* arraybuilder,
266 int64_t x);
267
269 LIBAWKWARD_EXPORT_SYMBOL uint8_t
270 awkward_ArrayBuilder_real(void* arraybuilder,
271 double x);
272
274 LIBAWKWARD_EXPORT_SYMBOL uint8_t
275 awkward_ArrayBuilder_complex(void* arraybuilder,
276 double real,
277 double imag);
278
280 LIBAWKWARD_EXPORT_SYMBOL uint8_t
281 awkward_ArrayBuilder_datetime(void* arraybuilder,
282 int64_t x,
283 const char* unit);
284
286 LIBAWKWARD_EXPORT_SYMBOL uint8_t
287 awkward_ArrayBuilder_timedelta(void* arraybuilder,
288 int64_t x,
289 const char* unit);
290
293 LIBAWKWARD_EXPORT_SYMBOL uint8_t
294 awkward_ArrayBuilder_bytestring(void* arraybuilder,
295 const char* x);
296
299 LIBAWKWARD_EXPORT_SYMBOL uint8_t
300 awkward_ArrayBuilder_bytestring_length(void* arraybuilder,
301 const char* x,
302 int64_t length);
303
305 LIBAWKWARD_EXPORT_SYMBOL uint8_t
306 awkward_ArrayBuilder_string(void* arraybuilder,
307 const char* x);
308
310 LIBAWKWARD_EXPORT_SYMBOL uint8_t
311 awkward_ArrayBuilder_string_length(void* arraybuilder,
312 const char* x,
313 int64_t length);
314
317 LIBAWKWARD_EXPORT_SYMBOL uint8_t
318 awkward_ArrayBuilder_beginlist(void* arraybuilder);
319
321 LIBAWKWARD_EXPORT_SYMBOL uint8_t
322 awkward_ArrayBuilder_endlist(void* arraybuilder);
323
326 LIBAWKWARD_EXPORT_SYMBOL uint8_t
327 awkward_ArrayBuilder_begintuple(void* arraybuilder,
328 int64_t numfields);
329
331 LIBAWKWARD_EXPORT_SYMBOL uint8_t
332 awkward_ArrayBuilder_index(void* arraybuilder,
333 int64_t index);
334
337 LIBAWKWARD_EXPORT_SYMBOL uint8_t
338 awkward_ArrayBuilder_endtuple(void* arraybuilder);
339
342 LIBAWKWARD_EXPORT_SYMBOL uint8_t
343 awkward_ArrayBuilder_beginrecord(void* arraybuilder);
344
347 LIBAWKWARD_EXPORT_SYMBOL uint8_t
348 awkward_ArrayBuilder_beginrecord_fast(void* arraybuilder,
349 const char* name);
350
353 LIBAWKWARD_EXPORT_SYMBOL uint8_t
354 awkward_ArrayBuilder_beginrecord_check(void* arraybuilder,
355 const char* name);
356
359 LIBAWKWARD_EXPORT_SYMBOL uint8_t
360 awkward_ArrayBuilder_field_fast(void* arraybuilder,
361 const char* key);
362
365 LIBAWKWARD_EXPORT_SYMBOL uint8_t
366 awkward_ArrayBuilder_field_check(void* arraybuilder,
367 const char* key);
368
371 LIBAWKWARD_EXPORT_SYMBOL uint8_t
372 awkward_ArrayBuilder_endrecord(void* arraybuilder);
373}
374
375#endif // AWKWARD_ARRAYBUILDER_H_
awkward_ArrayBuilder_beginlist
LIBAWKWARD_EXPORT_SYMBOL uint8_t awkward_ArrayBuilder_beginlist(void *arraybuilder)
C interface to ArrayBuilder::beginlist.
awkward_ArrayBuilder_timedelta
LIBAWKWARD_EXPORT_SYMBOL uint8_t awkward_ArrayBuilder_timedelta(void *arraybuilder, int64_t x, const char *unit)
C interface to ArrayBuilder::timedelta.
awkward_ArrayBuilder_field_check
LIBAWKWARD_EXPORT_SYMBOL uint8_t awkward_ArrayBuilder_field_check(void *arraybuilder, const char *key)
C interface to ArrayBuilder::field_check.
awkward_ArrayBuilder_string_length
LIBAWKWARD_EXPORT_SYMBOL uint8_t awkward_ArrayBuilder_string_length(void *arraybuilder, const char *x, int64_t length)
C interface to ArrayBuilder::string.
awkward_ArrayBuilder_complex
LIBAWKWARD_EXPORT_SYMBOL uint8_t awkward_ArrayBuilder_complex(void *arraybuilder, double real, double imag)
C interface to ArrayBuilder::complex.
awkward_ArrayBuilder_index
LIBAWKWARD_EXPORT_SYMBOL uint8_t awkward_ArrayBuilder_index(void *arraybuilder, int64_t index)
C interface to ArrayBuilder::index.
awkward_ArrayBuilder_begintuple
LIBAWKWARD_EXPORT_SYMBOL uint8_t awkward_ArrayBuilder_begintuple(void *arraybuilder, int64_t numfields)
C interface to ArrayBuilder::begintuple.
awkward_ArrayBuilder_endtuple
LIBAWKWARD_EXPORT_SYMBOL uint8_t awkward_ArrayBuilder_endtuple(void *arraybuilder)
C interface to ArrayBuilder::endtuple.
awkward_ArrayBuilder_length
LIBAWKWARD_EXPORT_SYMBOL uint8_t awkward_ArrayBuilder_length(void *arraybuilder, int64_t *result)
C interface to ArrayBuilder::length.
awkward_ArrayBuilder_null
LIBAWKWARD_EXPORT_SYMBOL uint8_t awkward_ArrayBuilder_null(void *arraybuilder)
C interface to ArrayBuilder::null.
awkward_ArrayBuilder_endlist
LIBAWKWARD_EXPORT_SYMBOL uint8_t awkward_ArrayBuilder_endlist(void *arraybuilder)
C interface to ArrayBuilder::endlist.
awkward_ArrayBuilder_string
LIBAWKWARD_EXPORT_SYMBOL uint8_t awkward_ArrayBuilder_string(void *arraybuilder, const char *x)
C interface to ArrayBuilder::string.
awkward_ArrayBuilder_beginrecord_check
LIBAWKWARD_EXPORT_SYMBOL uint8_t awkward_ArrayBuilder_beginrecord_check(void *arraybuilder, const char *name)
C interface to ArrayBuilder::beginrecord_check.
awkward_ArrayBuilder_field_fast
LIBAWKWARD_EXPORT_SYMBOL uint8_t awkward_ArrayBuilder_field_fast(void *arraybuilder, const char *key)
C interface to ArrayBuilder::field_fast.
awkward_ArrayBuilder_datetime
LIBAWKWARD_EXPORT_SYMBOL uint8_t awkward_ArrayBuilder_datetime(void *arraybuilder, int64_t x, const char *unit)
C interface to ArrayBuilder::datetime.
awkward_ArrayBuilder_boolean
LIBAWKWARD_EXPORT_SYMBOL uint8_t awkward_ArrayBuilder_boolean(void *arraybuilder, bool x)
C interface to ArrayBuilder::boolean.
awkward_ArrayBuilder_bytestring_length
LIBAWKWARD_EXPORT_SYMBOL uint8_t awkward_ArrayBuilder_bytestring_length(void *arraybuilder, const char *x, int64_t length)
C interface to ArrayBuilder::bytestring.
awkward_ArrayBuilder_real
LIBAWKWARD_EXPORT_SYMBOL uint8_t awkward_ArrayBuilder_real(void *arraybuilder, double x)
C interface to ArrayBuilder::real.
awkward_ArrayBuilder_bytestring
LIBAWKWARD_EXPORT_SYMBOL uint8_t awkward_ArrayBuilder_bytestring(void *arraybuilder, const char *x)
C interface to ArrayBuilder::bytestring.
awkward_ArrayBuilder_integer
LIBAWKWARD_EXPORT_SYMBOL uint8_t awkward_ArrayBuilder_integer(void *arraybuilder, int64_t x)
C interface to ArrayBuilder::integer.
awkward_ArrayBuilder_clear
LIBAWKWARD_EXPORT_SYMBOL uint8_t awkward_ArrayBuilder_clear(void *arraybuilder)
C interface to ArrayBuilder::clear.
awkward_ArrayBuilder_beginrecord
LIBAWKWARD_EXPORT_SYMBOL uint8_t awkward_ArrayBuilder_beginrecord(void *arraybuilder)
C interface to ArrayBuilder::beginrecord.
awkward_ArrayBuilder_endrecord
LIBAWKWARD_EXPORT_SYMBOL uint8_t awkward_ArrayBuilder_endrecord(void *arraybuilder)
C interface to ArrayBuilder::endrecord.
awkward_ArrayBuilder_beginrecord_fast
LIBAWKWARD_EXPORT_SYMBOL uint8_t awkward_ArrayBuilder_beginrecord_fast(void *arraybuilder, const char *name)
C interface to ArrayBuilder::beginrecord_fast.
BuilderOptions.h
Builder.h
awkward::ArrayBuilder
User interface to the Builder system: the ArrayBuilder is a fixed reference while the Builder subclas...
Definition: ArrayBuilder.h:23
awkward::ArrayBuilder::builder_update
void builder_update(BuilderPtr builder)
Definition: ArrayBuilder.h:228
awkward::ArrayBuilder::beginrecord
void beginrecord()
Begins building a record without a name.
awkward::ArrayBuilder::boolean
void boolean(bool x)
Adds a boolean value x to the accumulated data.
awkward::ArrayBuilder::beginrecord_check
void beginrecord_check(const char *name)
Begins building a record with a name.
awkward::ArrayBuilder::ArrayBuilder
ArrayBuilder(const BuilderOptions &options)
Creates an ArrayBuilder from a full set of parameters.
awkward::ArrayBuilder::complex
void complex(std::complex< double > x)
Adds a complex value x to the accumulated data.
awkward::ArrayBuilder::bytestring
void bytestring(const std::string &x)
Adds an unencoded bytestring x in STL format to the accumulated data.
awkward::ArrayBuilder::endlist
void endlist()
Ends a nested list.
awkward::ArrayBuilder::string
void string(const char *x)
Adds a UTF-8 encoded, null-terminated bytestring value x to the accumulated data.
awkward::ArrayBuilder::timedelta
void timedelta(int64_t x, const std::string &unit)
Adds a timedelta value x to the accumulated data.
awkward::ArrayBuilder::endrecord
void endrecord()
Ends a record.
awkward::ArrayBuilder::real
void real(double x)
Adds a real value x to the accumulated data.
awkward::ArrayBuilder::beginlist
void beginlist()
Begins building a nested list.
awkward::ArrayBuilder::integer
void integer(int64_t x)
Adds an integer value x to the accumulated data.
awkward::ArrayBuilder::field_check
void field_check(const char *key)
Sets the pointer to a given record field key; the next command will fill that slot.
awkward::ArrayBuilder::endtuple
void endtuple()
Ends a tuple.
awkward::ArrayBuilder::maybeupdate
void maybeupdate(const BuilderPtr builder)
Internal function to replace the root node of the ArrayBuilder's Builder tree with a new root.
awkward::ArrayBuilder::field_fast
void field_fast(const char *key)
Sets the pointer to a given record field key; the next command will fill that slot.
awkward::ArrayBuilder::field_check
void field_check(const std::string &key)
Sets the pointer to a given record field key; the next command will fill that slot.
awkward::ArrayBuilder::builder
const BuilderPtr builder() const
Definition: ArrayBuilder.h:226
awkward::ArrayBuilder::to_buffers
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).
awkward::ArrayBuilder::begintuple
void begintuple(int64_t numfields)
Begins building a tuple with a fixed number of fields.
awkward::ArrayBuilder::null
void null()
Adds a null value to the accumulated data.
awkward::ArrayBuilder::clear
void clear()
Removes all accumulated data without resetting the type knowledge.
awkward::ArrayBuilder::string
void string(const std::string &x)
Adds a UTF-8 encoded bytestring x in STL format to the accumulated data.
awkward::ArrayBuilder::string
void string(const char *x, int64_t length)
Adds a UTF-8 encoded bytestring value x with a given length to the accumulated data.
awkward::ArrayBuilder::datetime
void datetime(int64_t x, const std::string &unit)
Adds a datetime value x to the accumulated data.
awkward::ArrayBuilder::index
void index(int64_t index)
Sets the pointer to a given tuple field index; the next command will fill that slot.
awkward::ArrayBuilder::length
int64_t length() const
Current length of the accumulated array.
awkward::ArrayBuilder::bytestring
void bytestring(const char *x)
Adds an unencoded, null-terminated bytestring value x to the accumulated data.
awkward::ArrayBuilder::beginrecord_fast
void beginrecord_fast(const char *name)
Begins building a record with a name.
awkward::ArrayBuilder::bytestring
void bytestring(const char *x, int64_t length)
Adds an unencoded bytestring value x with a given length to the accumulated data.
awkward::ArrayBuilder::beginrecord_check
void beginrecord_check(const std::string &name)
Begins building a record with a name.
awkward::BuffersContainer
Abstract class to represent the output of ak.to_buffers. In Python, this would be a dict of NumPy arr...
Definition: Builder.h:20
common.h
LIBAWKWARD_EXPORT_SYMBOL
#define LIBAWKWARD_EXPORT_SYMBOL
Definition: common.h:45
awkward
Definition: BitMaskedArray.h:15
awkward::BuilderPtr
std::shared_ptr< Builder > BuilderPtr
Definition: ArrayBuilder.h:16
awkward::Options
Container for all configuration options needed by ArrayBuilder, GrowableBuffer, LayoutBuilder and the...
Definition: BuilderOptions.h:20