Kea 2.7.4
|
Implements a set of unique LabeledValues. More...
#include <labeled_value.h>
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 LabeledValuePtr & | get (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. | |
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.
isc::util::LabeledValueSet::LabeledValueSet | ( | ) |
|
virtual |
Destructor.
Destructor is virtual to permit derivations.
Definition at line 63 of file labeled_value.cc.
void isc::util::LabeledValueSet::add | ( | const int | value, |
const std::string & | label ) |
Adds an entry to the set for the given value and label.
value | the numeric constant value to be labeled. |
label | the text label to associate to this value. |
LabeledValuePtr | if 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().
void isc::util::LabeledValueSet::add | ( | LabeledValuePtr | entry | ) |
Adds the given entry to the set.
entry | is the entry to add. |
LabeledValuePtr | if 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().
const LabeledValuePtr & isc::util::LabeledValueSet::get | ( | int | value | ) |
Fetches a pointer to the entry associated with value.
value | is the value of the entry desired. |
Definition at line 88 of file labeled_value.cc.
Referenced by isc::util::StateModel::getEvent(), and isc::util::StateSet::getState().
std::string isc::util::LabeledValueSet::getLabel | ( | const int | value | ) | const |
Fetches the label for the given value.
value | is the value for which the label is desired. |
Definition at line 106 of file labeled_value.cc.
References UNDEFINED_LABEL.
Referenced by add().
bool isc::util::LabeledValueSet::isDefined | ( | const int | value | ) | const |
Tests if the set contains an entry for the given value.
value | is the value of the entry to test. |
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().
|
static |
Defines a text label returned by when value is not found.
Definition at line 117 of file labeled_value.h.
Referenced by getLabel().