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 std::string_view option)
const;
103 virtual std::string
get_default(std::string_view option)
const = 0;
126 template <
class Func>
128 std::string_view option, Func &&transformer)
const {
129 const auto value = get_option_string_or_default_(section, option);
131 return transformer(value, get_option_description(section, option));
150 template <
class Func>
153 Func &&transformer)
const {
154 const auto value = get_option_string_(section, option);
156 return transformer(value, get_option_description(section, option));
170 [[deprecated(
"use get_option(..., StringOption{}) instead")]]
174 std::string_view option)
const {
175 return get_option(section, option,
176 [](
auto const &value,
auto const &) {
return value; });
199 [[deprecated(
"used get_option(..., IntOption<T>{}) instead")]]
202 std::string_view option, T min_value = 0,
203 T max_value = std::numeric_limits<T>::max())
const {
204 return get_option(section, option,
IntOption<T>{min_value, max_value});
225 [[deprecated(
"used get_option(..., MilliSecondsOption{}) instead")]]
227 std::chrono::milliseconds
230 double min_value = 0.0,
231 double max_value = std::numeric_limits<double>::max())
const {
232 return get_option(section, option,
241 : section_name_{get_section_name(section)} {}
249 static std::string get_section_name(
265 std::optional<std::string> get_option_string_(
267 std::string_view option)
const;
277 std::string get_option_string_or_default_(
279 std::string_view option)
const;
Retrieve and manage plugin configuration.
Definition: plugin_config.h:62
virtual bool is_required(std::string_view option) const =0
Returns whether the given option is required.
BasePluginConfig(const mysql_harness::ConfigSection *section)
Constructor for derived classes.
Definition: plugin_config.h:240
BasePluginConfig & operator=(BasePluginConfig &&)=default
T get_uint_option(const mysql_harness::ConfigSection *section, std::string_view 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:201
BasePluginConfig(BasePluginConfig &&)=default
BasePluginConfig()=default
decltype(auto) get_option_no_default(const mysql_harness::ConfigSection *section, std::string_view option, Func &&transformer) const
get option value.
Definition: plugin_config.h:151
BasePluginConfig(const BasePluginConfig &)=default
std::string section_name_
Name of the section.
Definition: plugin_config.h:256
decltype(auto) get_option(const mysql_harness::ConfigSection *section, std::string_view option, Func &&transformer) const
get option value.
Definition: plugin_config.h:127
virtual std::string get_default(std::string_view option) const =0
Gets the default for the given option.
virtual ~BasePluginConfig()=default
destructor
std::string get_option_string(const mysql_harness::ConfigSection *section, std::string_view option) const
Gets value of given option as string.
Definition: plugin_config.h:173
std::chrono::milliseconds get_option_milliseconds(const mysql_harness::ConfigSection *section, std::string_view 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:228
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