26#ifndef MYSQL_HARNESS_PLUGIN_CONFIG_INCLUDED
27#define MYSQL_HARNESS_PLUGIN_CONFIG_INCLUDED
34#include "harness_export.h"
44 using std::invalid_argument::invalid_argument;
52 using std::invalid_argument::invalid_argument;
90 std::string get_option_description(
92 const std::string &option)
const;
103 virtual std::string
get_default(
const std::string &option)
const = 0;
126 template <
class Func>
128 const std::string &option,
129 Func &&transformer)
const {
130 const auto value = get_option_string_or_default_(section, option);
132 return transformer(value, get_option_description(section, option));
151 template <
class Func>
154 Func &&transformer)
const {
155 const auto value = get_option_string_(section, option);
157 return transformer(value, get_option_description(section, option));
171 [[deprecated(
"use get_option(..., StringOption{}) instead")]]
175 const std::string &option)
const {
177 [](
auto const &value,
auto const &) {
return value; });
200 [[deprecated(
"used get_option(..., IntOption<T>{}) instead")]]
203 const std::string &option, T min_value = 0,
204 T max_value = std::numeric_limits<T>::max())
const {
226 [[deprecated(
"used get_option(..., MilliSecondsOption{}) instead")]]
228 std::chrono::milliseconds
231 double min_value = 0.0,
232 double max_value = std::numeric_limits<double>::max())
const {
242 : section_name_{get_section_name(section)} {}
250 static std::string get_section_name(
266 std::optional<std::string> get_option_string_(
268 const std::string &option)
const;
278 std::string get_option_string_or_default_(
280 const std::string &option)
const;
Retrieve and manage plugin configuration.
Definition: plugin_config.h:62
std::chrono::milliseconds get_option_milliseconds(const mysql_harness::ConfigSection *section, const std::string &option, double min_value=0.0, double max_value=std::numeric_limits< double >::max()) const
Gets a number of milliseconds using the given option.
Definition: plugin_config.h:229
T get_uint_option(const mysql_harness::ConfigSection *section, const std::string &option, T min_value=0, T max_value=std::numeric_limits< T >::max()) const
Gets an unsigned integer using the given option.
Definition: plugin_config.h:202
BasePluginConfig(const mysql_harness::ConfigSection *section)
Constructor for derived classes.
Definition: plugin_config.h:241
std::string get_option_string(const mysql_harness::ConfigSection *section, const std::string &option) const
Gets value of given option as string.
Definition: plugin_config.h:174
decltype(auto) get_option_no_default(const mysql_harness::ConfigSection *section, const std::string &option, Func &&transformer) const
get option value.
Definition: plugin_config.h:152
BasePluginConfig & operator=(BasePluginConfig &&)=default
BasePluginConfig(BasePluginConfig &&)=default
virtual bool is_required(const std::string &option) const =0
Returns whether the given option is required.
BasePluginConfig()=default
BasePluginConfig(const BasePluginConfig &)=default
std::string section_name_
Name of the section.
Definition: plugin_config.h:257
decltype(auto) get_option(const mysql_harness::ConfigSection *section, const std::string &option, Func &&transformer) const
get option value.
Definition: plugin_config.h:127
virtual std::string get_default(const std::string &option) const =0
Gets the default for the given option.
virtual ~BasePluginConfig()=default
destructor
BasePluginConfig & operator=(const BasePluginConfig &)=default
Configuration section.
Definition: config_parser.h:141
Definition: config_option.h:168
Definition: config_option.h:108
Exception that gets thrown when the configuration option is present but it is empty value.
Definition: plugin_config.h:50
Exception that gets thrown when the configuration option is missing.
Definition: plugin_config.h:42