1#ifndef LIBPRESSIO_CONFIGURABLE_H
2#define LIBPRESSIO_CONFIGURABLE_H
23 virtual const char*
prefix()
const=0;
36 virtual void set_name(std::string
const& new_name) {
38 this->
name = new_name;
96 template <
class StringType>
98 if(
name.empty()) options.
set(key, value);
99 else options.
set(
name, key, value);
110 template <
class StringType>
125 template <
class StringType,
class Po
interType>
128 if(
name.empty())
return options.
get(std::forward<StringType>(key), value);
129 return options.
get(
name, std::forward<StringType>(key), value);
141 template<
class StringType,
class Wrapper,
class... Args>
143 set_meta(
pressio_options& options, StringType&& key, std::string
const& current_id, Wrapper
const& current_value, Args&&... args)
const {
144 set(options, std::forward<StringType>(key), current_id);
145 options.
copy_from(current_value->get_options(std::forward<Args>(args)...));
157 template<
class StringType,
class Wrapper,
class... Args>
160 set(options, std::forward<StringType>(key), docstring);
161 options.
copy_from(current_value->get_documentation(std::forward<Args>(args)...));
173 template<
class StringType,
class Wrapper,
class Registry,
class... Args>
176 std::vector<std::string> plugins;
177 plugins.reserve(registry.size());
178 for (
auto const& i : registry) {
179 plugins.emplace_back(i.first);
181 set(options, std::forward<StringType>(key), plugins);
182 options.
copy_from(current_value->get_configuration());
194 template<
class StringType,
class Wrapper,
class Registry,
class... Args>
197 std::vector<std::string> plugins;
198 plugins.reserve(registry.size());
199 for (
auto const& i : registry) {
200 plugins.emplace_back(i.first);
202 set(options, std::forward<StringType>(key), plugins);
203 for (
auto const& current_value : current_values) {
204 options.
copy_from(current_value->get_configuration());
218 template<
class StringType,
class Wrapper,
class... Args>
221 set(options, std::forward<StringType>(key), docstring);
222 for (
auto const& wrapper : current_values) {
223 options.
copy_from(wrapper->get_documentation(std::forward<Args>(args)...));
236 template<
class StringType,
class Wrapper,
class... Args>
238 set_meta_many(
pressio_options& options, StringType&& key, std::vector<std::string>
const& current_ids, std::vector<Wrapper>
const& current_values, Args&&... args)
const {
239 set(options, std::forward<StringType>(key), current_ids);
240 for (
auto const& wrapper : current_values) {
241 options.
copy_from(wrapper->get_options(std::forward<Args>(args)...));
255 template <
class StringType,
class Registry,
class Wrapper>
259 Registry
const& registry,
260 std::string& current_id,
261 Wrapper& current_value) {
265 if (new_id != current_id) {
266 auto new_value = registry.build(new_id);
268 current_id = std::move(new_id);
269 current_value = std::move(new_value);
279 current_value->set_options(options);
293 template <
class StringType,
class Registry,
class Wrapper>
297 Registry
const& registry,
298 std::vector<std::string>& current_ids,
299 std::vector<Wrapper>& current_values) {
300 std::vector<std::string> new_ids;
303 if (new_ids != current_ids) {
304 std::vector<Wrapper> new_values;
305 bool all_built =
true;
306 for (
auto const& new_id : new_ids) {
307 new_values.emplace_back(registry.build(new_id));
308 all_built &= new_values.back();
309 if(not all_built)
break;
312 current_ids = std::move(new_ids);
313 current_values = std::move(new_values);
323 for (
auto& current_value : current_values) {
324 current_value->set_options(options);
336 void set_names_many(std::string
const&
name, std::vector<T>& plugins, std::vector<std::string>
const& names)
const {
338 for (
auto & plugin : plugins) {
339 plugin->set_name(
name);
342 if(not names.empty()) {
343 for (
size_t i = 0; i < std::min(plugins.size(), names.size()); ++i) {
344 plugins[i]->set_name(
name +
"/" + names[i]);
347 for (
auto & plugin : plugins) {
348 plugin->set_name(
name +
"/" + plugin->prefix());
360 for (
auto const& i : config) {
365 return set_error(1,
"option " + i.first +
" does not exist");
369 casted.
set(i.first, types.get(i.first));
372 return set_error(1,
"option " + i.first +
" could not be converted");
400 return std::string(
prefix()) +
":metric";
Definition: configurable.h:17
void set_meta_many_docs(pressio_options &options, StringType &&key, std::string const &docstring, std::vector< Wrapper > const ¤t_values, Args &&... args) const
Definition: configurable.h:220
void set_names_many(std::string const &name, std::vector< T > &plugins, std::vector< std::string > const &names) const
Definition: configurable.h:336
void set_meta_many(pressio_options &options, StringType &&key, std::vector< std::string > const ¤t_ids, std::vector< Wrapper > const ¤t_values, Args &&... args) const
Definition: configurable.h:238
virtual void set_name(std::string const &new_name)
Definition: configurable.h:36
virtual struct pressio_options get_documentation() const
void set_meta_configuration(pressio_options &options, StringType &&key, Registry const ®istry, Wrapper const ¤t_value) const
Definition: configurable.h:175
void set_meta(pressio_options &options, StringType &&key, std::string const ¤t_id, Wrapper const ¤t_value, Args &&... args) const
Definition: configurable.h:143
static pressio_thread_safety get_threadsafe(pressio_configurable const &c)
Definition: configurable.h:389
virtual int check_options(struct pressio_options const &)
virtual const char * prefix() const =0
std::string get_metrics_key_name() const
Definition: configurable.h:399
std::string name
Definition: configurable.h:404
virtual struct pressio_options get_configuration() const
virtual void set_name_impl(std::string const &new_name)
Definition: configurable.h:46
enum pressio_options_key_status get(pressio_options const &options, StringType &&key, PointerType value) const
Definition: configurable.h:127
pressio_options_key_status get_meta(pressio_options const &options, StringType &&key, Registry const ®istry, std::string ¤t_id, Wrapper ¤t_value)
Definition: configurable.h:257
void set(pressio_options &options, StringType const &key, pressio_option const &value) const
Definition: configurable.h:97
void set_meta_many_configuration(pressio_options &options, StringType &&key, Registry const ®istry, std::vector< Wrapper > const ¤t_values) const
Definition: configurable.h:196
pressio_options_key_status get_meta_many(pressio_options const &options, StringType &&key, Registry const ®istry, std::vector< std::string > ¤t_ids, std::vector< Wrapper > ¤t_values)
Definition: configurable.h:295
void set_type(pressio_options &options, StringType const &key, pressio_option_type type) const
Definition: configurable.h:111
std::string const & get_name() const
Definition: configurable.h:28
void set_meta_docs(pressio_options &options, StringType &&key, std::string const &docstring, Wrapper const ¤t_value, Args &&... args) const
Definition: configurable.h:159
virtual struct pressio_options get_options() const
virtual int set_options(struct pressio_options const &options)
Definition: errorable.h:13
int set_error(int code, std::string const &msg)
interface for types which can report and have errors
C++ pressio_options and pressio_option interfaces.
Compress, decompress, and configure pressio and lossless compressors.
pressio_thread_safety
Definition: pressio_compressor.h:268
@ pressio_thread_safety_single
Definition: pressio_compressor.h:270
pressio_option_type
Definition: pressio_options.h:57
@ pressio_conversion_special
Definition: pressio_options.h:53
pressio_options_key_status
Definition: pressio_options.h:27
@ pressio_options_key_does_not_exist
Definition: pressio_options.h:35
@ pressio_options_key_set
Definition: pressio_options.h:29
@ pressio_options_key_exists
Definition: pressio_options.h:32
Definition: options.h:352
void set_type(StringType &&key, pressio_option_type type)
Definition: options.h:476
void set(StringType &&key, pressio_option const &value)
Definition: options.h:423
void copy_from(pressio_options const &o, bool ignore_empty=false)
Definition: options.h:664
enum pressio_options_key_status cast_set(StringType &&key, pressio_option const &value, enum pressio_conversion_safety safety=pressio_conversion_implicit)
Definition: options.h:446
pressio_option const & get(StringType const &key) const
Definition: options.h:496
pressio_options_key_status key_status(std::string const &key) const
Definition: options.h:395