Kea 1.5.0
stamped_value.cc
Go to the documentation of this file.
1// Copyright (C) 2018 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#include <cc/stamped_value.h>
9#include <boost/lexical_cast.hpp>
10
11namespace isc {
12namespace data {
13
14StampedValue::StampedValue(const std::string& name,
15 const std::string& value)
16 : StampedElement(), name_(name), value_(value) {
17}
18
19StampedValue::StampedValue(const std::string& name,
20 const int64_t value)
21 : StampedElement(), name_(name), value_() {
22
23 try {
24 value_ = boost::lexical_cast<std::string>(value);
25 } catch (...) {
26 isc_throw(BadValue, "unable to cast value " << value
27 << " to a string");
28 }
29}
30
32StampedValue::create(const std::string& name,
33 const std::string& value) {
34 return (StampedValuePtr(new StampedValue(name, value)));
35}
36
38StampedValue::create(const std::string& name,
39 const int64_t value) {
40 return (StampedValuePtr(new StampedValue(name, value)));
41}
42
43
44int64_t
46 if (!value_.empty()) {
47 try {
48 return (boost::lexical_cast<int64_t>(value_));
49 } catch (...) {
50 isc_throw(BadValue, "unable to cast value " << value_
51 << " to a signed integer");
52 }
53 }
54
55 return (0);
56}
57
58} // end of namespace isc::data
59} // end of namespace isc
A generic exception that is thrown if a parameter given to a method is considered invalid in that con...
This class represents configuration element which is associated with the modification timestamp.
This class represents string or signed integer configuration element associated with the modification...
Definition: stamped_value.h:37
StampedValue(const std::string &name, const std::string &value)
Constructor.
int64_t getSignedIntegerValue() const
Returns value as signed integer.
static StampedValuePtr create(const std::string &name, const std::string &value)
Convenience function creating shared pointer to the object.
const Name & name_
Definition: dns/message.cc:693
#define isc_throw(type, stream)
A shortcut macro to insert known values into exception arguments.
boost::shared_ptr< StampedValue > StampedValuePtr
Pointer to the stamped value.
Definition: stamped_value.h:21
Defines the logger used by the top-level component of kea-dhcp-ddns.