Awkward Array: include/awkward/layoutbuilder/FormBuilder.h Source File

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>
10#include "awkward/forth/ForthMachine.h"
11#include "awkward/forth/ForthOutputBuffer.h"
12#include "awkward/builder/Builder.h"
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>
21 using LayoutBuilderPtr = LayoutBuilder<T, I>*;
22
29 template<typename T, typename I>
30 class LIBAWKWARD_EXPORT_SYMBOL FormBuilder {
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
97 boolean(bool x, LayoutBuilderPtr<T, I> builder) {
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
141 begin_list(LayoutBuilderPtr<T, I> builder) {
142 throw std::runtime_error(
143 std::string("FormBuilder 'begin_list' is not implemented yet"));
144 }
145
147 virtual void
148 end_list(LayoutBuilderPtr<T, I> builder) {
149 throw std::runtime_error(
150 std::string("FormBuilder 'end_list' is not implemented yet"));
151 }
152
155 virtual bool
156 active() {
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_
Builder.h
ForthMachine.h
ForthOutputBuffer.h
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
awkward::FormBuilder
Abstract base class for nodes within a LayoutBuilder Every builder will have an output buffer based o...
Definition: FormBuilder.h:30
awkward::FormBuilder::complex
virtual void complex(std::complex< double > x, LayoutBuilderPtr< T, I > builder)
Adds a complex value x to the accumulated data.
Definition: FormBuilder.h:118
awkward::FormBuilder::~FormBuilder
virtual ~FormBuilder()
Virtual destructor acts as a first non-inline virtual function that determines a specific translation...
awkward::FormBuilder::float64
virtual void float64(double x, LayoutBuilderPtr< T, I > builder)
Adds a real value x to the accumulated data.
Definition: FormBuilder.h:111
awkward::FormBuilder::active
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
awkward::FormBuilder::int64
virtual void int64(int64_t x, LayoutBuilderPtr< T, I > builder)
Adds an integer value x to the accumulated data.
Definition: FormBuilder.h:104
awkward::FormBuilder::bytestring
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
awkward::FormBuilder::to_buffers
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).
awkward::FormBuilder::len
virtual ssize_t len(const ForthOutputBufferMap &outputs) const =0
The builder's output buffer length.
awkward::FormBuilder::is_complex
virtual bool is_complex() const
Definition: FormBuilder.h:51
awkward::FormBuilder::vm_func_type
virtual const std::string vm_func_type() const =0
The array builder VM function type.
awkward::FormBuilder::boolean
virtual void boolean(bool x, LayoutBuilderPtr< T, I > builder)
Adds a boolean value x to the accumulated data.
Definition: FormBuilder.h:97
awkward::FormBuilder::begin_list
virtual void begin_list(LayoutBuilderPtr< T, I > builder)
Begins building a nested list.
Definition: FormBuilder.h:141
awkward::FormBuilder::vm_func
virtual const std::string vm_func() const =0
AwkwardForth virtual machine instructions of the array builder function.
awkward::FormBuilder::vm_output_data
virtual const std::string vm_output_data() const =0
AwkwardForth virtual machine data output key.
awkward::FormBuilder::end_list
virtual void end_list(LayoutBuilderPtr< T, I > builder)
Ends a nested list.
Definition: FormBuilder.h:148
awkward::FormBuilder::string
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
awkward::FormBuilder::classname
virtual const std::string classname() const =0
User-friendly name of this class.
awkward::FormBuilder::vm_func_name
virtual const std::string vm_func_name() const =0
The array builder VM function name.
awkward::FormBuilder::vm_output
virtual const std::string vm_output() const =0
AwkwardForth virtual machine instructions of the data outputs.
awkward::FormBuilder::tag
virtual void tag(int8_t x)
Adds an integer value x to the accumulated data.
Definition: FormBuilder.h:90
awkward::FormBuilder::parameters_as_string
virtual std::string parameters_as_string(const util::Parameters &parameters) const
FIXME: find if it's already implemented in utils.
Definition: FormBuilder.h:162
awkward::FormBuilder::vm_error
virtual const std::string vm_error() const =0
Error messages in the AwkwardForth virtual machine instructions.
awkward::FormBuilder::vm_from_stack
virtual const std::string vm_from_stack() const =0
AwkwardForth virtual machine instructions to retrieve the data from the VM stack.
awkward::LayoutBuilder
User interface to the FormBuilder system: the LayoutBuilder is a fixed reference while the FormBuilde...
Definition: LayoutBuilder.h:62
LIBAWKWARD_EXPORT_SYMBOL
#define LIBAWKWARD_EXPORT_SYMBOL
Definition: common.h:45
awkward::util::Parameters
std::map< std::string, std::string > Parameters
Definition: util.h:165
awkward
Definition: BitMaskedArray.h:15
awkward::ForthOutputBufferMap
std::map< std::string, std::shared_ptr< ForthOutputBuffer > > ForthOutputBufferMap
Definition: FormBuilder.h:16
awkward::FormBuilderPtr
std::shared_ptr< FormBuilder< T, I > > FormBuilderPtr
Definition: FormBuilder.h:177