Kea  1.5.0
triplet.h
Go to the documentation of this file.
1 // Copyright (C) 2012-2015 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 TRIPLET_H
8 #define TRIPLET_H
9 
10 #include <exceptions/exceptions.h>
11 
12 namespace isc {
13 namespace dhcp {
14 
35 template <class T>
36 class Triplet {
37 public:
38 
45  Triplet<T>& operator=(T other) {
46  min_ = other;
47  default_ = other;
48  max_ = other;
49  // The value is now specified because we just assigned one.
50  unspecified_ = false;
51  return (*this);
52  }
53 
58  operator T() const {
59  return (default_);
60  }
61 
66  : min_(0), default_(0), max_(0),
67  unspecified_(true) {
68  }
69 
76  Triplet(T value)
77  : min_(value), default_(value), max_(value),
78  unspecified_(false) {
79  }
80 
84  Triplet(T min, T def, T max)
85  : min_(min), default_(def), max_(max),
86  unspecified_(false) {
87  if ( (min_ > def) || (def > max_) ) {
88  isc_throw(BadValue, "Invalid triplet values.");
89  }
90  }
91 
93  T getMin() const { return (min_);}
94 
96  T get() const { return (default_); }
97 
110  T get(T hint) const {
111  if (hint <= min_) {
112  return (min_);
113  }
114 
115  if (hint >= max_) {
116  return (max_);
117  }
118 
119  return (hint);
120  }
121 
123  T getMax() const { return (max_); }
124 
128  bool unspecified() const {
129  return (unspecified_);
130  }
131 
132 private:
133 
135  T min_;
136 
138  T default_;
139 
141  T max_;
142 
144  bool unspecified_;
145 };
146 
147 
148 } // namespace isc::dhcp
149 } // namespace isc
150 
151 #endif // TRIPLET_H
Triplet(T min, T def, T max)
Sets the default value and thresholds.
Definition: triplet.h:84
#define isc_throw(type, stream)
A shortcut macro to insert known values into exception arguments.
A generic exception that is thrown if a parameter given to a method is considered invalid in that con...
T get() const
Returns the default value.
Definition: triplet.h:96
bool unspecified() const
Check if the value has been specified.
Definition: triplet.h:128
T getMax() const
Returns a maximum allowed value.
Definition: triplet.h:123
Triplet()
Constructor without parameters.
Definition: triplet.h:65
T get(T hint) const
Returns value with a hint.
Definition: triplet.h:110
This template specifies a parameter value.
Definition: triplet.h:36
Defines the logger used by the top-level component of kea-dhcp-ddns.
Triplet< T > & operator=(T other)
Base type to Triplet conversion.
Definition: triplet.h:45
T getMin() const
Returns a minimum allowed value.
Definition: triplet.h:93
Triplet(T value)
Sets a fixed value.
Definition: triplet.h:76