Kea  1.9.9-git
stamped_value.h
Go to the documentation of this file.
1 // Copyright (C) 2018-2019 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 STAMPED_VALUE_H
8 #define STAMPED_VALUE_H
9 
10 #include <cc/data.h>
11 #include <cc/stamped_element.h>
12 #include <boost/multi_index/hashed_index.hpp>
13 #include <boost/multi_index/mem_fun.hpp>
14 #include <boost/multi_index/ordered_index.hpp>
15 #include <boost/multi_index_container.hpp>
16 #include <boost/shared_ptr.hpp>
17 #include <cstdint>
18 #include <string>
19 
20 namespace isc {
21 namespace data {
22 
24 
26 typedef boost::shared_ptr<StampedValue> StampedValuePtr;
27 
41 class StampedValue : public StampedElement {
42 public:
43 
47  StampedValue(const std::string& name);
48 
57  StampedValue(const std::string& name, const ElementPtr& value);
58 
65  StampedValue(const std::string& name, const std::string& value);
66 
70  static StampedValuePtr create(const std::string& name);
71 
80  static StampedValuePtr create(const std::string& name,
81  const ElementPtr& value);
82 
89  static StampedValuePtr create(const std::string& name,
90  const std::string& value);
91 
103  static StampedValuePtr create(const std::string& name,
104  const std::string& value,
105  Element::types type);
106 
112  int getType() const;
113 
117  std::string getName() const {
118  return (name_);
119  }
120 
130  std::string getValue() const;
131 
135  bool amNull() const {
136  return (!value_);
137  }
138 
144  int64_t getIntegerValue() const;
145 
151  bool getBoolValue() const;
152 
158  double getDoubleValue() const;
159 
162  return (value_);
163  }
164 
165 private:
166 
175  void validateConstruct() const;
176 
187  void validateAccess(Element::types type) const;
188 
190  std::string name_;
191 
193  ElementPtr value_;
194 };
195 
198 
199 
202 
205 
207 typedef boost::multi_index_container<
209  boost::multi_index::indexed_by<
210  // Index used to access value by name.
211  boost::multi_index::hashed_non_unique<
212  boost::multi_index::tag<StampedValueNameIndexTag>,
213  boost::multi_index::const_mem_fun<
214  StampedValue,
215  std::string,
217  >
218  >,
219 
220  // Index used to access value by modification time.
221  boost::multi_index::ordered_non_unique<
222  boost::multi_index::tag<StampedValueModificationTimeIndexTag>,
223  boost::multi_index::const_mem_fun<
225  boost::posix_time::ptime,
227  >
228  >
229  >
231 
233 
234 } // end of namespace isc::data
235 } // end of namespace isc
236 
237 #endif
This class represents configuration element which is associated with database identifier, modification timestamp and servers.
int64_t getIntegerValue() const
Returns value as signed integer.
bool getBoolValue() const
Returns value as a boolean.
boost::shared_ptr< StampedValue > StampedValuePtr
Pointer to the stamped value.
Definition: stamped_value.h:23
double getDoubleValue() const
Returns value as a real number.
int getType() const
Returns a type of the value.
boost::shared_ptr< Element > ElementPtr
Definition: data.h:20
static StampedValuePtr create(const std::string &name)
Factory function creating a null value.
std::string getName() const
Returns value name.
bool amNull() const
Checks if the value is null.
boost::posix_time::ptime getModificationTime() const
Returns timestamp.
Tag for the index for access by modification time.
boost::shared_ptr< const Element > ConstElementPtr
Definition: data.h:23
This class represents a named configuration parameter, e.g.
Definition: stamped_value.h:41
Tag for the index for access by value name.
StampedValue(const std::string &name)
Constructor creating a null value.
Defines the logger used by the top-level component of kea-dhcp-ddns.
boost::multi_index_container< StampedValuePtr, boost::multi_index::indexed_by< boost::multi_index::hashed_non_unique< boost::multi_index::tag< StampedValueNameIndexTag >, boost::multi_index::const_mem_fun< StampedValue, std::string,&StampedValue::getName > >, boost::multi_index::ordered_non_unique< boost::multi_index::tag< StampedValueModificationTimeIndexTag >, boost::multi_index::const_mem_fun< BaseStampedElement, boost::posix_time::ptime,&BaseStampedElement::getModificationTime > > >> StampedValueCollection
Multi index container for StampedValue.
ConstElementPtr getElementValue() const
Returns the value as Element.
This class represents configuration element which is associated with database identifier and the modi...
std::string getValue() const
Returns value as string.