5#ifndef LIBPRESSIO_PRESSIO_IMPL_H
6#define LIBPRESSIO_PRESSIO_IMPL_H
13#include "std_compat/language.h"
26 T
build(std::string
const& name)
const {
27 auto factory = factories.find(name);
28 if ( factory != factories.end()) {
29 return factory->second();
41 template <
class Name,
class Factory>
43 factories.emplace(std::forward<Name>(name), std::forward<Factory>(factory));
47 std::map<std::string, std::function<T()>> factories;
59 auto begin() const -> decltype(factories.
begin()) {
return std::begin(factories); }
63 auto end() const -> decltype(factories.
end()) {
return std::end(factories); }
72 return factories.find(key) != factories.end();
81 auto find(std::string
const& key)
const ->
decltype(factories.find(key)) {
82 return factories.find(key);
91 auto find(std::string
const& key) ->
decltype(factories.find(key)) {
92 return factories.find(key);
96 return factories.size();
114 template <
class RegistryType,
class NameType,
class Factory>
158 std::string
const&
err_msg()
const {
return error.msg; }
165 std::shared_ptr<libpressio_compressor_plugin>
get_compressor(std::string
const& compressor_id) {
167 if (compressor)
return compressor;
169 set_error(1, std::string(
"invalid compressor id ") + compressor_id);
179 std::shared_ptr<libpressio_io_plugin>
get_io(std::string
const& io_module_id)
181 auto io_module =
io_plugins().build(io_module_id);
183 return RVO_MOVE(io_module);
185 set_error(1, std::string(
"invalid io_plugin id ") + io_module_id);
196 std::unique_ptr<libpressio_metrics_plugin>
get_metric(Str
id) {
199 set_error(2, std::string(
"failed to construct metrics plugin: ") +
id);
211 template <
class ForwardIt>
212 std::unique_ptr<libpressio_metrics_plugin>
get_metrics(ForwardIt first, ForwardIt last) {
213 std::vector<pressio_metrics> plugins;
215 for (
auto metric = first; metric != last; ++metric) {
217 if(not plugins.back()) {
218 set_error(2, std::string(
"failed to construct metrics plugin: ") + *metric);
225 if(metrics)
return metrics;
227 set_error(3,
"failed to construct composite metric");
Definition: pressio.h:105
pressio_register(pressio_registry< RegistryType > ®istry, NameType &&name, Factory &&factory)
Definition: pressio.h:115
an extension header for adding compressor plugins to libpressio
C++ interface to read and write files.
pressio_registry< std::unique_ptr< libpressio_metrics_plugin > > & metrics_plugins()
pressio_registry< std::unique_ptr< libpressio_io_plugin > > & io_plugins()
pressio_registry< std::shared_ptr< libpressio_compressor_plugin > > & compressor_plugins()
an extension header for adding metrics plugins to libpressio
std::unique_ptr< libpressio_metrics_plugin > make_m_composite(std::vector< pressio_metrics > &&plugins)
void regsiter_factory(Name &&name, Factory &&factory)
Definition: pressio.h:42
T value_type
Definition: pressio.h:51
auto find(std::string const &key) const -> decltype(factories.find(key))
Definition: pressio.h:81
auto find(std::string const &key) -> decltype(factories.find(key))
Definition: pressio.h:91
T build(std::string const &name) const
Definition: pressio.h:26
T const const_reference
Definition: pressio.h:55
bool contains(std::string const &key) const
Definition: pressio.h:71
auto end() const -> decltype(factories.end())
Definition: pressio.h:63
auto begin() const -> decltype(factories.begin())
Definition: pressio.h:59
T & reference
Definition: pressio.h:53
Definition: pressio.h:137
std::shared_ptr< libpressio_compressor_plugin > get_compressor(std::string const &compressor_id)
Definition: pressio.h:165
static const char * features()
static const char * supported_metrics()
std::unique_ptr< libpressio_metrics_plugin > get_metrics(ForwardIt first, ForwardIt last)
Definition: pressio.h:212
static const char * supported_compressors()
static unsigned int major_version()
static const char * supported_io()
static const char * version()
static unsigned int minor_version()
int err_code() const
Definition: pressio.h:153
std::string const & err_msg() const
Definition: pressio.h:158
std::unique_ptr< libpressio_metrics_plugin > get_metric(Str id)
Definition: pressio.h:196
void set_error(int code, std::string const &msg)
Definition: pressio.h:145
static unsigned int patch_version()
std::shared_ptr< libpressio_io_plugin > get_io(std::string const &io_module_id)
Definition: pressio.h:179