Kea 2.5.8
triplet.h
Go to the documentation of this file.
1// Copyright (C) 2012-2021 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
11#include <util/optional.h>
12
13namespace isc {
14namespace util {
15
36template <class T>
37class Triplet : public util::Optional<T> {
38public:
39
40 using util::Optional<T>::get;
41
49 min_ = other;
51 max_ = other;
52 // The value is now specified because we just assigned one.
54 return (*this);
55 }
56
61 : util::Optional<T>(), min_(0), max_(0) {
62 }
63
70 Triplet(T value)
71 : util::Optional<T>(value), min_(value), max_(value) {
72 }
73
77 Triplet(T min, T def, T max)
78 : util::Optional<T>(def), min_(min), max_(max) {
79 if ( (min_ > def) || (def > max_) ) {
80 isc_throw(BadValue, "Invalid triplet values.");
81 }
82 }
83
85 T getMin() const { return (min_);}
86
99 T get(T hint) const {
100 if (hint <= min_) {
101 return (min_);
102 }
103
104 if (hint >= max_) {
105 return (max_);
106 }
107
108 return (hint);
109 }
110
112 T getMax() const { return (max_); }
113
114private:
115
117 T min_;
118
120 T max_;
121};
122
123
124} // namespace isc::dhcp
125} // namespace isc
126
127#endif // TRIPLET_H
A generic exception that is thrown if a parameter given to a method is considered invalid in that con...
A template representing an optional value.
Definition: optional.h:36
T get() const
Retrieves the encapsulated value.
Definition: optional.h:114
This template specifies a parameter value.
Definition: triplet.h:37
Triplet()
Constructor without parameters.
Definition: triplet.h:60
Triplet(T min, T def, T max)
Sets the default value and thresholds.
Definition: triplet.h:77
T get(T hint) const
Returns value with a hint.
Definition: triplet.h:99
Triplet< T > & operator=(T other)
Base type to Triplet conversion.
Definition: triplet.h:48
T getMax() const
Returns a maximum allowed value.
Definition: triplet.h:112
T getMin() const
Returns a minimum allowed value.
Definition: triplet.h:85
Triplet(T value)
Sets a fixed value.
Definition: triplet.h:70
#define isc_throw(type, stream)
A shortcut macro to insert known values into exception arguments.
Defines the logger used by the top-level component of kea-lfc.