All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
util.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_UTIL_H_
4#define AWKWARD_UTIL_H_
5
6#include <string>
7#include <vector>
8#include <map>
9#include <memory>
10
11#include "awkward/common.h"
12
13#ifndef _MSC_VER
14 #include "dlfcn.h"
15#endif
16
17namespace awkward {
18 namespace util {
22 enum class dtype {
24 boolean,
25 int8,
26 int16,
27 int32,
28 int64,
29 uint8,
30 uint16,
31 uint32,
32 uint64,
33 float16,
34 float32,
35 float64,
42 size
43 };
44
46 dtype
47 name_to_dtype(const std::string& name);
48
50 const std::string
52
54 dtype
55 format_to_dtype(const std::string& format, int64_t itemsize);
56
58 const std::string
59 dtype_to_format(dtype dt, const std::string& format = "");
60
62 int64_t
64
66 bool
68
70 bool
72
74 bool
76
78 bool
80
82 bool
84
92 void
93 handle_error(const struct Error &err,
94 const std::string &classname = std::string(""));
95
106 std::string
107 quote(const std::string& x);
108
109 using RecordLookup = std::vector<std::string>;
110 using RecordLookupPtr = std::shared_ptr<RecordLookup>;
111
117 init_recordlookup(int64_t numfields);
118
121 int64_t
122 fieldindex(const RecordLookupPtr& recordlookup,
123 const std::string& key,
124 int64_t numfields);
125
128 const std::string
129 key(const RecordLookupPtr& recordlookup,
130 int64_t fieldindex,
131 int64_t numfields);
132
135 bool
136 haskey(const RecordLookupPtr& recordlookup,
137 const std::string& key,
138 int64_t numfields);
139
142 const std::vector<std::string>
143 keys(const RecordLookupPtr& recordlookup, int64_t numfields);
144
145 using Parameters = std::map<std::string, std::string>;
146
149 bool
150 json_equals(const std::string &myvalue, const std::string &value);
151
158 bool
159 parameter_equals(const Parameters& parameters,
160 const std::string& key,
161 const std::string& value);
162
172 bool
173 parameters_equal(const Parameters& self, const Parameters& other, bool check_all);
174
177 void
178 merge_parameters(Parameters& output, const Parameters& input);
179
182 bool
183 parameter_isstring(const Parameters& parameters, const std::string& key);
184
187 bool
188 parameter_isname(const Parameters& parameters, const std::string& key);
189
192 const std::string
193 parameter_asstring(const Parameters& parameters, const std::string& key);
194
195 using TypeStrs = std::map<std::string, std::string>;
196
199 std::string
200 gettypestr(const Parameters& parameters,
201 const TypeStrs& typestrs);
202
204 enum class ForthError {
205 // execution can continue
206 none,
207
208 // execution cannot continue
209 not_ready,
210 is_done,
211 user_halt,
224
225 size
226 };
227
239 template <typename T>
241 public:
244 void
245 operator()(T const* ptr) {
246 uint8_t const* in = reinterpret_cast<uint8_t const*>(ptr);
247 delete [] in;
248 }
249 };
250
251 }
252}
253
254#endif // AWKWARD_UTIL_H_
Used as a std::shared_ptr deleter (second argument) to overload delete ptr with delete[] ptr.
Definition: util.h:240
void operator()(T const *ptr)
Called by std::shared_ptr when its reference count reaches zero.
Definition: util.h:245
#define LIBAWKWARD_EXPORT_SYMBOL
Definition: common.h:45
const std::string parameter_asstring(const Parameters &parameters, const std::string &key)
Returns the parameter associated with key as a string if parameter_isstring; raises an error otherwis...
bool is_signed(dtype dt)
True if the dtype is a signed integer.
dtype format_to_dtype(const std::string &format, int64_t itemsize)
Convert a NumPy format string and itemsize into a dtype enum.
bool parameters_equal(const Parameters &self, const Parameters &other, bool check_all)
Returns true if all key-value pairs in self is equal to all key-value pairs in other.
std::map< std::string, std::string > Parameters
Definition: util.h:145
bool parameter_equals(const Parameters &parameters, const std::string &key, const std::string &value)
Returns true if the value associated with a key in parameters is equal to the specified value.
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.
bool parameter_isname(const Parameters &parameters, const std::string &key)
Returns true if the parameter associated with key is a string that matches [A-Za-z_][A-Za-z_0-9]*; fa...
bool parameter_isstring(const Parameters &parameters, const std::string &key)
Returns true if the parameter associated with key is a string; false otherwise.
bool json_equals(const std::string &myvalue, const std::string &value)
Returns true if myvalue is equal to value when interpreted as JSON.
bool is_complex(dtype dt)
True if the dtype is a complex number.
bool is_unsigned(dtype dt)
True if the dtype is an unsigned integer.
std::string quote(const std::string &x)
Puts quotation marks around a string and escapes the appropriate characters.
int64_t fieldindex(const RecordLookupPtr &recordlookup, const std::string &key, int64_t numfields)
Returns the field index associated with a key, given a RecordLookup and a number of fields.
dtype name_to_dtype(const std::string &name)
Returns the name associated with a given dtype.
std::shared_ptr< RecordLookup > RecordLookupPtr
Definition: util.h:110
Mapping::value_type::value_type value(Mapping a, const std::string &name)
Definition: datetime_util.h:49
std::vector< std::string > RecordLookup
Definition: util.h:109
void merge_parameters(Parameters &output, const Parameters &input)
Merges a set of input parameters with output, keeping only those that are common to all sets.
ForthError
Exhaustive list of runtime errors possible in the ForthMachine.
Definition: util.h:204
bool is_integer(dtype dt)
True if the dtype is a non-boolean integer (signed or unsigned).
std::map< std::string, std::string > TypeStrs
Definition: util.h:195
const std::string dtype_to_name(dtype dt)
Returns the name associated with a given dtype.
std::string gettypestr(const Parameters &parameters, const TypeStrs &typestrs)
Extracts a custom type string from typestrs if required by one of the parameters or an empty string i...
RecordLookupPtr init_recordlookup(int64_t numfields)
Initializes a RecordLookup by assigning each element with a string representation of its field index ...
void handle_error(const struct Error &err, const std::string &classname=std::string(""))
If the Error struct contains an error message (from a cpu-kernel through the C interface),...
dtype
NumPy dtypes that can be interpreted within Awkward C++ (only the primitive, fixed-width types)....
Definition: util.h:22
bool haskey(const RecordLookupPtr &recordlookup, const std::string &key, int64_t numfields)
Returns true if a RecordLookup has a given key; false otherwise.
const std::vector< std::string > keys(const RecordLookupPtr &recordlookup, int64_t numfields)
Returns a given RecordLookup as keys or generate anonymous ones form a number of fields.
const std::string dtype_to_format(dtype dt, const std::string &format="")
Convert a dtype enum into a NumPy format string.
int64_t dtype_to_itemsize(dtype dt)
Convert a dtype enum into an itemsize.
std::string name(Mapping a, V value)
Definition: datetime_util.h:39
bool is_real(dtype dt)
True if the dtype is a non-complex floating point number.
Definition: ArrayBuilder.h:14
Definition: common.h:57