Kea 2.7.6
|
A template representing an optional value. More...
#include <optional.h>
Public Types | |
typedef T | ValueType |
Type of the encapsulated value. | |
Public Member Functions | |
Optional () | |
Default constructor. | |
Optional () | |
Specialization of the default Optional constructor for strings. | |
template<typename A > | |
Optional (A value, const bool unspecified=false) | |
Constructor. | |
bool | empty () const |
Checks if the encapsulated value is empty. | |
bool | empty () const |
Specialization of the Optional::empty method for strings. | |
T | get () const |
Retrieves the encapsulated value. | |
operator T () const | |
Type cast operator. | |
bool | operator!= (const T &other) const |
Inequality operator. | |
template<typename A > | |
Optional< T > & | operator= (A other) |
Assigns a new value value and marks it "specified". | |
bool | operator== (const T &other) const |
Equality operator. | |
bool | unspecified () const |
Checks if the value has been specified or unspecified. | |
void | unspecified (bool unspecified) |
Modifies the flag that indicates whether the value is specified or unspecified. | |
T | valueOr (T const &or_value) const |
Retrieves the encapsulated value if specified, or the given value otherwise. | |
Protected Attributes | |
T | default_ |
Encapsulated value. | |
bool | unspecified_ |
Flag which indicates if the value is specified. | |
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.
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 |
Specialization of the default Optional
constructor for strings.
It calls default string object constructor.
Definition at line 167 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 153 of file optional.h.
References isc_throw.
Referenced by isc::dhcp::Subnet6ConfigParser::initSubnet(), isc::dhcp::SharedNetwork6Parser::parse(), isc::dhcp::CfgSubnets4::selectSubnet4o6(), and isc::dhcp::Network::setIface().
|
inline |
Specialization of the Optional::empty
method for strings.
Definition at line 175 of file optional.h.
|
inline |
Retrieves the encapsulated value.
Definition at line 114 of file optional.h.
References isc::util::Optional< T >::default_.
Referenced by isc::db::PsqlBindArray::addOptional(), isc::dhcp::calculateDdnsTtl(), isc::db::MySqlBinding::condCreateBool(), isc::db::MySqlBinding::condCreateFloat(), isc::db::MySqlBinding::condCreateInteger(), isc::db::MySqlBinding::condCreateIPv4Address(), isc::dhcp::OptionDataParser::createOption(), isc::process::ConfigControlInfo::equals(), isc::dhcp::BaseNetworkParser::getAdditionalClassesElem(), isc::dhcp::Network::getDdnsReplaceClientNameMode(), isc::dhcp::AllocEngine::getOfferLft(), isc::dhcp::Subnet6ConfigParser::initSubnet(), isc::process::ConfigBase::merge(), isc::util::operator<<(), isc::dhcp::SharedNetwork6Parser::parse(), isc::dhcp::BaseNetworkParser::parseTeePercents(), isc::dhcp::Network4::setSiaddr(), isc::dhcp::ClientClassDef::toElement(), isc::dhcp::Network::toElement(), isc::process::ConfigBase::toElement(), 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.
References isc::util::Optional< T >::default_.
|
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.
References isc::util::Optional< T >::default_, and isc::util::Optional< T >::unspecified_.
|
inline |
Equality operator.
other | value to be compared. |
Definition at line 67 of file optional.h.
References isc::util::Optional< T >::default_.
|
inline |
Checks if the value has been specified or unspecified.
Definition at line 143 of file optional.h.
References isc::util::Optional< T >::unspecified_.
Referenced by isc::util::Optional< T >::unspecified().
|
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 136 of file optional.h.
References isc::util::Optional< T >::unspecified(), and isc::util::Optional< T >::unspecified_.
Referenced by isc::db::PsqlBindArray::add(), isc::db::PsqlBindArray::addMax(), isc::db::PsqlBindArray::addMin(), isc::db::PsqlBindArray::addOptional(), isc::db::PsqlBindArray::addOptional(), isc::db::PsqlBindArray::addOptionalInet4(), isc::db::PsqlBindArray::addOptionalInet6(), isc::dhcp::calculateDdnsTtl(), isc::db::MySqlBinding::condCreateBool(), isc::db::MySqlBinding::condCreateFloat(), isc::db::MySqlBinding::condCreateInteger(), isc::db::MySqlBinding::condCreateIPv4Address(), isc::db::MySqlBinding::condCreateString(), isc::dhcp::OptionDataParser::createOption(), isc::dhcp::OptionDataParser::findOptionDefinition(), isc::dhcp::Network::getDdnsReplaceClientNameMode(), isc::dhcp::AllocEngine::getLifetimes6(), isc::dhcp::AllocEngine::getOfferLft(), isc::dhcp::Subnet6ConfigParser::initSubnet(), isc::process::ConfigBase::merge(), isc::dhcp::ClientClassDefParser::parse(), isc::dhcp::SharedNetwork6Parser::parse(), isc::dhcp::BaseNetworkParser::parseTeePercents(), isc::dhcp::ClientClassDef::toElement(), isc::dhcp::Network::toElement(), isc::dhcp::SrvConfig::toElement(), isc::process::ConfigBase::toElement(), isc::process::ConfigControlInfo::toElement(), and isc::ha::HAConfig::validate().
|
inline |
Retrieves the encapsulated value if specified, or the given value otherwise.
or_value | the value it defaults to, if unspecified |
Definition at line 124 of file optional.h.
References isc::util::Optional< T >::default_, and isc::util::Optional< T >::unspecified_.
|
protected |
Encapsulated value.
Definition at line 158 of file optional.h.
Referenced by isc::util::Optional< T >::get(), isc::util::Optional< bool >::operator bool(), isc::util::Optional< T >::operator!=(), isc::util::Optional< T >::operator=(), isc::util::Optional< T >::operator==(), and isc::util::Optional< T >::valueOr().
|
protected |
Flag which indicates if the value is specified.
Definition at line 159 of file optional.h.
Referenced by isc::util::Optional< T >::operator=(), isc::util::Optional< T >::unspecified(), isc::util::Optional< T >::unspecified(), and isc::util::Optional< T >::valueOr().