uzuki2
Recovering R lists faithfully from HDF5 or JSON
Loading...
Searching...
No Matches
interfaces.hpp
Go to the documentation of this file.
1#ifndef UZUKI2_INTERFACES_HPP
2#define UZUKI2_INTERFACES_HPP
3
4#include <string>
5#include <memory>
6#include <vector>
7#include <cstdint>
8
14namespace uzuki2 {
15
28enum Type {
29 INTEGER,
30 NUMBER,
31 STRING,
32 BOOLEAN,
33 FACTOR,
34 LIST,
35 NOTHING,
36 EXTERNAL
37};
38
43inline bool is_vector(Type t) {
44 return (t >= 0 && t < LIST);
45}
46
50class Base {
51public:
55 Base() = default;
56 Base(Base&&) = default;
57 Base(const Base&) = default;
58 Base& operator=(Base&&) = default;
59 Base& operator=(const Base&) = default;
60 virtual ~Base() = default;
68 virtual Type type() const = 0;
69};
70
74class Vector : public Base {
75public:
79 virtual size_t size () const = 0;
80
88 virtual void set_name(size_t i, std::string n) = 0;
89
95 virtual void set_missing(size_t i) = 0;
96};
97
101class IntegerVector : public Vector {
102public:
103 Type type() const {
104 return INTEGER;
105 }
106
113 virtual void set(size_t i, int32_t v) = 0;
114};
115
119class NumberVector : public Vector {
120public:
121 Type type() const {
122 return NUMBER;
123 }
124
131 virtual void set(size_t i, double v) = 0;
132};
133
137class StringVector : public Vector {
138public:
139 Type type() const {
140 return STRING;
141 }
142
149 virtual void set(size_t i, std::string v) = 0;
150
158 enum Format {
159 NONE,
160 DATE,
161 DATETIME
162 };
163};
164
168class BooleanVector : public Vector {
169public:
170 Type type() const {
171 return BOOLEAN;
172 }
173
180 virtual void set(size_t i, bool v) = 0;
181};
182
189class Factor : public Vector {
190public:
191 Type type() const {
192 return FACTOR;
193 }
194
201 virtual void set(size_t i, size_t v) = 0;
202
209 virtual void set_level(size_t il, std::string vl) = 0;
210};
211
215class Nothing : public Base {
216public:
217 Type type() const {
218 return NOTHING;
219 }
220};
221
227class External : public Base {
228public:
229 Type type() const {
230 return EXTERNAL;
231 }
232};
233
237class List : public Base {
238public:
239 Type type() const {
240 return LIST;
241 }
242
246 virtual size_t size() const = 0;
247
254 virtual void set(size_t i, std::shared_ptr<Base> v) = 0;
255
263 virtual void set_name(size_t i, std::string n) = 0;
264};
265
266}
267
268#endif
Base interface for all R objects.
Definition interfaces.hpp:50
virtual Type type() const =0
Interface for a boolean vector.
Definition interfaces.hpp:168
virtual void set(size_t i, bool v)=0
Type type() const
Definition interfaces.hpp:170
Interface for unsupported objects.
Definition interfaces.hpp:227
Type type() const
Definition interfaces.hpp:229
Interface for a factor.
Definition interfaces.hpp:189
virtual void set_level(size_t il, std::string vl)=0
Type type() const
Definition interfaces.hpp:191
virtual void set(size_t i, size_t v)=0
Interface for integer vectors.
Definition interfaces.hpp:101
Type type() const
Definition interfaces.hpp:103
virtual void set(size_t i, int32_t v)=0
Interface for lists.
Definition interfaces.hpp:237
virtual void set_name(size_t i, std::string n)=0
virtual void set(size_t i, std::shared_ptr< Base > v)=0
Type type() const
Definition interfaces.hpp:239
virtual size_t size() const =0
Representation of R's NULL.
Definition interfaces.hpp:215
Type type() const
Definition interfaces.hpp:217
Interface for a double-precision vector.
Definition interfaces.hpp:119
Type type() const
Definition interfaces.hpp:121
virtual void set(size_t i, double v)=0
Interface for a string vector.
Definition interfaces.hpp:137
Format
Definition interfaces.hpp:158
Type type() const
Definition interfaces.hpp:139
virtual void set(size_t i, std::string v)=0
Interface for vector-like objects.
Definition interfaces.hpp:74
virtual void set_name(size_t i, std::string n)=0
virtual void set_missing(size_t i)=0
virtual size_t size() const =0
Parse an R list from a HDF5 or JSON file.
Definition parse_json.hpp:28
Type
Definition interfaces.hpp:28
bool is_vector(Type t)
Definition interfaces.hpp:43