libpressio 0.93.0
Loading...
Searching...
No Matches
io.h
Go to the documentation of this file.
1#ifndef PRESSIO_IO_PLUGIN_H
2#define PRESSIO_IO_PLUGIN_H
3#include <string>
4#include <memory>
5#include "configurable.h"
6#include "versionable.h"
7#include "errorable.h"
8#include <std_compat/span.h>
9
15struct pressio_data;
16
21 public:
22
23 virtual ~libpressio_io_plugin()=default;
24
33 struct pressio_data* read(struct pressio_data* data);
34
44 template <class ContigIterator>
45 int read_many(ContigIterator data_begin, ContigIterator data_end) {
47 compat::span<struct pressio_data*> data(data_begin, data_end);
48 return read_many_impl(data);
49 }
50
55 int write(struct pressio_data const* data);
56
66 template <class ContigIterator>
67 int write_many(ContigIterator data_begin, ContigIterator data_end) {
69 compat::span<const struct pressio_data*> data(data_begin, data_end);
70 return write_many_impl(data);
71 }
72
78 int check_options(struct pressio_options const&) override final;
79
84 int set_options(struct pressio_options const& options) override final;
89 struct pressio_options get_documentation() const override final;
94 struct pressio_options get_configuration() const override final;
102 struct pressio_options get_options() const override final;
103
112 virtual std::shared_ptr<libpressio_io_plugin> clone()=0;
113
119 void set_name(std::string const& new_name) final;
120
121
122 protected:
123
129 virtual int check_options_impl(struct pressio_options const&);
130
135 virtual pressio_data* read_impl(struct pressio_data* data)=0;
136
141 virtual int write_impl(struct pressio_data const* data)=0;
142
147 virtual int read_many_impl(compat::span<struct pressio_data*> const& data) {
148 (void)data;
149 return set_error(1, "read many not supported");
150 }
151
156 virtual int write_many_impl(compat::span<struct pressio_data const*> const& data) {
157 (void)data;
158 return set_error(1, "write many not supported");
159 }
160
165 virtual struct pressio_options get_documentation_impl() const=0;
166
171 virtual struct pressio_options get_configuration_impl() const=0;
172
177 virtual int set_options_impl(struct pressio_options const& options)=0;
178
186 virtual struct pressio_options get_options_impl() const=0;
187
188 private:
189};
190
198 pressio_io(std::unique_ptr<libpressio_io_plugin>&& impl): plugin(std::forward<std::unique_ptr<libpressio_io_plugin>>(impl)) {}
202 pressio_io(std::shared_ptr<libpressio_io_plugin>&& impl): plugin(std::forward<std::shared_ptr<libpressio_io_plugin>>(impl)) {}
206 pressio_io()=default;
210 pressio_io(pressio_io const& io): plugin(io->clone()) {}
215 if(&io == this) return *this;
216 plugin = io->clone();
217 return *this;
218 }
222 pressio_io(pressio_io&& io)=default;
227
229 operator bool() const {
230 return bool(plugin);
231 }
232
234 libpressio_io_plugin& operator*() const noexcept {
235 return *plugin;
236 }
237
240 return plugin.get();
241 }
242
246 std::shared_ptr<libpressio_io_plugin> plugin;
247};
248
249#endif /* end of include guard: PRESSIO_IO_PLUGIN_H */
Definition: configurable.h:17
int set_error(int code, std::string const &msg)
Definition: versionable.h:11
interface for configurable types
interface for types which can report and have errors
Definition: io.h:20
virtual int read_many_impl(compat::span< struct pressio_data * > const &data)
Definition: io.h:147
virtual pressio_data * read_impl(struct pressio_data *data)=0
virtual struct pressio_options get_options_impl() const =0
virtual struct pressio_options get_configuration_impl() const =0
virtual int check_options_impl(struct pressio_options const &)
int write_many(ContigIterator data_begin, ContigIterator data_end)
Definition: io.h:67
virtual struct pressio_options get_documentation_impl() const =0
virtual std::shared_ptr< libpressio_io_plugin > clone()=0
struct pressio_data * read(struct pressio_data *data)
struct pressio_options get_documentation() const override final
void set_name(std::string const &new_name) final
int set_options(struct pressio_options const &options) override final
int check_options(struct pressio_options const &) override final
int read_many(ContigIterator data_begin, ContigIterator data_end)
Definition: io.h:45
int write(struct pressio_data const *data)
virtual int write_impl(struct pressio_data const *data)=0
virtual int write_many_impl(compat::span< struct pressio_data const * > const &data)
Definition: io.h:156
virtual int set_options_impl(struct pressio_options const &options)=0
struct pressio_options get_configuration() const override final
struct pressio_options get_options() const override final
Definition: data.h:52
Definition: io.h:194
libpressio_io_plugin * operator->() const noexcept
Definition: io.h:239
pressio_io & operator=(pressio_io &&io)=default
pressio_io(std::shared_ptr< libpressio_io_plugin > &&impl)
Definition: io.h:202
pressio_io(std::unique_ptr< libpressio_io_plugin > &&impl)
Definition: io.h:198
pressio_io(pressio_io const &io)
Definition: io.h:210
std::shared_ptr< libpressio_io_plugin > plugin
Definition: io.h:246
pressio_io & operator=(pressio_io const &io)
Definition: io.h:214
libpressio_io_plugin & operator*() const noexcept
Definition: io.h:234
pressio_io()=default
pressio_io(pressio_io &&io)=default
Definition: options.h:352
interface for versionable types