MySQL 9.0.0
Source Code Documentation
mysql_harness::BasePluginConfig Class Referenceabstract

Retrieve and manage plugin configuration. More...

#include <plugin_config.h>

Inheritance diagram for mysql_harness::BasePluginConfig:
[legend]

Public Member Functions

 BasePluginConfig ()=default
 
 BasePluginConfig (const BasePluginConfig &)=default
 
 BasePluginConfig (BasePluginConfig &&)=default
 
BasePluginConfigoperator= (const BasePluginConfig &)=default
 
BasePluginConfigoperator= (BasePluginConfig &&)=default
 
virtual ~BasePluginConfig ()=default
 destructor More...
 
std::string get_option_description (const mysql_harness::ConfigSection *section, std::string_view option) const
 get description of the option. More...
 
virtual std::string get_default (std::string_view option) const =0
 Gets the default for the given option. More...
 
virtual bool is_required (std::string_view option) const =0
 Returns whether the given option is required. More...
 
template<class Func >
decltype(auto) get_option (const mysql_harness::ConfigSection *section, std::string_view option, Func &&transformer) const
 get option value. More...
 
template<class Func >
decltype(auto) get_option_no_default (const mysql_harness::ConfigSection *section, std::string_view option, Func &&transformer) const
 get option value. More...
 
std::string get_option_string (const mysql_harness::ConfigSection *section, std::string_view option) const
 Gets value of given option as string. More...
 
template<class 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. More...
 
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. More...
 

Protected Member Functions

 BasePluginConfig (const mysql_harness::ConfigSection *section)
 Constructor for derived classes. More...
 

Static Protected Member Functions

static std::string get_section_name (const mysql_harness::ConfigSection *section)
 Generate the name for this configuration. More...
 

Private Member Functions

std::optional< std::string > get_option_string_ (const mysql_harness::ConfigSection *section, std::string_view option) const
 get value of an option from a config-section. More...
 
std::string get_option_string_or_default_ (const mysql_harness::ConfigSection *section, std::string_view option) const
 get value of an option from a config-section. More...
 

Private Attributes

std::string section_name_
 Name of the section. More...
 

Detailed Description

Retrieve and manage plugin configuration.

BasePluginConfig is an abstract class which can be used to by plugins to derive their own class retrieving configuration from, for example, Harness ConfigSection instances.

Constructor & Destructor Documentation

◆ BasePluginConfig() [1/4]

mysql_harness::BasePluginConfig::BasePluginConfig ( )
default

◆ BasePluginConfig() [2/4]

mysql_harness::BasePluginConfig::BasePluginConfig ( const BasePluginConfig )
default

◆ BasePluginConfig() [3/4]

mysql_harness::BasePluginConfig::BasePluginConfig ( BasePluginConfig &&  )
default

◆ ~BasePluginConfig()

virtual mysql_harness::BasePluginConfig::~BasePluginConfig ( )
virtualdefault

destructor

◆ BasePluginConfig() [4/4]

mysql_harness::BasePluginConfig::BasePluginConfig ( const mysql_harness::ConfigSection section)
inlineprotected

Constructor for derived classes.

Member Function Documentation

◆ get_default()

virtual std::string mysql_harness::BasePluginConfig::get_default ( std::string_view  option) const
pure virtual

◆ get_option()

template<class Func >
decltype(auto) mysql_harness::BasePluginConfig::get_option ( const mysql_harness::ConfigSection section,
std::string_view  option,
Func &&  transformer 
) const
inline

get option value.

gets the option from a config-section (or its default value if it doesn't exist) and converts it with a transformation function.

Parameters
sectionconfiguration section
optionname of the option
transformertransformation function. The signature of the transformation function should be equivalent to: (const std::string &value, const std::string &option_description) and returns the transformed value.
Returns
return value of the the transformation function.

◆ get_option_description()

std::string mysql_harness::BasePluginConfig::get_option_description ( const mysql_harness::ConfigSection section,
std::string_view  option 
) const

get description of the option.

For example, option wait_timeout in section [routing:homepage] will return a prefix (without quotes):

option wait_timeout in [routing:homepage]
Parameters
sectionconfiguration section
optionName of the option
Returns
Prefix as std::string

◆ get_option_milliseconds()

std::chrono::milliseconds mysql_harness::BasePluginConfig::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
inline

Gets a number of milliseconds using the given option.

The expected option value is a string with floating point number in seconds (with '.' as a decimal separator) in standard or scientific notation

  • for value = "1.0" expected result is std::chrono:milliseconds(1000)
  • for value = "0.01" expected result is std::chrono:milliseconds(10)
  • for value = "1.6E-2" expected result is std::chrono:milliseconds(16)
Parameters
sectionInstance of ConfigSection
optionOption name in section
min_valueMinimum value
max_valueMaximum value
Returns
value converted to milliseconds
Exceptions
std::invalid_argumenton errors

◆ get_option_no_default()

template<class Func >
decltype(auto) mysql_harness::BasePluginConfig::get_option_no_default ( const mysql_harness::ConfigSection section,
std::string_view  option,
Func &&  transformer 
) const
inline

get option value.

gets the option from a config-section and converts it with a transformation function.

does not call get_default().

Parameters
sectionconfiguration section
optionname of the option
transformertransformation function. The signature of the transformation function should be equivalent to: (const std::string &value, const std::string &option_description) and returns the transformed value.
Returns
transformed value.

◆ get_option_string()

std::string mysql_harness::BasePluginConfig::get_option_string ( const mysql_harness::ConfigSection section,
std::string_view  option 
) const
inline

Gets value of given option as string.

Exceptions
option_not_presentif the required option is missing
option_emptyif the required option is present but empty
Parameters
sectionInstance of ConfigSection
optionname of the option
Returns
Option value as std::string

◆ get_option_string_()

std::optional< std::string > mysql_harness::BasePluginConfig::get_option_string_ ( const mysql_harness::ConfigSection section,
std::string_view  option 
) const
private

get value of an option from a config-section.

does not call get_default()

Returns
a value of the option if it exists.

◆ get_option_string_or_default_()

std::string mysql_harness::BasePluginConfig::get_option_string_or_default_ ( const mysql_harness::ConfigSection section,
std::string_view  option 
) const
private

get value of an option from a config-section.

gets value from get_default() if the option-value is not present or empty.

Returns
a value of the option if it exists.

◆ get_section_name()

std::string mysql_harness::BasePluginConfig::get_section_name ( const mysql_harness::ConfigSection section)
staticprotected

Generate the name for this configuration.

Parameters
sectionInstance of ConfigSection
Returns
the name for this configuration

◆ get_uint_option()

template<class T >
T mysql_harness::BasePluginConfig::get_uint_option ( const mysql_harness::ConfigSection section,
std::string_view  option,
min_value = 0,
max_value = std::numeric_limits<T>::max() 
) const
inline

Gets an unsigned integer using the given option.

Gets an unsigned integer using the given option. The type can be any unsigned integer type such as uint16_t.

The min_value argument can be used to set a minimum value for the option. For example, when 0 (zero) is not allowed, min_value can be set to 0. The maximum value is whatever the maximum of the use type is.

Throws std::invalid_argument on errors.

Parameters
sectionInstance of ConfigSection
optionOption name in section
min_valueMinimum value
max_valueMaximum value
Returns
value read from the configuration

◆ is_required()

◆ operator=() [1/2]

BasePluginConfig & mysql_harness::BasePluginConfig::operator= ( BasePluginConfig &&  )
default

◆ operator=() [2/2]

BasePluginConfig & mysql_harness::BasePluginConfig::operator= ( const BasePluginConfig )
default

Member Data Documentation

◆ section_name_

std::string mysql_harness::BasePluginConfig::section_name_
private

Name of the section.


The documentation for this class was generated from the following files: