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#include <cstddef>
9
15namespace uzuki2 {
16
29enum Type {
30 INTEGER,
31 NUMBER,
32 STRING,
33 BOOLEAN,
34 FACTOR,
35 LIST,
36 NOTHING,
37 EXTERNAL
38};
39
44inline bool is_vector(Type t) {
45 return (t >= 0 && t < LIST);
46}
47
51class Base {
52public:
56 Base() = default;
57 Base(Base&&) = default;
58 Base(const Base&) = default;
59 Base& operator=(Base&&) = default;
60 Base& operator=(const Base&) = default;
61 virtual ~Base() = default;
69 virtual Type type() const = 0;
70};
71
75class Vector : public Base {
76public:
80 virtual std::size_t size () const = 0;
81
89 virtual void set_name(std::size_t i, std::string n) = 0;
90
96 virtual void set_missing(std::size_t i) = 0;
97};
98
102class IntegerVector : public Vector {
103public:
104 Type type() const {
105 return INTEGER;
106 }
107
114 virtual void set(std::size_t i, std::int32_t v) = 0;
115};
116
120class NumberVector : public Vector {
121public:
122 Type type() const {
123 return NUMBER;
124 }
125
132 virtual void set(std::size_t i, double v) = 0;
133};
134
138class StringVector : public Vector {
139public:
140 Type type() const {
141 return STRING;
142 }
143
150 virtual void set(std::size_t i, std::string v) = 0;
151
159 enum Format {
160 NONE,
161 DATE,
162 DATETIME
163 };
164};
165
169class BooleanVector : public Vector {
170public:
171 Type type() const {
172 return BOOLEAN;
173 }
174
181 virtual void set(std::size_t i, bool v) = 0;
182};
183
190class Factor : public Vector {
191public:
192 Type type() const {
193 return FACTOR;
194 }
195
202 virtual void set(std::size_t i, std::size_t v) = 0;
203
210 virtual void set_level(std::size_t il, std::string vl) = 0;
211};
212
216class Nothing : public Base {
217public:
218 Type type() const {
219 return NOTHING;
220 }
221};
222
228class External : public Base {
229public:
230 Type type() const {
231 return EXTERNAL;
232 }
233};
234
238class List : public Base {
239public:
240 Type type() const {
241 return LIST;
242 }
243
247 virtual std::size_t size() const = 0;
248
255 virtual void set(std::size_t i, std::shared_ptr<Base> v) = 0;
256
264 virtual void set_name(std::size_t i, std::string n) = 0;
265};
266
267}
268
269#endif
Base interface for all R objects.
Definition interfaces.hpp:51
virtual Type type() const =0
Interface for a boolean vector.
Definition interfaces.hpp:169
Type type() const
Definition interfaces.hpp:171
virtual void set(std::size_t i, bool v)=0
Interface for unsupported objects.
Definition interfaces.hpp:228
Type type() const
Definition interfaces.hpp:230
Interface for a factor.
Definition interfaces.hpp:190
Type type() const
Definition interfaces.hpp:192
virtual void set(std::size_t i, std::size_t v)=0
virtual void set_level(std::size_t il, std::string vl)=0
Interface for integer vectors.
Definition interfaces.hpp:102
Type type() const
Definition interfaces.hpp:104
virtual void set(std::size_t i, std::int32_t v)=0
Interface for lists.
Definition interfaces.hpp:238
virtual void set(std::size_t i, std::shared_ptr< Base > v)=0
Type type() const
Definition interfaces.hpp:240
virtual void set_name(std::size_t i, std::string n)=0
virtual std::size_t size() const =0
Representation of R's NULL.
Definition interfaces.hpp:216
Type type() const
Definition interfaces.hpp:218
Interface for a double-precision vector.
Definition interfaces.hpp:120
Type type() const
Definition interfaces.hpp:122
virtual void set(std::size_t i, double v)=0
Interface for a string vector.
Definition interfaces.hpp:138
Format
Definition interfaces.hpp:159
Type type() const
Definition interfaces.hpp:140
virtual void set(std::size_t i, std::string v)=0
Interface for vector-like objects.
Definition interfaces.hpp:75
virtual void set_name(std::size_t i, std::string n)=0
virtual std::size_t size() const =0
virtual void set_missing(std::size_t i)=0
Parse an R list from a HDF5 or JSON file.
Definition parse_json.hpp:31
Type
Definition interfaces.hpp:29
bool is_vector(Type t)
Definition interfaces.hpp:44