MySQL 8.0.40
Source Code Documentation
|
The Properties class defines an interface for storing key=value pairs, where both key and value may be UTF-8 strings. More...
#include <properties.h>
Public Types | |
typedef std::map< String_type, String_type > | Map |
typedef std::map< String_type, String_type >::size_type | size_type |
typedef Map::iterator | iterator |
typedef Map::const_iterator | const_iterator |
Public Member Functions | |
virtual iterator | begin ()=0 |
virtual const_iterator | begin () const =0 |
virtual iterator | end ()=0 |
virtual const_iterator | end () const =0 |
virtual bool | insert_values (const Properties &properties)=0 |
Insert keys and values from a different property object. More... | |
virtual bool | insert_values (const String_type &raw_string)=0 |
Insert keys and values from a raw string. More... | |
virtual size_type | size () const =0 |
Get the number of key=value pairs. More... | |
virtual bool | empty () const =0 |
Are there any key=value pairs? More... | |
virtual void | clear ()=0 |
Remove all key=value pairs. More... | |
virtual bool | valid_key (const String_type &key) const =0 |
Check if the submitted key is valid. More... | |
virtual bool | exists (const String_type &key) const =0 |
Check for the existence of a key=value pair given the key. More... | |
virtual bool | remove (const String_type &key)=0 |
Remove the key=value pair for the given key if it exists. More... | |
virtual const String_type | raw_string () const =0 |
Create a string containing all key=value pairs as a semicolon separated list. More... | |
virtual bool | get (const String_type &key, String_type *value) const =0 |
Get the string value for a given key. More... | |
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... | |
virtual bool | set (const String_type &key, const String_type &value)=0 |
Add a new key=value pair where the value is a string. 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 | |
Properties & | operator= (const Properties &)=delete |
virtual | ~Properties ()=default |
Static Public Member Functions | |
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 Properties * | parse_properties (const String_type &raw_properties) |
Parse the submitted string for properties on the format "key=value;key=value;...". More... | |
The Properties class defines an interface for storing key=value pairs, where both key and value may be UTF-8 strings.
The interface contains functions for testing whether a key exists, replacing or removing key=value pairs, iteration etc. The interface also defines template functions for converting between strings and various primitive types.
Please note that in debug builds, the get() functions will assert that the key exists. This is to make sure that non-existing keys are handled explicitly at the client side.
The raw_string() function returns a semicolon separated list of all key=value pairs. Characters '=' and ';' that are part of key or value are escaped using the '\' as an escape character. The escape character itself must also be escaped if being part of key or value.
Examples of usage:
Add key=value: p->set("akey=avalue");
Add a numeric value: p->set("intvalue", 1234);
Get values: int32 num; p->get("intvalue", &num);
Get raw string: String_type mylist= p->raw_string();
Further comments can be found in the files properties_impl.{h,cc} where the interface is implemented.
typedef Map::const_iterator dd::Properties::const_iterator |
typedef Map::iterator dd::Properties::iterator |
typedef std::map<String_type, String_type> dd::Properties::Map |
typedef std::map<String_type,String_type>::size_type dd::Properties::size_type |
|
default |
|
default |
|
virtualdefault |
|
pure virtual |
Implemented in dd::Properties_impl.
|
pure virtual |
Implemented in dd::Properties_impl.
|
pure virtual |
Remove all key=value pairs.
Implemented in dd::Properties_impl.
|
pure virtual |
Are there any key=value pairs?
Implemented in dd::Properties_impl.
|
pure virtual |
Implemented in dd::Properties_impl.
|
pure virtual |
Implemented in dd::Properties_impl.
|
pure virtual |
Check for the existence of a key=value pair given the key.
key | Key to be checked. |
Implemented in dd::Properties_impl.
|
static |
Convert string to bool.
Valid values are "true", "false", and decimal numbers, where "0" will be taken to mean false, and numbers != 0 will be taken to mean true.
bool_str | String containing boolean value to convert. | |
[out] | value | Converted value. |
true | if an error occurred |
false | if success |
|
static |
Convert a string to a value of an integral type.
Verify correct sign, check for overflow and conversion errors.
T | Value type. |
number | String containing integral value to convert. | |
[out] | value | Converted value. |
true | if an error occurred |
false | if success |
bool dd::Properties::get | ( | const String_type & | key, |
Lex_type * | value, | ||
MEM_ROOT * | mem_root | ||
) | const |
Get the lex string value for a given key.
Return true (assert in debug builds) if the operation fails, i.e., if the key does not exist or if the key is invalid.
Lex_type | Type of LEX string. |
key | Key to lookup the value for. | |
[out] | value | LEX_STRING or LEX_CSTRING value. |
[in] | mem_root | MEM_ROOT to allocate string. |
|
pure virtual |
Get the string value for a given key.
Return true (assert in debug builds) if the operation fails, i.e., if the key does not exist or if the key is invalid.
key | Key to lookup the value for. | |
[out] | value | String value. |
Implemented in dd::Properties_impl.
bool dd::Properties::get | ( | const String_type & | key, |
Value_type * | value | ||
) | const |
Get the string value for the key and convert it to the appropriate type.
Return true (assert in debug builds) if the operation fails, i.e., if the key does not exist or is invalid, or if the type conversion fails.
Value_type | Type of the value to get. |
key | Key to lookup. | |
[out] | value | Value of appropriate type. |
|
pure virtual |
Insert keys and values from a different property object.
properties | Object which will have its properties copied to 'this' object. |
Implemented in dd::Properties_impl.
|
pure virtual |
Insert keys and values from a raw string.
Invalid keys will be silently ignored, using the set of valid keys in the target object as a filter. The source is a string, so it has no definition of valid keys.
raw_string | String with key/value pairs which will be parsed and added to the 'this' object. |
Implemented in dd::Properties_impl.
|
delete |
|
static |
Parse the submitted string for properties on the format "key=value;key=value;...".
Create new property object and add the properties to the map in the object.
raw_properties | string containing list of key=value pairs |
NULL | if an error occurred |
|
pure virtual |
Create a string containing all key=value pairs as a semicolon separated list.
Key and value are separated by '='. The '=' and ';' characters are escaped using '\' if part of key or value, hence, the escape character '\' must also be escaped.
Implemented in dd::Properties_impl.
|
pure virtual |
Remove the key=value pair for the given key if it exists.
Otherwise, do nothing.
key | key to lookup. |
Implemented in dd::Properties_impl.
|
pure virtual |
Add a new key=value pair where the value is a string.
If the key already exists, the associated value will be replaced by the new value argument.
Return true (assert in debug builds) if the operation fails, i.e., if the key is invalid.
key | Key to map to a value. |
value | String value to be associated with the key. |
Implemented in dd::Properties_impl.
|
inline |
Convert the value to a string and set it for the given key.
Return true (assert in debug builds) if the operation fails, i.e., if the key is invalid.
Value_type | Type of the value to set. |
key | Key to assign to. | |
[out] | value | Value of appropriate type. |
|
pure virtual |
Get the number of key=value pairs.
Implemented in dd::Properties_impl.
|
static |
Convert a value of an integral type (including bool) to a string.
Create an output stream and write the value.
T | Value type. |
value | Actual value to convert. |
|
pure virtual |
Check if the submitted key is valid.
key | Key to be checked. |
true | if the key is valid, otherwise false. |
Implemented in dd::Properties_impl.