Kea  1.5.0
context.cc
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 #include <config.h>
8 
9 #include <stats/context.h>
10 #include <map>
11 
12 namespace isc {
13 namespace stats {
14 
15 ObservationPtr StatContext::get(const std::string& name) const {
16  std::map<std::string, ObservationPtr>::const_iterator obs = stats_.find(name);
17  if (obs == stats_.end()) {
18  return (ObservationPtr());
19  } else {
20  return (obs->second);
21  }
22 }
23 
24 void StatContext::add(const ObservationPtr& obs) {
25  std::map<std::string, ObservationPtr>::iterator existing = stats_.find(obs->getName());
26  if (existing == stats_.end()) {
27  stats_.insert(make_pair(obs->getName() ,obs));
28  } else {
29  isc_throw(DuplicateStat, "Statistic named " << obs->getName()
30  << " already exists.");
31  }
32 
33 }
34 
35 bool StatContext::del(const std::string& name) {
36  std::map<std::string, ObservationPtr>::iterator obs = stats_.find(name);
37  if (obs == stats_.end()) {
38  return (false);
39  } else {
40  stats_.erase(obs);
41  return (true);
42  }
43 }
44 
45 };
46 };
isc::stats::StatContext::add
void add(const ObservationPtr &obs)
Adds a new observation.
Definition: context.cc:24
isc::stats::StatContext::del
bool del(const std::string &name)
Attempts to delete an observation.
Definition: context.cc:35
isc::stats::DuplicateStat
Exception indicating that a given statistic is duplicated.
Definition: context.h:18
isc::stats::StatContext::get
ObservationPtr get(const std::string &name) const
attempts to get an observation
Definition: context.cc:15
isc::stats::ObservationPtr
boost::shared_ptr< Observation > ObservationPtr
Observation pointer.
Definition: observation.h:261
isc
Defines the logger used by the top-level component of kea-dhcp-ddns.
Definition: agent_parser.cc:144
isc_throw
#define isc_throw(type, stream)
A shortcut macro to insert known values into exception arguments.
Definition: exceptions/exceptions.h:192
isc::stats::StatContext::stats_
std::map< std::string, ObservationPtr > stats_
Statistics container.
Definition: context.h:55
context.h