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
50struct Base {
54 virtual ~Base() {}
62 virtual Type type() const = 0;
63};
64
68struct Vector : public Base {
72 virtual size_t size () const = 0;
73
81 virtual void set_name(size_t i, std::string n) = 0;
82
88 virtual void set_missing(size_t i) = 0;
89};
90
94struct IntegerVector : public Vector {
95 Type type() const {
96 return INTEGER;
97 }
98
105 virtual void set(size_t i, int32_t v) = 0;
106};
107
111struct NumberVector : public Vector {
112 Type type() const {
113 return NUMBER;
114 }
115
122 virtual void set(size_t i, double v) = 0;
123};
124
128struct StringVector : public Vector {
129 Type type() const {
130 return STRING;
131 }
132
139 virtual void set(size_t i, std::string v) = 0;
140
148 enum Format {
149 NONE,
150 DATE,
151 DATETIME
152 };
153};
154
158struct BooleanVector : public Vector {
159 Type type() const {
160 return BOOLEAN;
161 }
162
169 virtual void set(size_t i, bool v) = 0;
170};
171
178struct Factor : public Vector {
179 Type type() const {
180 return FACTOR;
181 }
182
189 virtual void set(size_t i, size_t v) = 0;
190
197 virtual void set_level(size_t il, std::string vl) = 0;
198};
199
203struct Nothing : public Base {
204 Type type() const {
205 return NOTHING;
206 }
207};
208
214struct External : public Base {
215 Type type() const {
216 return EXTERNAL;
217 }
218};
219
223struct List : public Base {
224 Type type() const {
225 return LIST;
226 }
227
231 virtual size_t size() const = 0;
232
239 virtual void set(size_t i, std::shared_ptr<Base> v) = 0;
240
248 virtual void set_name(size_t i, std::string n) = 0;
249};
250
251}
252
253#endif
Parse an R list from a HDF5 or JSON file.
Definition parse_json.hpp:29
Type
Definition interfaces.hpp:28
bool is_vector(Type t)
Definition interfaces.hpp:43
Base interface for all R objects.
Definition interfaces.hpp:50
virtual Type type() const =0
Interface for a boolean vector.
Definition interfaces.hpp:158
virtual void set(size_t i, bool v)=0
Type type() const
Definition interfaces.hpp:159
Interface for unsupported objects.
Definition interfaces.hpp:214
Type type() const
Definition interfaces.hpp:215
Interface for a factor.
Definition interfaces.hpp:178
virtual void set_level(size_t il, std::string vl)=0
Type type() const
Definition interfaces.hpp:179
virtual void set(size_t i, size_t v)=0
Interface for integer vectors.
Definition interfaces.hpp:94
Type type() const
Definition interfaces.hpp:95
virtual void set(size_t i, int32_t v)=0
Interface for lists.
Definition interfaces.hpp:223
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:224
virtual size_t size() const =0
Representation of R's NULL.
Definition interfaces.hpp:203
Type type() const
Definition interfaces.hpp:204
Interface for a double-precision vector.
Definition interfaces.hpp:111
Type type() const
Definition interfaces.hpp:112
virtual void set(size_t i, double v)=0
Interface for a string vector.
Definition interfaces.hpp:128
Format
Definition interfaces.hpp:148
Type type() const
Definition interfaces.hpp:129
virtual void set(size_t i, std::string v)=0
Interface for vector-like objects.
Definition interfaces.hpp:68
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