Kea 1.5.0
optional_value.h
Go to the documentation of this file.
1// Copyright (C) 2014-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 OPTIONAL_VALUE_H
8#define OPTIONAL_VALUE_H
9
10#include <ostream>
11
12namespace isc {
13namespace util {
14
22
26 OptionalValueState(const bool specified)
27 : specified_(specified) {
28 }
31};
32
54template<typename T>
56public:
57
63 : value_(T()), specified_(false) {
64 }
65
73 explicit OptionalValue(const T& value, const OptionalValueState& state =
74 OptionalValueState(false))
75 : value_(value), specified_(state.specified_) {
76 }
77
79 T get() const {
80 return (value_);
81 }
82
86 void set(const T& value) {
87 value_ = value;
88 }
89
93 void specify(const T& value) {
94 set(value);
96 }
97
103 void specify(const OptionalValueState& state) {
104 specified_ = state.specified_;
105 }
106
110 bool isSpecified() const {
111 return (specified_);
112 }
113
117 void operator=(const T& value) {
118 specify(value);
119 }
120
126 bool operator==(const T& value) const {
127 return (specified_ && (value_ == value));
128 }
129
135 bool operator!=(const T& value) const {
136 return (!operator==(value));
137 }
138
145 operator T() const {
146 return (value_);
147 }
148
149private:
150 T value_;
151 bool specified_;
152};
153
165template<typename T>
166std::ostream&
167operator<<(std::ostream& os, const OptionalValue<T>& optional_value) {
168 os << optional_value.get();
169 return (os);
170}
171
172
173} // end of namespace isc::util
174} // end of namespace isc
175
176#endif // OPTIONAL_VALUE_H
Simple class representing an optional value.
T get() const
Retrieves the actual value.
bool operator==(const T &value) const
Equality operator.
void specify(const T &value)
Sets the new value and marks it specified.
OptionalValue(const T &value, const OptionalValueState &state=OptionalValueState(false))
Constructor.
void specify(const OptionalValueState &state)
Sets the value to "specified" or "unspecified".
void operator=(const T &value)
Specifies a new value value and marks it "specified".
OptionalValue()
Default constructor.
bool isSpecified() const
Checks if the value is specified or unspecified.
bool operator!=(const T &value) const
Inequality operator.
void set(const T &value)
Sets the actual value.
std::ostream & operator<<(std::ostream &os, const CSVRow &row)
Overrides standard output stream operator for CSVRow object.
Definition: csv_file.cc:69
Defines the logger used by the top-level component of kea-dhcp-ddns.
Indicate if an OptionalValue is is specified or not.
bool specified_
A bool value encapsulated by this structure.
OptionalValueState(const bool specified)
Constructor.