Kea: staged_value.h Source File

| Kea 3.0.0

staged_value.h
Go to the documentation of this file.
1// Copyright (C) 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 STAGED_VALUE_H
8#define STAGED_VALUE_H
9
10#include <boost/noncopyable.hpp>
11#include <boost/shared_ptr.hpp>
12
13namespace isc {
14namespace util {
15
31template<typename ValueType>
32 class StagedValue : public boost::noncopyable {
33public:
34
38 StagedValue()
39 : staging_(new ValueType()), current_(new ValueType()),
40 modified_(false) {
41 }
42
48 const ValueType& getValue() const {
49 return (modified_ ? *staging_ : *current_);
50 }
51
55 void setValue(const ValueType& new_value) {
56 *staging_ = new_value;
57 modified_ = true;
58 }
59
61 void commit() {
62 // Only apply changes if any modifications made.
63 if (modified_) {
64 current_ = staging_;
65 }
66 revert();
67 }
68
70 void reset() {
71 revert();
72 current_.reset(new ValueType());
73 }
74
76 void revert() {
77 staging_.reset(new ValueType());
78 modified_ = false;
79 }
80
85 StagedValue& operator=(const ValueType& value) {
86 setValue(value);
87 return (*this);
88 }
89
93 operator const ValueType&() const {
94 return (getValue());
95 }
96
97private:
98
102 boost::shared_ptr<ValueType> staging_;
103
107 boost::shared_ptr<ValueType> current_;
108
111 bool modified_;
112
113};
114
115} // namespace isc::util
116} // namespace isc
117
118#endif // STAGED_VALUE_H
isc::util::StagedValue::revert
void revert()
Reverts any modifications since last commit.
Definition staged_value.h:76
isc::util::StagedValue::operator=
StagedValue & operator=(const ValueType &value)
Assignment operator.
Definition staged_value.h:85
isc::util::StagedValue::commit
void commit()
Commits a value.
Definition staged_value.h:61
isc::util::StagedValue::setValue
void setValue(const ValueType &new_value)
Sets new value.
Definition staged_value.h:55
isc::util::StagedValue::getValue
const ValueType & getValue() const
Retrieves current value.
Definition staged_value.h:48
isc::util::StagedValue::reset
void reset()
Resets value to defaults.
Definition staged_value.h:70
isc::util::StagedValue::StagedValue
StagedValue()
Constructor.
Definition staged_value.h:38
isc::util
Definition time_utils.cc:43
isc
Defines the logger used by the top-level component of kea-lfc.
Definition agent_parser.cc:148