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

Static Public Member Functions

static StampedValuePtr create (const std::string &name)
 Factory function creating a null value. More...
 
static StampedValuePtr create (const std::string &name, const ElementPtr &value)
 Factory function creating a value from the Element. More...
 
static StampedValuePtr create (const std::string &name, const std::string &value)
 Factory function creating a string value. More...
 
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. More...
 

Additional Inherited Members

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

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 associatied 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().

◆ 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 nor real.

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.

References getBoolValue(), getDoubleValue(), and getIntegerValue().

+ Here is the call graph for this function:

◆ 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 nor real.

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, create(), isc::data::Element::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.

Referenced by amNull().

◆ 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::boolean, isc::data::Element::integer, isc_throw, isc::data::Element::real, isc::data::Element::string, and isc::data::Element::typeToName().

Referenced by amNull().

+ Here is the call graph for this function:

◆ 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.

Referenced by amNull().

◆ getName()

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

Returns value name.

Returns
Value name.

Definition at line 117 of file stamped_value.h.

References getValue().

+ Here is the call graph for this function:

◆ 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.

Referenced by getName().


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