Kea  1.5.0
isc::util::OptionalValue< T > Class Template Reference

Simple class representing an optional value. More...

#include <optional_value.h>

Public Member Functions

 OptionalValue ()
 Default constructor. More...
 
 OptionalValue (const T &value, const OptionalValueState &state=OptionalValueState(false))
 Constructor. More...
 
get () const
 Retrieves the actual value. More...
 
bool isSpecified () const
 Checks if the value is specified or unspecified. More...
 
 operator T () const
 Type cast operator. More...
 
bool operator!= (const T &value) const
 Inequality operator. More...
 
void operator= (const T &value)
 Specifies a new value value and marks it "specified". More...
 
bool operator== (const T &value) const
 Equality operator. More...
 
void set (const T &value)
 Sets the actual value. More...
 
void specify (const OptionalValueState &state)
 Sets the value to "specified" or "unspecified". More...
 
void specify (const T &value)
 Sets the new value and marks it specified. More...
 

Detailed Description

template<typename T>
class isc::util::OptionalValue< T >

Simple class representing an optional value.

This template class encapsulates a value of any type. An additional flag held by this class indicates if the value is "specified" or "unspecified". For example, a configuration parser for DHCP server may use this class to represent the value of the configuration parameter which may appear in the configuration file, but is not mandatory. The value of the OptionalValue may be initialized to "unspecified" initially. When the configuration parser finds that the appropriate 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.

This is a generic class and may be used in all cases when there is a need for the additional information to be carried along with the value. Alternative approach is to use a pointer which is only initialized if the actual value needs to be specified, but this may not be feasible in all cases.

Template Parameters
Typeof the encapsulated value.

Definition at line 55 of file optional_value.h.

Constructor & Destructor Documentation

◆ OptionalValue() [1/2]

template<typename T >
isc::util::OptionalValue< T >::OptionalValue ( )
inline

Default constructor.

Note that the type T must have a default constructor to use this constructor.

Definition at line 62 of file optional_value.h.

◆ OptionalValue() [2/2]

template<typename T >
isc::util::OptionalValue< T >::OptionalValue ( const T &  value,
const OptionalValueState state = OptionalValueState(false) 
)
inlineexplicit

Constructor.

Creates optional value. The value defaults to "unspecified".

Parameters
valueDefault explicit value.
stateSpecifies bool which determines if the value is initially specified or not (default is false).

Definition at line 73 of file optional_value.h.

Member Function Documentation

◆ get()

◆ isSpecified()

template<typename T >
bool isc::util::OptionalValue< T >::isSpecified ( ) const
inline

Checks if the value is specified or unspecified.

Returns
true if the value is specified, false otherwise.

Definition at line 110 of file optional_value.h.

Referenced by isc::dhcp::Iface::countActive4(), isc::dhcp::IfaceMgr::openSockets4(), and isc::dhcp::CqlHostExchange::prepareExchange().

◆ operator T()

template<typename T >
isc::util::OptionalValue< T >::operator T ( ) const
inline

Type cast operator.

This operator converts the optional value to the actual value being encapsulated.

Returns
Encapsulated value.

Definition at line 145 of file optional_value.h.

◆ operator!=()

template<typename T >
bool isc::util::OptionalValue< T >::operator!= ( const T &  value) const
inline

Inequality operator.

Parameters
valueActual value to compare to.
Returns
true if the value is unspecified or unequal.

Definition at line 135 of file optional_value.h.

◆ operator=()

template<typename T >
void isc::util::OptionalValue< T >::operator= ( const T &  value)
inline

Specifies a new value value and marks it "specified".

Parameters
valueNew actual value.

Definition at line 117 of file optional_value.h.

References isc::util::OptionalValue< T >::specify().

+ Here is the call graph for this function:

◆ operator==()

template<typename T >
bool isc::util::OptionalValue< T >::operator== ( const T &  value) const
inline

Equality operator.

Parameters
valueActual value to compare to.
Returns
true if the value is specified and equals the argument.

Definition at line 126 of file optional_value.h.

◆ set()

template<typename T >
void isc::util::OptionalValue< T >::set ( const T &  value)
inline

Sets the actual value.

Parameters
valueNew value.

Definition at line 86 of file optional_value.h.

Referenced by isc::util::OptionalValue< T >::specify().

◆ specify() [1/2]

template<typename T >
void isc::util::OptionalValue< T >::specify ( const OptionalValueState state)
inline

Sets the value to "specified" or "unspecified".

It does not alter the actual value. It only marks it "specified" or "unspecified".

Parameters
statedetermines if a value is specified or not

Definition at line 103 of file optional_value.h.

References isc::util::OptionalValueState::specified_.

◆ specify() [2/2]

template<typename T >
void isc::util::OptionalValue< T >::specify ( const T &  value)
inline

Sets the new value and marks it specified.

Parameters
valueNew actual value.

Definition at line 93 of file optional_value.h.

References isc::util::OptionalValue< T >::set().

Referenced by isc::util::OptionalValue< T >::operator=().

+ Here is the call graph for this function:

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