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/util.h"
13 
14 namespace awkward {
15  class Content;
16  using ContentPtr = std::shared_ptr<Content>;
17  class ArrayBuilderOptions;
18  class Builder;
19  using BuilderPtr = std::shared_ptr<Builder>;
20 
27  public:
32  ArrayBuilder(const ArrayBuilderOptions& options);
33 
36  const std::string
37  to_buffers(BuffersContainer& container, int64_t& form_key_id) const;
38 
40  int64_t
41  length() const;
42 
45  void
46  clear();
47 
49  void
50  null();
51 
53  void
54  boolean(bool x);
55 
57  void
58  integer(int64_t x);
59 
61  void
62  real(double x);
63 
65  void
66  complex(std::complex<double> x);
67 
69  void
70  datetime(int64_t x, const std::string& unit);
71 
73  void
74  timedelta(int64_t x, const std::string& unit);
75 
78  void
79  bytestring(const char* x);
80 
85  void
86  bytestring(const char* x, int64_t length);
87 
90  void
91  bytestring(const std::string& x);
92 
95  void
96  string(const char* x);
97 
102  void
103  string(const char* x, int64_t length);
104 
107  void
108  string(const std::string& x);
109 
111  void
112  beginlist();
113 
115  void
116  endlist();
117 
119  void
120  begintuple(int64_t numfields);
121 
124  void
125  index(int64_t index);
126 
128  void
129  endtuple();
130 
134  void
135  beginrecord();
136 
150  void
151  beginrecord_fast(const char* name);
152 
166  void
167  beginrecord_check(const char* name);
168 
182  void
183  beginrecord_check(const std::string& name);
184 
195  void
196  field_fast(const char* key);
197 
208  void
209  field_check(const char* key);
210 
221  void
222  field_check(const std::string& key);
223 
225  void
226  endrecord();
227 
228  // @brief Root node of the Builder tree.
229  const BuilderPtr builder() const { return builder_; }
230 
231  void builder_update(BuilderPtr builder) { builder_ = builder; }
232 
235  void
236  maybeupdate(const BuilderPtr builder);
237 
238 private:
240  static const char* no_encoding;
242  static const char* utf8_encoding;
244  BuilderPtr builder_;
245  };
246 }
247 
248 extern "C" {
251  awkward_ArrayBuilder_length(void* arraybuilder,
252  int64_t* result);
255  awkward_ArrayBuilder_clear(void* arraybuilder);
256 
259  awkward_ArrayBuilder_null(void* arraybuilder);
260 
263  awkward_ArrayBuilder_boolean(void* arraybuilder,
264  bool x);
265 
268  awkward_ArrayBuilder_integer(void* arraybuilder,
269  int64_t x);
270 
273  awkward_ArrayBuilder_real(void* arraybuilder,
274  double x);
275 
278  awkward_ArrayBuilder_complex(void* arraybuilder,
279  double real,
280  double imag);
281 
284  awkward_ArrayBuilder_datetime(void* arraybuilder,
285  int64_t x,
286  const char* unit);
287 
290  awkward_ArrayBuilder_timedelta(void* arraybuilder,
291  int64_t x,
292  const char* unit);
293 
297  awkward_ArrayBuilder_bytestring(void* arraybuilder,
298  const char* x);
299 
303  awkward_ArrayBuilder_bytestring_length(void* arraybuilder,
304  const char* x,
305  int64_t length);
306 
309  awkward_ArrayBuilder_string(void* arraybuilder,
310  const char* x);
311 
314  awkward_ArrayBuilder_string_length(void* arraybuilder,
315  const char* x,
316  int64_t length);
317 
321  awkward_ArrayBuilder_beginlist(void* arraybuilder);
322 
325  awkward_ArrayBuilder_endlist(void* arraybuilder);
326 
330  awkward_ArrayBuilder_begintuple(void* arraybuilder,
331  int64_t numfields);
332 
335  awkward_ArrayBuilder_index(void* arraybuilder,
336  int64_t index);
337 
341  awkward_ArrayBuilder_endtuple(void* arraybuilder);
342 
346  awkward_ArrayBuilder_beginrecord(void* arraybuilder);
347 
351  awkward_ArrayBuilder_beginrecord_fast(void* arraybuilder,
352  const char* name);
353 
357  awkward_ArrayBuilder_beginrecord_check(void* arraybuilder,
358  const char* name);
359 
363  awkward_ArrayBuilder_field_fast(void* arraybuilder,
364  const char* key);
365 
369  awkward_ArrayBuilder_field_check(void* arraybuilder,
370  const char* key);
371 
375  awkward_ArrayBuilder_endrecord(void* arraybuilder);
376 }
377 
378 #endif // AWKWARD_ARRAYBUILDER_H_
LIBAWKWARD_EXPORT_SYMBOL uint8_t awkward_ArrayBuilder_timedelta(void *arraybuilder, int64_t x, const char *unit)
C interface to ArrayBuilder::timedelta.
Container for all configuration options needed by ArrayBuilder, GrowableBuffer, and the Builder subcl...
Definition: ArrayBuilderOptions.h:13
LIBAWKWARD_EXPORT_SYMBOL uint8_t awkward_ArrayBuilder_bytestring_length(void *arraybuilder, const char *x, int64_t length)
C interface to ArrayBuilder::bytestring.
LIBAWKWARD_EXPORT_SYMBOL uint8_t awkward_ArrayBuilder_field_check(void *arraybuilder, const char *key)
C interface to ArrayBuilder::field_check.
LIBAWKWARD_EXPORT_SYMBOL uint8_t awkward_ArrayBuilder_beginlist(void *arraybuilder)
C interface to ArrayBuilder::beginlist.
LIBAWKWARD_EXPORT_SYMBOL uint8_t awkward_ArrayBuilder_beginrecord(void *arraybuilder)
C interface to ArrayBuilder::beginrecord.
#define LIBAWKWARD_EXPORT_SYMBOL
Definition: common.h:45
LIBAWKWARD_EXPORT_SYMBOL uint8_t awkward_ArrayBuilder_bytestring(void *arraybuilder, const char *x)
C interface to ArrayBuilder::bytestring.
const std::string key(const RecordLookupPtr &recordlookup, int64_t fieldindex, int64_t numfields)
Returns the key associated with a field index, given a RecordLookup and a number of fields...
Definition: BitMaskedArray.h:15
Abstract class to represent the output of ak.to_buffers. In Python, this would be a dict of NumPy arr...
Definition: Builder.h:22
LIBAWKWARD_EXPORT_SYMBOL uint8_t awkward_ArrayBuilder_null(void *arraybuilder)
C interface to ArrayBuilder::null.
std::string name(Mapping a, V value)
Definition: datetime_util.h:39
LIBAWKWARD_EXPORT_SYMBOL uint8_t awkward_ArrayBuilder_beginrecord_fast(void *arraybuilder, const char *name)
C interface to ArrayBuilder::beginrecord_fast.
LIBAWKWARD_EXPORT_SYMBOL uint8_t awkward_ArrayBuilder_real(void *arraybuilder, double x)
C interface to ArrayBuilder::real.
User interface to the Builder system: the ArrayBuilder is a fixed reference while the Builder subclas...
Definition: ArrayBuilder.h:26
LIBAWKWARD_EXPORT_SYMBOL uint8_t awkward_ArrayBuilder_integer(void *arraybuilder, int64_t x)
C interface to ArrayBuilder::integer.
LIBAWKWARD_EXPORT_SYMBOL uint8_t awkward_ArrayBuilder_beginrecord_check(void *arraybuilder, const char *name)
C interface to ArrayBuilder::beginrecord_check.
LIBAWKWARD_EXPORT_SYMBOL uint8_t awkward_ArrayBuilder_index(void *arraybuilder, int64_t index)
C interface to ArrayBuilder::index.
LIBAWKWARD_EXPORT_SYMBOL uint8_t awkward_ArrayBuilder_datetime(void *arraybuilder, int64_t x, const char *unit)
C interface to ArrayBuilder::datetime.
LIBAWKWARD_EXPORT_SYMBOL uint8_t awkward_ArrayBuilder_begintuple(void *arraybuilder, int64_t numfields)
C interface to ArrayBuilder::begintuple.
const BuilderPtr builder() const
Definition: ArrayBuilder.h:229
LIBAWKWARD_EXPORT_SYMBOL uint8_t awkward_ArrayBuilder_endtuple(void *arraybuilder)
C interface to ArrayBuilder::endtuple.
LIBAWKWARD_EXPORT_SYMBOL uint8_t awkward_ArrayBuilder_endrecord(void *arraybuilder)
C interface to ArrayBuilder::endrecord.
LIBAWKWARD_EXPORT_SYMBOL uint8_t awkward_ArrayBuilder_clear(void *arraybuilder)
C interface to ArrayBuilder::clear.
LIBAWKWARD_EXPORT_SYMBOL uint8_t awkward_ArrayBuilder_endlist(void *arraybuilder)
C interface to ArrayBuilder::endlist.
LIBAWKWARD_EXPORT_SYMBOL uint8_t awkward_ArrayBuilder_field_fast(void *arraybuilder, const char *key)
C interface to ArrayBuilder::field_fast.
std::shared_ptr< Builder > BuilderPtr
Definition: ArrayBuilder.h:19
LIBAWKWARD_EXPORT_SYMBOL uint8_t awkward_ArrayBuilder_complex(void *arraybuilder, double real, double imag)
C interface to ArrayBuilder::complex.
LIBAWKWARD_EXPORT_SYMBOL uint8_t awkward_ArrayBuilder_string_length(void *arraybuilder, const char *x, int64_t length)
C interface to ArrayBuilder::string.
LIBAWKWARD_EXPORT_SYMBOL uint8_t awkward_ArrayBuilder_boolean(void *arraybuilder, bool x)
C interface to ArrayBuilder::boolean.
std::shared_ptr< Content > ContentPtr
Definition: ArrayBuilder.h:16
LIBAWKWARD_EXPORT_SYMBOL uint8_t awkward_ArrayBuilder_string(void *arraybuilder, const char *x)
C interface to ArrayBuilder::string.
void builder_update(BuilderPtr builder)
Definition: ArrayBuilder.h:231
LIBAWKWARD_EXPORT_SYMBOL uint8_t awkward_ArrayBuilder_length(void *arraybuilder, int64_t *result)
C interface to ArrayBuilder::length.
Abstract base class for nodes within an ArrayBuilder that cumulatively discover an array&#39;s type and f...
Definition: Builder.h:40