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 
11 namespace isc {
12 namespace data {
13 
14 StampedValue::StampedValue(const std::string& name,
15  const std::string& value)
16  : StampedElement(), name_(name), value_(value) {
17 }
18 
19 StampedValue::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 
32 StampedValue::create(const std::string& name,
33  const std::string& value) {
34  return (StampedValuePtr(new StampedValue(name, value)));
35 }
36 
38 StampedValue::create(const std::string& name,
39  const int64_t value) {
40  return (StampedValuePtr(new StampedValue(name, value)));
41 }
42 
43 
44 int64_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
stamped_value.h
isc
Defines the logger used by the top-level component of kea-dhcp-ddns.
Definition: agent_parser.cc:144
isc::data::StampedValue::create
static StampedValuePtr create(const std::string &name, const std::string &value)
Convenience function creating shared pointer to the object.
Definition: stamped_value.cc:32
isc::data::StampedValue::getSignedIntegerValue
int64_t getSignedIntegerValue() const
Returns value as signed integer.
Definition: stamped_value.cc:45
isc_throw
#define isc_throw(type, stream)
A shortcut macro to insert known values into exception arguments.
Definition: exceptions/exceptions.h:192
isc::BadValue
A generic exception that is thrown if a parameter given to a method is considered invalid in that con...
Definition: exceptions/exceptions.h:132
isc::data::StampedElement
This class represents configuration element which is associated with the modification timestamp.
Definition: stamped_element.h:31
isc::data::StampedValue::StampedValue
StampedValue(const std::string &name, const std::string &value)
Constructor.
Definition: stamped_value.cc:14
exceptions.h
name_
const Name & name_
Definition: dns/message.cc:693
isc::data::StampedValuePtr
boost::shared_ptr< StampedValue > StampedValuePtr
Pointer to the stamped value.
Definition: stamped_value.h:18