Loading...
Searching...
No Matches
FormBuilder.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_FORMBUILDER_H_
4#define AWKWARD_FORMBUILDER_H_
5
6#include <complex>
7#include <map>
8#include <memory>
9#include <string>
13
14namespace awkward {
15
16 using ForthOutputBufferMap = std::map<std::string, std::shared_ptr<ForthOutputBuffer>>;
17
18 template <typename T, typename I> class LayoutBuilder;
19
20 template<typename T, typename I>
22
29 template<typename T, typename I>
31 public:
35 virtual ~FormBuilder();
36
38 virtual const std::string
39 classname() const = 0;
40
43 virtual const std::string
44 to_buffers(BuffersContainer& container, const ForthOutputBufferMap& outputs) const = 0;
45
47 virtual ssize_t
48 len(const ForthOutputBufferMap& outputs) const = 0;
49
50 virtual bool
51 is_complex() const {
52 return false;
53 }
54
55 // /// @brief The Form describing the array.
56 // virtual const FormPtr
57 // form() const = 0;
58
60 virtual const std::string
61 vm_output() const = 0;
62
64 virtual const std::string
65 vm_output_data() const = 0;
66
68 virtual const std::string
69 vm_func() const = 0;
70
72 virtual const std::string
73 vm_func_name() const = 0;
74
76 virtual const std::string
77 vm_func_type() const = 0;
78
81 virtual const std::string
82 vm_from_stack() const = 0;
83
85 virtual const std::string
86 vm_error() const = 0;
87
89 virtual void
90 tag(int8_t x) {
91 throw std::runtime_error(
92 std::string("FormBuilder 'tag' is not implemented yet"));
93 }
94
96 virtual void
98 throw std::runtime_error(
99 std::string("FormBuilder 'boolean' is not implemented yet"));
100 }
101
103 virtual void
104 int64(int64_t x, LayoutBuilderPtr<T, I> builder) {
105 throw std::runtime_error(
106 std::string("FormBuilder 'int64' is not implemented yet"));
107 }
108
110 virtual void
111 float64(double x, LayoutBuilderPtr<T, I> builder) {
112 throw std::runtime_error(
113 std::string("FormBuilder 'float64' is not implemented yet"));
114 }
115
117 virtual void
118 complex(std::complex<double> x, LayoutBuilderPtr<T, I> builder) {
119 throw std::runtime_error(
120 std::string("FormBuilder 'complex' is not implemented yet"));
121 }
122
125 virtual void
126 bytestring(const std::string& x, LayoutBuilderPtr<T, I> builder) {
127 throw std::runtime_error(
128 std::string("FormBuilder 'bytestring' is not implemented yet"));
129 }
130
133 virtual void
134 string(const std::string& x, LayoutBuilderPtr<T, I> builder) {
135 throw std::runtime_error(
136 std::string("FormBuilder 'string' is not implemented yet"));
137 }
138
140 virtual void
142 throw std::runtime_error(
143 std::string("FormBuilder 'begin_list' is not implemented yet"));
144 }
145
147 virtual void
149 throw std::runtime_error(
150 std::string("FormBuilder 'end_list' is not implemented yet"));
151 }
152
155 virtual bool
157 return false;
158 }
159
161 virtual std::string
162 parameters_as_string(const util::Parameters& parameters) const {
163 std::stringstream p;
164 if (!parameters.empty()) {
165 p << "\"parameters\": {";
166 for (auto const &pair: parameters) {
167 p << "\"" << pair.first << "\": " << pair.second << " ";
168 }
169 p << "}, ";
170 }
171 return p.str();
172 }
173
174 };
175
176 template <typename T, typename I>
177 using FormBuilderPtr = std::shared_ptr<FormBuilder<T, I>>;
178
179}
180
181#endif // AWKWARD_FORMBUILDER_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
Abstract base class for nodes within a LayoutBuilder Every builder will have an output buffer based o...
Definition: FormBuilder.h:30
virtual void complex(std::complex< double > x, LayoutBuilderPtr< T, I > builder)
Adds a complex value x to the accumulated data.
Definition: FormBuilder.h:118
virtual ~FormBuilder()
Virtual destructor acts as a first non-inline virtual function that determines a specific translation...
virtual void float64(double x, LayoutBuilderPtr< T, I > builder)
Adds a real value x to the accumulated data.
Definition: FormBuilder.h:111
virtual bool active()
If true, this node has started but has not finished a multi-step command (e.g. begin_list ....
Definition: FormBuilder.h:156
virtual void int64(int64_t x, LayoutBuilderPtr< T, I > builder)
Adds an integer value x to the accumulated data.
Definition: FormBuilder.h:104
virtual void bytestring(const std::string &x, LayoutBuilderPtr< T, I > builder)
Adds an unencoded bytestring x in STL format to the accumulated data.
Definition: FormBuilder.h:126
virtual const std::string to_buffers(BuffersContainer &container, const ForthOutputBufferMap &outputs) const =0
Copy the current snapshot into the BuffersContainer and return a Form as a std::string (JSON).
virtual ssize_t len(const ForthOutputBufferMap &outputs) const =0
The builder's output buffer length.
virtual bool is_complex() const
Definition: FormBuilder.h:51
virtual const std::string vm_func_type() const =0
The array builder VM function type.
virtual void boolean(bool x, LayoutBuilderPtr< T, I > builder)
Adds a boolean value x to the accumulated data.
Definition: FormBuilder.h:97
virtual void begin_list(LayoutBuilderPtr< T, I > builder)
Begins building a nested list.
Definition: FormBuilder.h:141
virtual const std::string vm_func() const =0
AwkwardForth virtual machine instructions of the array builder function.
virtual const std::string vm_output_data() const =0
AwkwardForth virtual machine data output key.
virtual void end_list(LayoutBuilderPtr< T, I > builder)
Ends a nested list.
Definition: FormBuilder.h:148
virtual void string(const std::string &x, LayoutBuilderPtr< T, I > builder)
Adds a UTF-8 encoded bytestring x in STL format to the accumulated data.
Definition: FormBuilder.h:134
virtual const std::string classname() const =0
User-friendly name of this class.
virtual const std::string vm_func_name() const =0
The array builder VM function name.
virtual const std::string vm_output() const =0
AwkwardForth virtual machine instructions of the data outputs.
virtual void tag(int8_t x)
Adds an integer value x to the accumulated data.
Definition: FormBuilder.h:90
virtual std::string parameters_as_string(const util::Parameters &parameters) const
FIXME: find if it's already implemented in utils.
Definition: FormBuilder.h:162
virtual const std::string vm_error() const =0
Error messages in the AwkwardForth virtual machine instructions.
virtual const std::string vm_from_stack() const =0
AwkwardForth virtual machine instructions to retrieve the data from the VM stack.
User interface to the FormBuilder system: the LayoutBuilder is a fixed reference while the FormBuilde...
Definition: LayoutBuilder.h:62
#define LIBAWKWARD_EXPORT_SYMBOL
Definition: common.h:45
std::map< std::string, std::string > Parameters
Definition: util.h:165
Definition: BitMaskedArray.h:15
std::map< std::string, std::shared_ptr< ForthOutputBuffer > > ForthOutputBufferMap
Definition: FormBuilder.h:16
std::shared_ptr< FormBuilder< T, I > > FormBuilderPtr
Definition: FormBuilder.h:177