Loading...
Searching...
No Matches
Builder.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_FILLABLE_H_
4#define AWKWARD_FILLABLE_H_
5
6#include <complex>
7#include <string>
8#include <vector>
9
10#include "awkward/common.h"
11
12namespace awkward {
13 class Builder;
14 using BuilderPtr = std::shared_ptr<Builder>;
15
21 public:
26 virtual void
27 copy_buffer(const std::string& name, const void* source, int64_t num_bytes) = 0;
28
30 virtual void
31 full_buffer(const std::string& name, int64_t length, int64_t value, const std::string& dtype) = 0;
32
33 virtual void*
34 empty_buffer(const std::string& name, int64_t num_bytes) = 0;
35 };
36
41 class EXPORT_SYMBOL Builder: public std::enable_shared_from_this<Builder> {
42 public:
46 virtual ~Builder();
47
49 virtual const std::string
50 classname() const = 0;
51
54 virtual const std::string
55 to_buffers(BuffersContainer& container, int64_t& form_key_id) const = 0;
56
58 virtual int64_t
59 length() const = 0;
60
63 virtual void
64 clear() = 0;
65
68 virtual bool
69 active() const = 0;
70
72 virtual const BuilderPtr
73 null() = 0;
74
76 virtual const BuilderPtr
77 boolean(bool x) = 0;
78
80 virtual const BuilderPtr
81 integer(int64_t x) = 0;
82
84 virtual const BuilderPtr
85 real(double x) = 0;
86
88 virtual const BuilderPtr
89 complex(std::complex<double> x) = 0;
90
92 virtual const BuilderPtr
93 datetime(int64_t x, const std::string& unit) = 0;
94
96 virtual const BuilderPtr
97 timedelta(int64_t x, const std::string& unit) = 0;
98
108 virtual const BuilderPtr
109 string(const char* x, int64_t length, const char* encoding) = 0;
110
112 virtual const BuilderPtr
114
116 virtual const BuilderPtr
117 endlist() = 0;
118
120 virtual const BuilderPtr
121 begintuple(int64_t numfields) = 0;
122
125 virtual const BuilderPtr
126 index(int64_t index) = 0;
127
129 virtual const BuilderPtr
130 endtuple() = 0;
131
143 virtual const BuilderPtr
144 beginrecord(const char* name, bool check) = 0;
145
157 virtual void
158 field(const char* key, bool check) = 0;
159
161 virtual const BuilderPtr
163 };
164}
165
166#endif // AWKWARD_FILLABLE_H_
Abstract class to represent the output of ak.to_buffers. In Python, this would be a dict of NumPy arr...
Definition Builder.h:20
virtual void full_buffer(const std::string &name, int64_t length, int64_t value, const std::string &dtype)=0
Create an array initialized to a given fill value.
virtual void * empty_buffer(const std::string &name, int64_t num_bytes)=0
virtual void copy_buffer(const std::string &name, const void *source, int64_t num_bytes)=0
Copy data at source with num_bytes into the BuffersContainer with name.
Abstract base class for nodes within an ArrayBuilder that cumulatively discover an array's type and f...
Definition Builder.h:41
virtual const BuilderPtr integer(int64_t x)=0
Adds an integer value x to the accumulated data.
virtual ~Builder()
Virtual destructor acts as a first non-inline virtual function that determines a specific translation...
virtual const std::string to_buffers(BuffersContainer &container, int64_t &form_key_id) const =0
Copy the current snapshot into the BuffersContainer and return a Form as a std::string (JSON).
virtual void field(const char *key, bool check)=0
Sets the pointer to a given record field key; the next command will fill that slot.
virtual const BuilderPtr datetime(int64_t x, const std::string &unit)=0
Adds a datetime value x to the accumulated data.
virtual const BuilderPtr endlist()=0
Ends a nested list.
virtual void clear()=0
Removes all accumulated data without resetting the type knowledge.
virtual bool active() const =0
If true, this node has started but has not finished a multi-step command (e.g. beginX ....
virtual const BuilderPtr beginlist()=0
Begins building a nested list.
virtual const BuilderPtr string(const char *x, int64_t length, const char *encoding)=0
Adds a string value x with a given length and encoding to the accumulated data.
virtual const BuilderPtr null()=0
Adds a null value to the accumulated data.
virtual const BuilderPtr endtuple()=0
Ends a tuple.
virtual const std::string classname() const =0
User-friendly name of this class.
virtual const BuilderPtr timedelta(int64_t x, const std::string &unit)=0
Adds a timedelta value x to the accumulated data.
virtual const BuilderPtr complex(std::complex< double > x)=0
Adds a complex value x to the accumulated data.
virtual const BuilderPtr index(int64_t index)=0
Sets the pointer to a given tuple field index; the next command will fill that slot.
virtual const BuilderPtr beginrecord(const char *name, bool check)=0
Begins building a record with an optional name.
virtual const BuilderPtr begintuple(int64_t numfields)=0
Begins building a tuple with a fixed number of fields.
virtual const BuilderPtr boolean(bool x)=0
Adds a boolean value x to the accumulated data.
virtual const BuilderPtr endrecord()=0
Ends a record.
virtual int64_t length() const =0
Current length of the accumulated array.
virtual const BuilderPtr real(double x)=0
Adds a real value x to the accumulated data.
#define EXPORT_SYMBOL
Definition common.h:25
Definition ArrayBuilder.h:14
std::shared_ptr< Builder > BuilderPtr
Definition ArrayBuilder.h:16