MySQL 8.3.0
Source Code Documentation
dd::Properties_impl Class Reference

The Properties_impl class implements the Properties interface. More...

#include <properties_impl.h>

Inheritance diagram for dd::Properties_impl:
[legend]

Public Member Functions

 Properties_impl ()=default
 
 Properties_impl (const std::set< String_type > &keys)
 
virtual const Properties_implimpl () const
 
iterator begin () override
 
const_iterator begin () const override
 
iterator end () override
 
const_iterator end () const override
 
size_type size () const override
 Get the number of key=value pairs. More...
 
bool empty () const override
 Are there any key=value pairs? More...
 
void clear () override
 Remove all key=value pairs. More...
 
bool valid_key (const String_type &key) const override
 Check if the submitted key is valid. More...
 
bool exists (const String_type &key) const override
 Check for the existence of a key=value pair given the key. More...
 
bool remove (const String_type &key) override
 Remove the key=value pair for the given key if it exists. More...
 
const String_type raw_string () const override
 Iterate over all entries in the private hash table. More...
 
bool get (const String_type &key, String_type *value) const override
 Get the string value for a given key. More...
 
bool set (const String_type &key, const String_type &value) override
 Set the key/value. More...
 
bool insert_values (const Properties &properties) override
 Insert key/value pairs from a different property object. More...
 
bool insert_values (const String_type &raw_string) override
 Insert key/value pairs from a string. More...
 
- Public Member Functions inherited from dd::Properties
template<typename Lex_type >
bool get (const String_type &key, Lex_type *value, MEM_ROOT *mem_root) const
 Get the lex string value for a given key. More...
 
template<typename Value_type >
bool get (const String_type &key, Value_type *value) const
 Get the string value for the key and convert it to the appropriate type. More...
 
template<typename Value_type >
bool set (const String_type &key, Value_type value)
 Convert the value to a string and set it for the given key. More...
 
 Properties ()=default
 
 Properties (const Properties &)=default
 
Propertiesoperator= (const Properties &)=delete
 
virtual ~Properties ()=default
 

Private Attributes

Properties::Map m_map
 
std::set< String_typem_keys
 

Additional Inherited Members

- Public Types inherited from dd::Properties
typedef std::map< String_type, String_typeMap
 
typedef std::map< String_type, String_type >::size_type size_type
 
typedef Map::iterator iterator
 
typedef Map::const_iterator const_iterator
 
- Static Public Member Functions inherited from dd::Properties
template<typename T >
static bool from_str (const String_type &number, T *value)
 Convert a string to a value of an integral type. More...
 
static bool from_str (const String_type &bool_str, bool *value)
 Convert string to bool. More...
 
template<class T >
static String_type to_str (T value)
 Convert a value of an integral type (including bool) to a string. More...
 
static Propertiesparse_properties (const String_type &raw_properties)
 Parse the submitted string for properties on the format "key=value;key=value;...". More...
 

Detailed Description

The Properties_impl class implements the Properties interface.

The key=value pairs are stored in a std::map. An instance can be created either by means of the default constructor, which creates an object with an empty map, or alternatively, it can be created by means of the static parse_properties function with a String_type argument. The string is supposed to contain a semicolon separated list of key=value pairs, where the characters '=' and ';' also may be part of key or value by escaping using the '\' as an escape character. The escape character itself must also be escaped if being part of key or value. All characters between '=' and ';' are considered part of key or value, whitespace is not ignored.

Escaping is removed during parsing so the strings in the map are not escaped. Escaping is only relevant in the context of raw strings that are to be parsed, and raw strings that are returned containing all key=value pairs.

Example (note \ due to escaping of C string literals): parse_properties("a=b;b = c") -> ("a", "b"), ("b ", " c") parse_properties("a\\==b;b=\\;c") -> ("a=", "b"), ("b", ";c")

get("a=") == "b" get("b") == ";c"

Additional key=value pairs may be added by means of the set function, which takes a string argument that is assumed to be unescaped.

Please also refer to the comments in the file properties.h where the interface is defined; the functions in the interface are commented there.

Constructor & Destructor Documentation

◆ Properties_impl() [1/2]

dd::Properties_impl::Properties_impl ( )
default

◆ Properties_impl() [2/2]

dd::Properties_impl::Properties_impl ( const std::set< String_type > &  keys)
inline

Member Function Documentation

◆ begin() [1/2]

const_iterator dd::Properties_impl::begin ( void  ) const
inlineoverridevirtual

Implements dd::Properties.

◆ begin() [2/2]

iterator dd::Properties_impl::begin ( void  )
inlineoverridevirtual

Implements dd::Properties.

◆ clear()

void dd::Properties_impl::clear ( )
inlineoverridevirtual

Remove all key=value pairs.

Implements dd::Properties.

◆ empty()

bool dd::Properties_impl::empty ( ) const
inlineoverridevirtual

Are there any key=value pairs?

Returns
true if there is no key=value pair, else false.

Implements dd::Properties.

◆ end() [1/2]

const_iterator dd::Properties_impl::end ( void  ) const
inlineoverridevirtual

Implements dd::Properties.

◆ end() [2/2]

iterator dd::Properties_impl::end ( void  )
inlineoverridevirtual

Implements dd::Properties.

◆ exists()

bool dd::Properties_impl::exists ( const String_type key) const
inlineoverridevirtual

Check for the existence of a key=value pair given the key.

Parameters
keyKey to be checked.
Returns
true if the given key exists, false otherwise.

Implements dd::Properties.

◆ get()

bool dd::Properties_impl::get ( const String_type key,
String_type value 
) const
overridevirtual

Get the string value for a given key.

Return true if the operation fails, i.e., if the key does not exist or if the key is invalid. Assert that the key exists in debug builds.

Parameters
keykey to lookup the value for
[out]valuestring value
Returns
Operation outcome, false if success, otherwise true

Implements dd::Properties.

◆ impl()

virtual const Properties_impl * dd::Properties_impl::impl ( ) const
inlinevirtual

◆ insert_values() [1/2]

bool dd::Properties_impl::insert_values ( const Properties properties)
overridevirtual

Insert key/value pairs from a different property object.

The set of valid keys is not copied, instead, the existing set in the destination object is used to ignore all invalid keys.

Parameters
propertiesSource object.
Return values
Operationoutcome, false if no error, otherwise true.

Implements dd::Properties.

◆ insert_values() [2/2]

bool dd::Properties_impl::insert_values ( const String_type raw_string)
overridevirtual

Insert key/value pairs from a string.

Parse the string and add key/value pairs to this object. The existing set of valid keys in the destination object is used to ignore all invalid keys.

Parameters
raw_stringString to be parsed.
Return values
Operationoutcome, false if no error, otherwise true.

Implements dd::Properties.

◆ raw_string()

const String_type dd::Properties_impl::raw_string ( ) const
overridevirtual

Iterate over all entries in the private hash table.

For each key value pair, escape both key and value, and append the strings to the result. Use '=' to separate key and value, and use ';' to separate pairs.

Invalid keys are not included in the output. However, there should never be a situation where invalid keys are present, so we just assert that the keys are valid.

Returns
string containing all escaped key value pairs

Implements dd::Properties.

◆ remove()

bool dd::Properties_impl::remove ( const String_type key)
inlineoverridevirtual

Remove the key=value pair for the given key if it exists.

Otherwise, do nothing.

Parameters
keykey to lookup.
Returns
false if the given key existed, true otherwise.

Implements dd::Properties.

◆ set()

bool dd::Properties_impl::set ( const String_type key,
const String_type value 
)
overridevirtual

Set the key/value.

If the key is invalid, a warning is written to the error log. Assert that the key exists in debug builds.

Parameters
keyKey to set.
valueValue to set.
Returns
Operation outcome, false if success, otherwise true

Implements dd::Properties.

◆ size()

size_type dd::Properties_impl::size ( ) const
inlineoverridevirtual

Get the number of key=value pairs.

Note
Invalid keys that are present will also be reflected in the count.
Returns
number of key=value pairs

Implements dd::Properties.

◆ valid_key()

bool dd::Properties_impl::valid_key ( const String_type key) const
inlineoverridevirtual

Check if the submitted key is valid.

Parameters
keyKey to be checked.
Return values
trueif the key is valid, otherwise false.

Implements dd::Properties.

Member Data Documentation

◆ m_keys

std::set<String_type> dd::Properties_impl::m_keys
private

◆ m_map

Properties::Map dd::Properties_impl::m_map
private

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