Kea 2.5.8
isc::util::LabeledValueSet Class Reference

Implements a set of unique LabeledValues. More...

#include <labeled_value.h>

+ Inheritance diagram for isc::util::LabeledValueSet:

Public Member Functions

 LabeledValueSet ()
 Constructor.
 
virtual ~LabeledValueSet ()
 Destructor.
 
void add (const int value, const std::string &label)
 Adds an entry to the set for the given value and label.
 
void add (LabeledValuePtr entry)
 Adds the given entry to the set.
 
const LabeledValuePtrget (int value)
 Fetches a pointer to the entry associated with value.
 
std::string getLabel (const int value) const
 Fetches the label for the given value.
 
bool isDefined (const int value) const
 Tests if the set contains an entry for the given value.
 

Static Public Attributes

static const char * UNDEFINED_LABEL = "UNDEFINED"
 Defines a text label returned by when value is not found.
 

Detailed Description

Implements a set of unique LabeledValues.

This class is intended to function as a dictionary of numeric values and the labels associated with them. It is essentially a thin wrapper around a std::map of LabeledValues, keyed by their values. This is handy for defining a set of "valid" constants while conveniently associating a text label with each value.

This class offers two variants of an add method for adding entries to the set, and accessors for finding an entry or an entry's label by value. Note that the add methods may throw but all accessors are exception safe. It is up to the caller to determine when and if an undefined value is exception-worthy.

More interestingly, a derivation of this class can be used to "define" valid instances of derivations of LabeledValue.

Definition at line 114 of file labeled_value.h.

Constructor & Destructor Documentation

◆ LabeledValueSet()

isc::util::LabeledValueSet::LabeledValueSet ( )

Constructor.

Constructs an empty set.

Definition at line 60 of file labeled_value.cc.

◆ ~LabeledValueSet()

isc::util::LabeledValueSet::~LabeledValueSet ( )
virtual

Destructor.

Destructor is virtual to permit derivations.

Definition at line 63 of file labeled_value.cc.

Member Function Documentation

◆ add() [1/2]

void isc::util::LabeledValueSet::add ( const int  value,
const std::string &  label 
)

Adds an entry to the set for the given value and label.

Parameters
valuethe numeric constant value to be labeled.
labelthe text label to associate to this value.
Exceptions
LabeledValuePtrif the label is empty, or if the set already contains an entry with the same value.

Definition at line 83 of file labeled_value.cc.

References add().

+ Here is the call graph for this function:

◆ add() [2/2]

void isc::util::LabeledValueSet::add ( LabeledValuePtr  entry)

Adds the given entry to the set.

Parameters
entryis the entry to add.
Exceptions
LabeledValuePtrif the entry is null or the set already contains an entry with the same value.

Definition at line 67 of file labeled_value.cc.

References getLabel(), isc_throw, and isDefined().

Referenced by add(), isc::util::StateSet::add(), and isc::util::StateModel::defineEvent().

+ Here is the call graph for this function:

◆ get()

const LabeledValuePtr & isc::util::LabeledValueSet::get ( int  value)

Fetches a pointer to the entry associated with value.

Parameters
valueis the value of the entry desired.
Returns
A pointer to the entry if the entry was found otherwise the pointer is empty.

Definition at line 88 of file labeled_value.cc.

Referenced by isc::util::StateModel::getEvent(), and isc::util::StateSet::getState().

◆ getLabel()

std::string isc::util::LabeledValueSet::getLabel ( const int  value) const

Fetches the label for the given value.

Parameters
valueis the value for which the label is desired.
Returns
the label of the value if defined, otherwise it returns UNDEFINED_LABEL.

Definition at line 106 of file labeled_value.cc.

References UNDEFINED_LABEL.

Referenced by add().

◆ isDefined()

bool isc::util::LabeledValueSet::isDefined ( const int  value) const

Tests if the set contains an entry for the given value.

Parameters
valueis the value of the entry to test.
Returns
True if an entry for value exists in the set, false if not.

Definition at line 100 of file labeled_value.cc.

Referenced by add(), isc::util::StateModel::getEvent(), isc::util::StateSet::getState(), and isc::util::StateModel::getStateInternal().

Member Data Documentation

◆ UNDEFINED_LABEL

const char * isc::util::LabeledValueSet::UNDEFINED_LABEL = "UNDEFINED"
static

Defines a text label returned by when value is not found.

Definition at line 117 of file labeled_value.h.

Referenced by getLabel().


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