Kea  1.9.9-git
labeled_value.h
Go to the documentation of this file.
1 // Copyright (C) 2013-2016 Internet Systems Consortium, Inc. ("ISC")
2 //
3 // This Source Code Form is subject to the terms of the Mozilla Public
4 // License, v. 2.0. If a copy of the MPL was not distributed with this
5 // file, You can obtain one at http://mozilla.org/MPL/2.0/.
6 
7 #ifndef LABELED_VALUE_H
8 #define LABELED_VALUE_H
9 
10 #include <exceptions/exceptions.h>
11 
12 #include <boost/shared_ptr.hpp>
13 #include <ostream>
14 #include <string>
15 #include <map>
16 
19 
20 namespace isc {
21 namespace util {
22 
25 public:
26  LabeledValueError(const char* file, size_t line, const char* what) :
27  isc::Exception(file, line, what) { };
28 };
29 
39 class LabeledValue {
40 public:
41 
48  LabeledValue(const int value, const std::string& label);
49 
53  virtual ~LabeledValue();
54 
58  int getValue() const;
59 
63  std::string getLabel() const;
64 
68  bool operator==(const LabeledValue& other) const;
69 
73  bool operator!=(const LabeledValue& other) const;
74 
78  bool operator<(const LabeledValue& other) const;
79 
80 private:
82  int value_;
83 
85  std::string label_;
86 };
87 
89 std::ostream& operator<<(std::ostream& os, const LabeledValue& vlp);
90 
92 typedef boost::shared_ptr<LabeledValue> LabeledValuePtr;
93 
95 typedef std::map<unsigned int, LabeledValuePtr> LabeledValueMap;
96 
97 
115 public:
117  static const char* UNDEFINED_LABEL;
118 
122  LabeledValueSet();
123 
127  virtual ~LabeledValueSet();
128 
135  void add(LabeledValuePtr entry);
136 
144  void add(const int value, const std::string& label);
145 
152  const LabeledValuePtr& get(int value);
153 
159  bool isDefined(const int value) const;
160 
167  std::string getLabel(const int value) const;
168 
169 private:
171  LabeledValueMap map_;
172 };
173 
174 } // namespace isc::util
175 } // namespace isc
176 #endif
virtual ~LabeledValueSet()
Destructor.
int getValue() const
Gets the integer value of this instance.
LabeledValueSet()
Constructor.
bool operator==(const LabeledValue &other) const
Equality operator.
std::ostream & operator<<(std::ostream &os, const CSVRow &row)
Overrides standard output stream operator for CSVRow object.
Definition: csv_file.cc:100
std::map< unsigned int, LabeledValuePtr > LabeledValueMap
Defines a map of pointers to LabeledValues keyed by value.
Definition: labeled_value.h:95
Thrown if an error is encountered handling a LabeledValue.
Definition: labeled_value.h:24
boost::shared_ptr< LabeledValue > LabeledValuePtr
Defines a shared pointer to a LabeledValue instance.
Definition: labeled_value.h:92
LabeledValueError(const char *file, size_t line, const char *what)
Definition: labeled_value.h:26
Implements the concept of a constant value with a text label.
Definition: labeled_value.h:39
virtual const char * what() const
Returns a C-style character string of the cause of the exception.
std::string getLabel() const
Gets the text label of this instance.
virtual ~LabeledValue()
Destructor.
This is a base class for exceptions thrown from the DNS library module.
Defines the logger used by the top-level component of kea-dhcp-ddns.
Implements a set of unique LabeledValues.
std::string getLabel(const int value) const
Fetches the label for the given value.
LabeledValue(const int value, const std::string &label)
Constructor.
bool operator<(const LabeledValue &other) const
Less-than operator.
bool isDefined(const int value) const
Tests if the set contains an entry for the given value.
bool operator!=(const LabeledValue &other) const
Inequality operator.
static const char * UNDEFINED_LABEL
Defines a text label returned by when value is not found.
void add(LabeledValuePtr entry)
Adds the given entry to the set.