Awkward Array: include/awkward/type/Type.h Source File

Loading...
Searching...
No Matches
Type.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_TYPE_H_
4#define AWKWARD_TYPE_H_
5
6#include <memory>
7#include <string>
8#include <vector>
9
10#include "awkward/common.h"
11#include "awkward/util.h"
12
13namespace awkward {
14 class Content;
15 using ContentPtr = std::shared_ptr<Content>;
16
17 class Type;
18 using TypePtr = std::shared_ptr<Type>;
19
23 class LIBAWKWARD_EXPORT_SYMBOL Type {
24 public:
27 Type(const util::Parameters& parameters, const std::string& typestr);
28
32 virtual ~Type();
33
40 virtual std::string
41 tostring_part(const std::string& indent,
42 const std::string& pre,
43 const std::string& post) const = 0;
44
47 virtual const TypePtr
48 shallow_copy() const = 0;
49
57 virtual bool
58 equal(const TypePtr& other, bool check_parameters) const = 0;
59
62 virtual int64_t
63 numfields() const = 0;
64
67 virtual int64_t
68 fieldindex(const std::string& key) const = 0;
69
74 virtual const std::string
75 key(int64_t fieldindex) const = 0;
76
79 virtual bool
80 haskey(const std::string& key) const = 0;
81
84 virtual const std::vector<std::string>
85 keys() const = 0;
86
88 virtual const ContentPtr
89 empty() const = 0;
90
98 const util::Parameters
99 parameters() const;
100
111 void
112 setparameters(const util::Parameters& parameters);
113
122 const std::string
123 parameter(const std::string& key) const;
124
135 void
136 setparameter(const std::string& key, const std::string& value);
137
148 bool
149 parameter_equals(const std::string& key, const std::string& value) const;
150
164 bool
165 parameters_equal(const util::Parameters& other, bool check_all) const;
166
169 bool
170 parameter_isstring(const std::string& key) const;
171
174 bool
175 parameter_isname(const std::string& key) const;
176
179 const std::string
180 parameter_asstring(const std::string& key) const;
181
185 const std::string
186 tostring() const;
187
192 const std::string
193 compare(TypePtr supertype);
194
197 const std::string
198 typestr() const;
199
200 protected:
204 bool
205 get_typestr(std::string& output) const;
206
209 bool
210 parameters_empty() const;
211
214 std::string
215 wrap_categorical(const std::string& output) const;
216
219 const std::string
220 string_parameters() const;
221
223 util::Parameters parameters_;
225 const std::string typestr_;
226 };
227}
228
229#endif // AWKWARD_TYPE_H_
awkward::Type
Abstract superclass of all high level types (flat hierarchy).
Definition: Type.h:23
awkward::Type::parameter_isstring
bool parameter_isstring(const std::string &key) const
Returns true if the parameter associated with key is a string; false otherwise.
awkward::Type::parameters_
util::Parameters parameters_
See parameters.
Definition: Type.h:223
awkward::Type::parameters_empty
bool parameters_empty() const
Internal function to determine if there are no parameters except __categorical__.
awkward::Type::empty
virtual const ContentPtr empty() const =0
Returns an empty array (Content) with this type.
awkward::Type::parameter_equals
bool parameter_equals(const std::string &key, const std::string &value) const
Returns true if the parameter associated with key exists and is equal to value; false otherwise.
awkward::Type::parameter
const std::string parameter(const std::string &key) const
Custom parameters inherited from the Content that this type describes.
awkward::Type::tostring
const std::string tostring() const
Returns a string representation of the type as a Datashape or its typestr overload (if non-empty).
awkward::Type::shallow_copy
virtual const TypePtr shallow_copy() const =0
Copies this Type without copying any hierarchically nested types.
awkward::Type::compare
const std::string compare(TypePtr supertype)
Returns a string showing a side-by-side comparison of two types, highlighting differences.
awkward::Type::get_typestr
bool get_typestr(std::string &output) const
Internal function that replaces output in-place with the typestr and returns true if the typestr is n...
awkward::Type::key
virtual const std::string key(int64_t fieldindex) const =0
The record name associated with a given field index or the tuple index as a string (e....
awkward::Type::equal
virtual bool equal(const TypePtr &other, bool check_parameters) const =0
Returns true if this type is equal to other; false otherwise.
awkward::Type::numfields
virtual int64_t numfields() const =0
The number of fields in the first nested tuple or records or -1 if this array does not contain a Reco...
awkward::Type::wrap_categorical
std::string wrap_categorical(const std::string &output) const
Internal function that wraps output with categorical[type= and ] if __categorical__ is true; passes t...
awkward::Type::parameters_equal
bool parameters_equal(const util::Parameters &other, bool check_all) const
Returns true if all parameters of this type are equal to the other parameters.
awkward::Type::tostring_part
virtual std::string tostring_part(const std::string &indent, const std::string &pre, const std::string &post) const =0
Internal function to build an output string for tostring.
awkward::Type::fieldindex
virtual int64_t fieldindex(const std::string &key) const =0
The position of a tuple or record key name if this array contains a RecordType.
awkward::Type::parameter_asstring
const std::string parameter_asstring(const std::string &key) const
Returns the parameter associated with key as a string if parameter_isstring; raises an error otherwis...
awkward::Type::typestr
const std::string typestr() const
Optional string that overrides the default string representation (missing if empty).
awkward::Type::setparameter
void setparameter(const std::string &key, const std::string &value)
Assign one parameter to this type (in-place).
awkward::Type::setparameters
void setparameters(const util::Parameters &parameters)
Assign one parameter for this type (in-place).
awkward::Type::parameter_isname
bool parameter_isname(const std::string &key) const
Returns true if the parameter associated with key is a string that matches [A-Za-z_][A-Za-z_0-9]*; fa...
awkward::Type::Type
Type(const util::Parameters &parameters, const std::string &typestr)
Called by all subclass constructors; assigns parameters and typestr upon construction.
awkward::Type::keys
virtual const std::vector< std::string > keys() const =0
A list of RecordType keys or an empty list if this type does not contain a RecordType.
awkward::Type::~Type
virtual ~Type()
Virtual destructor acts as a first non-inline virtual function that determines a specific translation...
awkward::Type::string_parameters
const std::string string_parameters() const
Internal function to format parameters as part of the tostring string.
awkward::Type::typestr_
const std::string typestr_
See typestr.
Definition: Type.h:225
awkward::Type::parameters
const util::Parameters parameters() const
Get one parameter from this type.
awkward::Type::haskey
virtual bool haskey(const std::string &key) const =0
Returns true if the type contains a RecordType with the specified key; false otherwise.
common.h
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::ContentPtr
std::shared_ptr< Content > ContentPtr
Definition: Content.h:15
awkward::TypePtr
std::shared_ptr< Type > TypePtr
Definition: Content.h:23
util.h