MySQL 9.0.0
Source Code Documentation
mysql_harness::ConfigSection Class Reference

Configuration section. More...

#include <config_parser.h>

Public Types

using OptionMap = std::map< std::string, std::string >
 
using OptionRange = Range< OptionMap::const_iterator >
 

Public Member Functions

 ConfigSection (const std::string &name_arg, const std::string &key_arg, const std::shared_ptr< const ConfigSection > &defaults)
 
 ConfigSection (const ConfigSection &, const std::shared_ptr< const ConfigSection > &defaults)
 
ConfigSectionoperator= (const ConfigSection &)=delete
 
 ConfigSection (const ConfigSection &)=default
 
void clear ()
 Clear the options in the section. More...
 
void update (const ConfigSection &other)
 Update section with contents of another section. More...
 
std::string get (std::string_view option) const
 
void set (std::string_view option, const std::string &value)
 
void add (const std::string &option, const std::string &value)
 
bool has (std::string_view option) const
 
OptionRange get_options () const
 Range for options in section. More...
 
std::string get_section_name (std::string_view option) const
 
std::string get_section_name () const
 
bool assert_default (const ConfigSection *def) const
 

Public Attributes

const std::string name
 
const std::string key
 

Private Member Functions

std::string do_replace (const std::string &value, int depth=0) const
 
std::pair< OptionMap::const_iterator, bool > do_locate (std::string_view option) const noexcept
 

Private Attributes

const int kMaxInterpolationDepth = 10
 
const std::shared_ptr< const ConfigSectiondefaults_
 
OptionMap options_
 

Detailed Description

Configuration section.

A named configuration file section with a zero or more configuration file options.

Member Typedef Documentation

◆ OptionMap

using mysql_harness::ConfigSection::OptionMap = std::map<std::string, std::string>

◆ OptionRange

using mysql_harness::ConfigSection::OptionRange = Range<OptionMap::const_iterator>

Constructor & Destructor Documentation

◆ ConfigSection() [1/3]

mysql_harness::ConfigSection::ConfigSection ( const std::string &  name_arg,
const std::string &  key_arg,
const std::shared_ptr< const ConfigSection > &  defaults 
)

◆ ConfigSection() [2/3]

mysql_harness::ConfigSection::ConfigSection ( const ConfigSection other,
const std::shared_ptr< const ConfigSection > &  defaults 
)

◆ ConfigSection() [3/3]

mysql_harness::ConfigSection::ConfigSection ( const ConfigSection )
default

Member Function Documentation

◆ add()

void mysql_harness::ConfigSection::add ( const std::string &  option,
const std::string &  value 
)

◆ assert_default()

bool mysql_harness::ConfigSection::assert_default ( const ConfigSection def) const
inline

◆ clear()

void mysql_harness::ConfigSection::clear ( )

Clear the options in the section.

This will remove options from the configuration section.

◆ do_locate()

std::pair< ConfigSection::OptionMap::const_iterator, bool > mysql_harness::ConfigSection::do_locate ( std::string_view  option) const
privatenoexcept

◆ do_replace()

std::string mysql_harness::ConfigSection::do_replace ( const std::string &  value,
int  depth = 0 
) const
private

◆ get()

std::string mysql_harness::ConfigSection::get ( std::string_view  option) const

◆ get_options()

OptionRange mysql_harness::ConfigSection::get_options ( ) const
inline

Range for options in section.

Typical usage is:

for (auto elem: section.get_options())
std::cout << "Option " << elem.first
<< " has value " << elem.second
<< std::endl;
Returns
a range of options each consisting of a pair option-value.

◆ get_section_name() [1/2]

std::string mysql_harness::ConfigSection::get_section_name ( ) const

◆ get_section_name() [2/2]

std::string mysql_harness::ConfigSection::get_section_name ( std::string_view  option) const

◆ has()

bool mysql_harness::ConfigSection::has ( std::string_view  option) const

◆ operator=()

ConfigSection & mysql_harness::ConfigSection::operator= ( const ConfigSection )
delete

◆ set()

void mysql_harness::ConfigSection::set ( std::string_view  option,
const std::string &  value 
)

◆ update()

void mysql_harness::ConfigSection::update ( const ConfigSection other)

Update section with contents of another section.

The configuration section will be updated with the contents of the other section. For any options that exist in the section, the value will be overwritten by the values in the other section. If the option do not exist, a new option will be created and the value set to the value of the option in the other section.

Note
The section name and key have to match for the update to be done.
Exceptions
bad_sectionThrown if the section name or section key do not match.
Parameters
otherSection to copy options and values from.

Member Data Documentation

◆ defaults_

const std::shared_ptr<const ConfigSection> mysql_harness::ConfigSection::defaults_
private

◆ key

const std::string mysql_harness::ConfigSection::key

◆ kMaxInterpolationDepth

const int mysql_harness::ConfigSection::kMaxInterpolationDepth = 10
private

◆ name

const std::string mysql_harness::ConfigSection::name

◆ options_

OptionMap mysql_harness::ConfigSection::options_
private

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