Kea 2.7.6
isc::data::StampedValue Class Reference

This class represents a named configuration parameter, e.g. More...

#include <stamped_value.h>

+ Inheritance diagram for isc::data::StampedValue:

Public Member Functions

 StampedValue (const std::string &name)
 Constructor creating a null value.
 
 StampedValue (const std::string &name, const ElementPtr &value)
 Constructor creating a value from the Element.
 
 StampedValue (const std::string &name, const std::string &value)
 Constructor creating a string value.
 
bool amNull () const
 Checks if the value is null.
 
bool getBoolValue () const
 Returns value as a boolean.
 
double getDoubleValue () const
 Returns value as a real number.
 
ConstElementPtr getElementValue () const
 Returns the value as Element.
 
int64_t getIntegerValue () const
 Returns value as signed integer.
 
std::string getName () const
 Returns value name.
 
int getType () const
 Returns a type of the value.
 
std::string getValue () const
 Returns value as string.
 
- Public Member Functions inherited from isc::data::StampedElement
 StampedElement ()
 Constructor.
 
void delServerTag (const std::string &server_tag)
 Deletes server tag.
 
isc::data::ElementPtr getMetadata () const
 Returns an object representing metadata to be returned with objects from the configuration backend.
 
std::set< ServerTaggetServerTags () const
 Returns server tags.
 
bool hasAllServerTag () const
 Checks if the element has 'all' server tag.
 
bool hasServerTag (const ServerTag &server_tag) const
 Checks if the element has the given server tag.
 
void setServerTag (const std::string &server_tag)
 Adds new server tag.
 
- Public Member Functions inherited from isc::data::BaseStampedElement
 BaseStampedElement ()
 Constructor.
 
uint64_t getId () const
 Returns element's database identifier.
 
boost::posix_time::ptime getModificationTime () const
 Returns timestamp.
 
void setId (const uint64_t id)
 Sets element's database identifier.
 
void setModificationTime (const boost::posix_time::ptime &timestamp)
 Sets timestamp to the explicitly provided value.
 
void updateModificationTime ()
 Sets timestamp to the current time.
 

Static Public Member Functions

static StampedValuePtr create (const std::string &name)
 Factory function creating a null value.
 
static StampedValuePtr create (const std::string &name, const ElementPtr &value)
 Factory function creating a value from the Element.
 
static StampedValuePtr create (const std::string &name, const std::string &value)
 Factory function creating a string value.
 
static StampedValuePtr create (const std::string &name, const std::string &value, Element::types type)
 Factory function which attempts to convert provided string value to a given type.
 

Additional Inherited Members

- Protected Attributes inherited from isc::data::BaseStampedElement
uint64_t id_
 Database identifier of the configuration element.
 
boost::posix_time::ptime timestamp_
 Holds timestamp value.
 

Detailed Description

This class represents a named configuration parameter, e.g.

global parameter of the DHCP server.

Global configuration elements having simple types, e.g. DHCP timers, need to be associated with modification timestamps. This association is made by deriving from StampedElement. The values can be strings, integers, booleans or real numbers.

Because the strings are more flexible, configuration elements are always held as strings in the configuration backends. This class reflects a single value held in the database. The value can be return in its orginal type or can be returned as a string. Also the null values are allowed.

Definition at line 41 of file stamped_value.h.

Constructor & Destructor Documentation

◆ StampedValue() [1/3]

isc::data::StampedValue::StampedValue ( const std::string & name)

Constructor creating a null value.

Parameters
nameName of the value.

Definition at line 16 of file stamped_value.cc.

Referenced by create(), create(), and create().

◆ StampedValue() [2/3]

isc::data::StampedValue::StampedValue ( const std::string & name,
const ElementPtr & value )

Constructor creating a value from the Element.

Parameters
nameName of the value.
valueValue encapsulated in the Element object.
Exceptions
BadValueif the value is null.
TypeErrorif the value is neither a string, integer, bool, real or a map with only one element of these types.

Definition at line 20 of file stamped_value.cc.

◆ StampedValue() [3/3]

isc::data::StampedValue::StampedValue ( const std::string & name,
const std::string & value )

Constructor creating a string value.

Creates stamped value from a string.

Parameters
nameName of the value.
valueValue to be set.

Definition at line 25 of file stamped_value.cc.

Member Function Documentation

◆ amNull()

bool isc::data::StampedValue::amNull ( ) const
inline

Checks if the value is null.

Returns
true if the value is null, false otherwise.

Definition at line 135 of file stamped_value.h.

◆ create() [1/4]

StampedValuePtr isc::data::StampedValue::create ( const std::string & name)
static

Factory function creating a null value.

Parameters
nameName of the value.

Definition at line 31 of file stamped_value.cc.

References StampedValue().

Referenced by create().

+ Here is the call graph for this function:

◆ create() [2/4]

StampedValuePtr isc::data::StampedValue::create ( const std::string & name,
const ElementPtr & value )
static

Factory function creating a value from the Element.

Parameters
nameName of the value.
valueValue encapsulated in the Element object.
Exceptions
BadValueif the value is null.
TypeErrorif the value is neither a string, integer, bool, real or a map with only one element of these types.

Definition at line 36 of file stamped_value.cc.

References StampedValue().

+ Here is the call graph for this function:

◆ create() [3/4]

StampedValuePtr isc::data::StampedValue::create ( const std::string & name,
const std::string & value )
static

Factory function creating a string value.

Creates stamped value from a string.

Parameters
nameName of the value.
valueValue to be set.

Definition at line 41 of file stamped_value.cc.

References StampedValue().

+ Here is the call graph for this function:

◆ create() [4/4]

StampedValuePtr isc::data::StampedValue::create ( const std::string & name,
const std::string & value,
Element::types type )
static

Factory function which attempts to convert provided string value to a given type.

This factory function is useful in cases when the value is read as a string from a database. The string value has to be converted to the appropriate data type. The type is also known from the database.

Parameters
nameName of the value.
valueValue given as string to be converted.
typeType of the value to convert to.

Definition at line 46 of file stamped_value.cc.

References isc::data::Element::boolean, isc::data::Element::create(), create(), isc::data::Element::integer, isc_throw, isc::data::Element::real, isc::data::Element::string, and isc::data::Element::typeToName().

+ Here is the call graph for this function:

◆ getBoolValue()

bool isc::data::StampedValue::getBoolValue ( ) const

Returns value as a boolean.

Returns
Stored value as a boolean.
Exceptions
TypeErrorif the value is not of Element::boolean type.

Definition at line 148 of file stamped_value.cc.

References isc::data::Element::boolean.

◆ getDoubleValue()

double isc::data::StampedValue::getDoubleValue ( ) const

Returns value as a real number.

Returns
Stored value as a real number.
Exceptions
TypeErrorif the value is not of Element::real type.

Definition at line 154 of file stamped_value.cc.

References isc::data::Element::real.

◆ getElementValue()

ConstElementPtr isc::data::StampedValue::getElementValue ( ) const
inline

Returns the value as Element.

Definition at line 161 of file stamped_value.h.

◆ getIntegerValue()

int64_t isc::data::StampedValue::getIntegerValue ( ) const

Returns value as signed integer.

Returns
Stored value as a signed integer.
Exceptions
TypeErrorif the value is not of Element::integer type.

Definition at line 142 of file stamped_value.cc.

References isc::data::Element::integer.

◆ getName()

std::string isc::data::StampedValue::getName ( ) const
inline

Returns value name.

Returns
Value name.

Definition at line 117 of file stamped_value.h.

◆ getType()

int isc::data::StampedValue::getType ( ) const

Returns a type of the value.

Returns
Type of the value as integer. It can be compared with the Element::getType() output.
Exceptions
InvalidOperationif the value is null.

Definition at line 96 of file stamped_value.cc.

References isc_throw.

◆ getValue()

std::string isc::data::StampedValue::getValue ( ) const

Returns value as string.

It is allowed to call this function for all supported data types. They are converted to a string. For example, a real number of 1.4 will be returned as "1.4". The boolean true value will be returned as "1" etc.

Returns
Stored value as string.
Exceptions
InvalidOperationif the value is null.

Definition at line 107 of file stamped_value.cc.

References isc::data::Element::boolean, isc::data::Element::integer, isc_throw, isc::data::Element::real, and isc::data::Element::string.


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