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
12namespace isc {
13namespace stats {
14
15ObservationPtr 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
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
35bool 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};
Exception indicating that a given statistic is duplicated.
Definition: context.h:18
#define isc_throw(type, stream)
A shortcut macro to insert known values into exception arguments.
boost::shared_ptr< Observation > ObservationPtr
Observation pointer.
Definition: observation.h:261
Defines the logger used by the top-level component of kea-dhcp-ddns.
bool del(const std::string &name)
Attempts to delete an observation.
Definition: context.cc:35
void add(const ObservationPtr &obs)
Adds a new observation.
Definition: context.cc:24
std::map< std::string, ObservationPtr > stats_
Statistics container.
Definition: context.h:55
ObservationPtr get(const std::string &name) const
attempts to get an observation
Definition: context.cc:15