Kea
1.9.9-git
|
A template representing an optional value. More...
#include <optional.h>
Public Types | |
typedef T | ValueType |
Type of the encapsulated value. More... | |
Public Member Functions | |
Optional () | |
Default constructor. More... | |
template<typename A > | |
Optional (A value, const bool unspecified=false) | |
Constructor. More... | |
template<> | |
Optional () | |
bool | empty () const |
Checks if the encapsulated value is empty. More... | |
template<> | |
bool | empty () const |
T | get () const |
Retrieves the encapsulated value. More... | |
operator T () const | |
Type cast operator. More... | |
bool | operator!= (const T &other) const |
Inequality operator. More... | |
template<typename A > | |
Optional< T > & | operator= (A other) |
Assigns a new value value and marks it "specified". More... | |
bool | operator== (const T &other) const |
Equality operator. More... | |
void | unspecified (bool unspecified) |
Modifies the flag that indicates whether the value is specified or unspecified. More... | |
bool | unspecified () const |
Checks if the value has been specified or unspecified. More... | |
Protected Attributes | |
T | default_ |
Encapsulated value. More... | |
bool | unspecified_ |
Flag which indicates if the value is specified. More... | |
A template representing an optional value.
This template class encapsulates an optional value. The default implementation encapsulates numeric values, but additional specializations are defined as necessary to support other types od data.
This class includes a boolean flag which indicates if the encapsulated value is specified or unspecified. For example, a configuration parser for the DHCP server may use this class to represent a value of the configuration parameter which may appear in the configuration file, but is not mandatory. The value of the Optional
may be initialized to "unspecified" initially. When the configuration parser finds that the particular parameter exists in the configuration file, the default value can be overridden and the value may be marked as "specified". If the parameter is not found, the value remains "unspecified" and the appropriate actions may be taken, e.g. the default value may be used.
Type | of the encapsulated value. |
Definition at line 36 of file optional.h.
typedef T isc::util::Optional< T >::ValueType |
Type of the encapsulated value.
Definition at line 40 of file optional.h.
|
inline |
Default constructor.
Sets the encapsulated value to 0 and marks it as "unspecified".
The caller must ensure that the constructor of the class T
creates a valid object when invoked with 0 as an argument. For example, a std::string(0)
compiles but will crash at runtime as 0 is not a valid pointer for the std::string(const char*)
constructor. Therefore, the specialization of the Optional
template for std::string
is provided below. It uses std::string
default constructor.
For any other type used with this template which doesn't come with an appropriate constructor, the caller must create a template specialization similar to the one provided for std::string
below.
Definition at line 94 of file optional.h.
|
inline |
Constructor.
Sets an explicit value and marks it as "specified".
A | Type of the value to be assigned. Typically this is T , but may also be a type that can be cast to T . |
value | value to be assigned. |
unspecified | initial state. Default is "unspecified". |
Definition at line 107 of file optional.h.
|
inline |
It calls default string object constructor.
Definition at line 152 of file optional.h.
|
inline |
Checks if the encapsulated value is empty.
This method can be overloaded in the template specializations that are dedicated to strings, vectors etc.
isc::InvalidOperation. |
Definition at line 138 of file optional.h.
Referenced by isc::dhcp::Subnet6ConfigParser::initSubnet(), isc::dhcp::SharedNetwork6Parser::parse(), and isc::dhcp::CfgSubnets4::selectSubnet4o6().
|
inline |
Definition at line 160 of file optional.h.
|
inline |
Retrieves the encapsulated value.
Definition at line 112 of file optional.h.
Referenced by isc::db::MySqlBinding::condCreateBool(), isc::db::MySqlBinding::condCreateFloat(), isc::db::MySqlBinding::condCreateInteger(), isc::db::MySqlBinding::condCreateIPv4Address(), isc::dhcp::Network::getDdnsReplaceClientNameMode(), isc::dhcp::Subnet6ConfigParser::initSubnet(), isc::process::ConfigBase::merge(), isc::dhcp::SharedNetwork6Parser::parse(), isc::dhcp::BaseNetworkParser::parseTeePercents(), isc::dhcp::Network4::setSiaddr(), and isc::ha::HAConfig::validate().
|
inline |
Type cast operator.
This operator converts the optional value to the actual value being encapsulated.
Definition at line 60 of file optional.h.
|
inline |
Inequality operator.
other | value to be compared. |
Definition at line 74 of file optional.h.
|
inline |
Assigns a new value value and marks it "specified".
A | Type of the value to be assigned. Typically this is T , but may also be a type that can be cast to T . |
other | new actual value. |
Definition at line 48 of file optional.h.
|
inline |
|
inline |
Modifies the flag that indicates whether the value is specified or unspecified.
unspecified | new value of the flag. If it is true , the value is marked as unspecified, otherwise it is marked as specified. |
Definition at line 121 of file optional.h.
Referenced by isc::db::MySqlBinding::condCreateBool(), isc::db::MySqlBinding::condCreateFloat(), isc::db::MySqlBinding::condCreateInteger(), isc::db::MySqlBinding::condCreateIPv4Address(), isc::db::MySqlBinding::condCreateString(), isc::dhcp::Network::getDdnsReplaceClientNameMode(), isc::dhcp::Subnet6ConfigParser::initSubnet(), isc::process::ConfigBase::merge(), isc::dhcp::SharedNetwork6Parser::parse(), isc::dhcp::BaseNetworkParser::parseTeePercents(), isc::dhcp::CqlHostExchange::prepareExchange(), isc::dhcp::ClientClassDef::toElement(), isc::process::ConfigControlInfo::toElement(), isc::dhcp::SrvConfig::toElement(), and isc::ha::HAConfig::validate().
|
inline |
Checks if the value has been specified or unspecified.
Definition at line 128 of file optional.h.
Referenced by isc::util::Optional< isc::dhcp::D2ClientConfig::ReplaceClientNameMode >::unspecified().
|
protected |
Encapsulated value.
Definition at line 143 of file optional.h.
Referenced by isc::util::Optional< isc::dhcp::D2ClientConfig::ReplaceClientNameMode >::get(), isc::util::Optional< uint32_t >::operator uint32_t(), isc::util::Optional< isc::dhcp::D2ClientConfig::ReplaceClientNameMode >::operator!=(), isc::util::Optional< isc::dhcp::D2ClientConfig::ReplaceClientNameMode >::operator=(), and isc::util::Optional< isc::dhcp::D2ClientConfig::ReplaceClientNameMode >::operator==().
|
protected |
Flag which indicates if the value is specified.
Definition at line 144 of file optional.h.
Referenced by isc::util::Optional< isc::dhcp::D2ClientConfig::ReplaceClientNameMode >::operator=(), and isc::util::Optional< isc::dhcp::D2ClientConfig::ReplaceClientNameMode >::unspecified().