BIND 10 trac2157, updated. d217636bf6a044af74de0e4231f6f3705831afbf [2157] inlining isc::statistics::Counter
BIND 10 source code commits
bind10-changes at lists.isc.org
Wed Sep 12 06:51:07 UTC 2012
The branch, trac2157 has been updated
via d217636bf6a044af74de0e4231f6f3705831afbf (commit)
via 32df493ce5ab5ed72083ae978ba5be66ec08bf3f (commit)
from 08807466356cb03b0989a05a942940a5d528de60 (commit)
Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.
- Log -----------------------------------------------------------------
commit d217636bf6a044af74de0e4231f6f3705831afbf
Author: Yoshitaka Aharen <aharen at jprs.co.jp>
Date: Mon Sep 10 15:20:12 2012 +0900
[2157] inlining isc::statistics::Counter
make isc::statistics::Counter and isc::statistics::CounterDict inline
for performance
commit 32df493ce5ab5ed72083ae978ba5be66ec08bf3f
Author: Yoshitaka Aharen <aharen at jprs.co.jp>
Date: Mon Sep 10 14:32:49 2012 +0900
[2157] inlining QRAttributes
make QRAttributes inline for performance
-----------------------------------------------------------------------
Summary of changes:
src/bin/auth/Makefile.am | 1 -
src/bin/auth/benchmarks/Makefile.am | 1 -
src/bin/auth/statistics.cc | 64 --------
src/bin/auth/statistics.h | 83 +++++++++--
src/bin/auth/tests/Makefile.am | 1 -
src/lib/statistics/Makefile.am | 6 +-
src/lib/statistics/counter.cc | 82 -----------
src/lib/statistics/counter.h | 54 +++++--
src/lib/statistics/counter_dict.cc | 265 ----------------------------------
src/lib/statistics/counter_dict.h | 202 ++++++++++++++++----------
src/lib/statistics/tests/Makefile.am | 1 -
11 files changed, 238 insertions(+), 522 deletions(-)
delete mode 100644 src/lib/statistics/counter.cc
delete mode 100644 src/lib/statistics/counter_dict.cc
-----------------------------------------------------------------------
diff --git a/src/bin/auth/Makefile.am b/src/bin/auth/Makefile.am
index 1f0fbbf..801c586 100644
--- a/src/bin/auth/Makefile.am
+++ b/src/bin/auth/Makefile.am
@@ -72,7 +72,6 @@ b10_auth_LDADD += $(top_builddir)/src/lib/asiolink/libasiolink.la
b10_auth_LDADD += $(top_builddir)/src/lib/log/liblog.la
b10_auth_LDADD += $(top_builddir)/src/lib/xfr/libxfr.la
b10_auth_LDADD += $(top_builddir)/src/lib/server_common/libserver_common.la
-b10_auth_LDADD += $(top_builddir)/src/lib/statistics/libstatistics.la
b10_auth_LDADD += $(SQLITE_LIBS)
# TODO: config.h.in is wrong because doesn't honor pkgdatadir
diff --git a/src/bin/auth/benchmarks/Makefile.am b/src/bin/auth/benchmarks/Makefile.am
index 2de01ff..463e30a 100644
--- a/src/bin/auth/benchmarks/Makefile.am
+++ b/src/bin/auth/benchmarks/Makefile.am
@@ -39,6 +39,5 @@ query_bench_LDADD += $(top_builddir)/src/lib/nsas/libnsas.la
query_bench_LDADD += $(top_builddir)/src/lib/asiolink/libasiolink.la
query_bench_LDADD += $(top_builddir)/src/lib/server_common/libserver_common.la
query_bench_LDADD += $(top_builddir)/src/lib/asiodns/libasiodns.la
-query_bench_LDADD += $(top_builddir)/src/lib/statistics/libstatistics.la
query_bench_LDADD += $(SQLITE_LIBS)
diff --git a/src/bin/auth/statistics.cc b/src/bin/auth/statistics.cc
index 7b66332..20369f0 100644
--- a/src/bin/auth/statistics.cc
+++ b/src/bin/auth/statistics.cc
@@ -395,70 +395,6 @@ Counters::registerStatisticsValidator
return (impl_->registerStatisticsValidator(validator));
}
-QRAttributes::QRAttributes() :
- req_ip_version_(0), req_transport_protocol_(0),
- req_opcode_(0),
- req_is_edns_0_(false), req_is_edns_badver_(false),
- req_is_dnssec_ok_(false),
- req_is_tsig_(false), req_is_sig0_(false), req_is_badsig_(false),
- zone_origin_(),
- answer_sent_(false),
- res_is_truncated_(false)
-{}
-
-QRAttributes::~QRAttributes()
-{}
-
-void
-QRAttributes::setQueryIPVersion(const int ip_version) {
- req_ip_version_ = ip_version;
-}
-
-void
-QRAttributes::setQueryTransportProtocol(const int transport_protocol) {
- req_transport_protocol_ = transport_protocol;
-}
-
-void
-QRAttributes::setQueryOpCode(const int opcode) {
- req_opcode_ = opcode;
-}
-
-void
-QRAttributes::setQueryEDNS(const bool is_edns_0, const bool is_edns_badver) {
- req_is_edns_0_ = is_edns_0;
- req_is_edns_badver_ = is_edns_badver;
-}
-
-void
-QRAttributes::setQueryDO(const bool is_dnssec_ok) {
- req_is_dnssec_ok_ = is_dnssec_ok;
-}
-
-void
-QRAttributes::setQuerySig(const bool is_tsig, const bool is_sig0,
- const bool is_badsig)
-{
- req_is_tsig_ = is_tsig;
- req_is_sig0_ = is_sig0;
- req_is_badsig_ = is_badsig;
-}
-
-void
-QRAttributes::setOrigin(const std::string& origin) {
- zone_origin_ = origin;
-}
-
-void
-QRAttributes::answerHasSent() {
- answer_sent_ = true;
-}
-
-void
-QRAttributes::setResponseTruncated(const bool is_truncated) {
- res_is_truncated_ = is_truncated;
-}
-
} // namespace statistics
} // namespace auth
} // namespace isc
diff --git a/src/bin/auth/statistics.h b/src/bin/auth/statistics.h
index 72b3bc0..7f5dc78 100644
--- a/src/bin/auth/statistics.h
+++ b/src/bin/auth/statistics.h
@@ -62,42 +62,101 @@ public:
/// This constructor is mostly exception free. But it may still throw
/// a standard exception if memory allocation fails inside the method.
///
- QRAttributes();
+ inline QRAttributes();
/// The destructor.
///
/// This method never throws an exception.
///
- ~QRAttributes();
+ inline ~QRAttributes();
/// \brief Set query opcode.
/// \throw None
- void setQueryOpCode(const int opcode);
+ inline void setQueryOpCode(const int opcode);
/// \brief Set IP version carrying a query.
/// \throw None
- void setQueryIPVersion(const int ip_version);
+ inline void setQueryIPVersion(const int ip_version);
/// \brief Set transport protocol carrying a query.
/// \throw None
- void setQueryTransportProtocol(const int transport_protocol);
+ inline void setQueryTransportProtocol(const int transport_protocol);
/// \brief Set query EDNS attributes.
/// \throw None
- void setQueryEDNS(const bool is_edns_0, const bool is_edns_badver);
+ inline void setQueryEDNS(const bool is_edns_0, const bool is_edns_badver);
/// \brief Set query DO bit.
/// \throw None
- void setQueryDO(const bool is_dnssec_ok);
+ inline void setQueryDO(const bool is_dnssec_ok);
/// \brief Set query TSIG attributes.
/// \throw None
- void setQuerySig(const bool is_tsig, const bool is_sig0,
- const bool is_badsig);
+ inline void setQuerySig(const bool is_tsig, const bool is_sig0,
+ const bool is_badsig);
/// \brief Set zone origin.
/// \throw None
- void setOrigin(const std::string& origin);
+ inline void setOrigin(const std::string& origin);
/// \brief Set if the answer has sent.
/// \throw None
- void answerHasSent();
+ inline void answerHasSent();
/// \brief Set if the response is truncated.
/// \throw None
- void setResponseTruncated(const bool is_truncated);
+ inline void setResponseTruncated(const bool is_truncated);
};
+inline QRAttributes::QRAttributes() :
+ req_ip_version_(0), req_transport_protocol_(0),
+ req_opcode_(0),
+ req_is_edns_0_(false), req_is_edns_badver_(false),
+ req_is_dnssec_ok_(false),
+ req_is_tsig_(false), req_is_sig0_(false), req_is_badsig_(false),
+ zone_origin_(),
+ answer_sent_(false),
+ res_is_truncated_(false)
+{}
+
+inline QRAttributes::~QRAttributes()
+{}
+
+inline void
+QRAttributes::setQueryIPVersion(const int ip_version) {
+ req_ip_version_ = ip_version;
+}
+
+inline void
+QRAttributes::setQueryTransportProtocol(const int transport_protocol) {
+ req_transport_protocol_ = transport_protocol;
+}
+
+inline void
+QRAttributes::setQueryOpCode(const int opcode) {
+ req_opcode_ = opcode;
+}
+
+inline void
+QRAttributes::setQueryEDNS(const bool is_edns_0, const bool is_edns_badver) {
+ req_is_edns_0_ = is_edns_0;
+ req_is_edns_badver_ = is_edns_badver;
+}
+
+inline void
+QRAttributes::setQueryDO(const bool is_dnssec_ok) {
+ req_is_dnssec_ok_ = is_dnssec_ok;
+}
+
+inline void
+QRAttributes::setQuerySig(const bool is_tsig, const bool is_sig0,
+ const bool is_badsig)
+{
+ req_is_tsig_ = is_tsig;
+ req_is_sig0_ = is_sig0;
+ req_is_badsig_ = is_badsig;
+}
+
+inline void
+QRAttributes::answerHasSent() {
+ answer_sent_ = true;
+}
+
+inline void
+QRAttributes::setResponseTruncated(const bool is_truncated) {
+ res_is_truncated_ = is_truncated;
+}
+
/// \brief Set of query counters.
///
/// \c Counters is set of query counters class. It holds query counters
diff --git a/src/bin/auth/tests/Makefile.am b/src/bin/auth/tests/Makefile.am
index 602c1d6..8b2a350 100644
--- a/src/bin/auth/tests/Makefile.am
+++ b/src/bin/auth/tests/Makefile.am
@@ -78,7 +78,6 @@ run_unittests_LDADD += $(top_builddir)/src/lib/log/liblog.la
run_unittests_LDADD += $(top_builddir)/src/lib/server_common/libserver_common.la
run_unittests_LDADD += $(top_builddir)/src/lib/nsas/libnsas.la
run_unittests_LDADD += $(top_builddir)/src/lib/util/unittests/libutil_unittests.la
-run_unittests_LDADD += $(top_builddir)/src/lib/statistics/libstatistics.la
run_unittests_LDADD += $(top_builddir)/src/lib/config/tests/libfake_session.la
run_unittests_LDADD += $(GTEST_LDADD)
run_unittests_LDADD += $(SQLITE_LIBS)
diff --git a/src/lib/statistics/Makefile.am b/src/lib/statistics/Makefile.am
index 6c7b910..e3543a2 100644
--- a/src/lib/statistics/Makefile.am
+++ b/src/lib/statistics/Makefile.am
@@ -1,4 +1,4 @@
-SUBDIRS = . tests
+SUBDIRS = tests
AM_CPPFLAGS = -I$(top_srcdir)/src/lib -I$(top_builddir)/src/lib
AM_CPPFLAGS += $(BOOST_INCLUDES) $(MULTITHREADING_FLAG)
@@ -17,8 +17,4 @@ if USE_CLANGPP
AM_CXXFLAGS += -Wno-unused-parameter
endif
-lib_LTLIBRARIES = libstatistics.la
-libstatistics_la_SOURCES = counter.h counter.cc
-libstatistics_la_SOURCES += counter_dict.h counter_dict.cc
-
CLEANFILES = *.gcno *.gcda
diff --git a/src/lib/statistics/counter.cc b/src/lib/statistics/counter.cc
deleted file mode 100644
index 53dc58e..0000000
--- a/src/lib/statistics/counter.cc
+++ /dev/null
@@ -1,82 +0,0 @@
-// Copyright (C) 2011 Internet Systems Consortium, Inc. ("ISC")
-//
-// Permission to use, copy, modify, and/or distribute this software for any
-// purpose with or without fee is hereby granted, provided that the above
-// copyright notice and this permission notice appear in all copies.
-//
-// THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
-// REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
-// AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
-// INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
-// LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
-// OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
-// PERFORMANCE OF THIS SOFTWARE.
-
-#include <vector>
-
-#include <boost/noncopyable.hpp>
-
-#include <statistics/counter.h>
-
-namespace {
-const unsigned int InitialValue = 0;
-} // namespace
-
-namespace isc {
-namespace statistics {
-
-class CounterImpl : boost::noncopyable {
- private:
- std::vector<Counter::Value> counters_;
- public:
- CounterImpl(const size_t nelements);
- ~CounterImpl();
- void inc(const Counter::Type&);
- const Counter::Value& get(const Counter::Type&) const;
-};
-
-CounterImpl::CounterImpl(const size_t items) :
- counters_(items, InitialValue)
-{
- if (items == 0) {
- isc_throw(isc::InvalidParameter, "Items must not be 0");
- }
-}
-
-CounterImpl::~CounterImpl() {}
-
-void
-CounterImpl::inc(const Counter::Type& type) {
- if(type >= counters_.size()) {
- isc_throw(isc::OutOfRange, "Counter type is out of range");
- }
- ++counters_.at(type);
- return;
-}
-
-const Counter::Value&
-CounterImpl::get(const Counter::Type& type) const {
- if(type >= counters_.size()) {
- isc_throw(isc::OutOfRange, "Counter type is out of range");
- }
- return (counters_.at(type));
-}
-
-Counter::Counter(const size_t items) : impl_(new CounterImpl(items))
-{}
-
-Counter::~Counter() {}
-
-void
-Counter::inc(const Type& type) {
- impl_->inc(type);
- return;
-}
-
-const Counter::Value&
-Counter::get(const Type& type) const {
- return (impl_->get(type));
-}
-
-} // namespace statistics
-} // namespace isc
diff --git a/src/lib/statistics/counter.h b/src/lib/statistics/counter.h
index 9e467ce..ed5c276 100644
--- a/src/lib/statistics/counter.h
+++ b/src/lib/statistics/counter.h
@@ -15,24 +15,29 @@
#ifndef __COUNTER_H
#define __COUNTER_H 1
+#include <exceptions/exceptions.h>
+
#include <boost/noncopyable.hpp>
#include <boost/scoped_ptr.hpp>
-#include <exceptions/exceptions.h>
+#include <vector>
+
+namespace {
+const unsigned int InitialValue = 0;
+} // anonymous namespace
namespace isc {
namespace statistics {
-// forward declaration for pImpl idiom
-class CounterImpl;
-
class Counter : boost::noncopyable {
-private:
- boost::scoped_ptr<CounterImpl> impl_;
public:
typedef unsigned int Type;
typedef unsigned int Value;
+private:
+ std::vector<Counter::Value> counters_;
+
+public:
/// The constructor.
///
/// This constructor is mostly exception free. But it may still throw
@@ -41,29 +46,56 @@ public:
/// \param items A number of counter items to hold (greater than 0)
///
/// \throw isc::InvalidParameter \a items is 0
- Counter(const size_t items);
+ explicit inline Counter(const size_t items);
/// The destructor.
///
/// This method never throws an exception.
- ~Counter();
+ inline ~Counter();
/// \brief Increment a counter item specified with \a type.
///
/// \param type %Counter item to increment
///
/// \throw isc::OutOfRange \a type is invalid
- void inc(const Type& type);
+ inline void inc(const Counter::Type);
/// \brief Get the value of a counter item specified with \a type.
///
/// \param type %Counter item to get the value of
///
/// \throw isc::OutOfRange \a type is invalid
- const Value& get(const Type& type) const;
+ inline const Counter::Value& get(const Counter::Type) const;
};
+inline Counter::Counter(const size_t items) :
+ counters_(items, InitialValue)
+{
+ if (items == 0) {
+ isc_throw(isc::InvalidParameter, "Items must not be 0");
+ }
+}
+
+inline Counter::~Counter() {}
+
+inline void
+Counter::inc(const Counter::Type type) {
+ if(type >= counters_.size()) {
+ isc_throw(isc::OutOfRange, "Counter type is out of range");
+ }
+ ++counters_.at(type);
+ return;
+}
+
+inline const Counter::Value&
+Counter::get(const Counter::Type type) const {
+ if(type >= counters_.size()) {
+ isc_throw(isc::OutOfRange, "Counter type is out of range");
+ }
+ return (counters_.at(type));
+}
+
} // namespace statistics
} // namespace isc
-#endif
+#endif // __COUNTER_H
diff --git a/src/lib/statistics/counter_dict.cc b/src/lib/statistics/counter_dict.cc
deleted file mode 100644
index 55353b2..0000000
--- a/src/lib/statistics/counter_dict.cc
+++ /dev/null
@@ -1,265 +0,0 @@
-// Copyright (C) 2011 Internet Systems Consortium, Inc. ("ISC")
-//
-// Permission to use, copy, modify, and/or distribute this software for any
-// purpose with or without fee is hereby granted, provided that the above
-// copyright notice and this permission notice appear in all copies.
-//
-// THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
-// REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
-// AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
-// INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
-// LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
-// OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
-// PERFORMANCE OF THIS SOFTWARE.
-
-#include <cassert>
-#include <stdexcept>
-#include <iterator>
-#include <map>
-#include <boost/noncopyable.hpp>
-#include <boost/shared_ptr.hpp>
-
-#include <statistics/counter_dict.h>
-
-namespace {
-typedef boost::shared_ptr<isc::statistics::Counter> CounterPtr;
-typedef std::map<std::string, CounterPtr> DictionaryMap;
-}
-
-namespace isc {
-namespace statistics {
-
-// Implementation detail class for CounterDictionary::ConstIterator
-class CounterDictionaryConstIteratorImpl;
-
-class CounterDictionaryImpl : boost::noncopyable {
-private:
- DictionaryMap dictionary_;
- std::vector<std::string> elements_;
- const size_t items_;
- // Default constructor is forbidden; number of counter items must be
- // specified at the construction of this class.
- CounterDictionaryImpl();
-public:
- CounterDictionaryImpl(const size_t items);
- ~CounterDictionaryImpl();
- void addElement(const std::string& name);
- void deleteElement(const std::string& name);
- Counter& getElement(const std::string& name);
-public:
- CounterDictionaryConstIteratorImpl begin() const;
- CounterDictionaryConstIteratorImpl end() const;
-};
-
-// Constructor with number of items
-CounterDictionaryImpl::CounterDictionaryImpl(const size_t items) :
- items_(items)
-{
- // The number of items must not be 0
- if (items == 0) {
- isc_throw(isc::InvalidParameter, "Items must not be 0");
- }
-}
-
-// Destructor
-CounterDictionaryImpl::~CounterDictionaryImpl() {}
-
-void
-CounterDictionaryImpl::addElement(const std::string& name) {
- // throw if the element already exists
- if (dictionary_.count(name) != 0) {
- isc_throw(isc::InvalidParameter,
- "Element " << name << " already exists");
- }
- assert(items_ != 0);
- // Create a new Counter and add to the map
- dictionary_.insert(
- DictionaryMap::value_type(name, CounterPtr(new Counter(items_))));
-}
-
-void
-CounterDictionaryImpl::deleteElement(const std::string& name) {
- size_t result = dictionary_.erase(name);
- if (result != 1) {
- // If an element with specified name does not exist, throw
- // isc::OutOfRange.
- isc_throw(isc::OutOfRange, "Element " << name << " does not exist");
- }
-}
-
-Counter&
-CounterDictionaryImpl::getElement(const std::string& name) {
- DictionaryMap::const_iterator i = dictionary_.find(name);
- if (i != dictionary_.end()) {
- // the key was found. return the element.
- return (*(i->second));
- } else {
- // If an element with specified name does not exist, throw
- // isc::OutOfRange.
- isc_throw(isc::OutOfRange, "Element " << name << " does not exist");
- }
-}
-
-// Constructor
-// Initialize impl_
-CounterDictionary::CounterDictionary(const size_t items) :
- impl_(new CounterDictionaryImpl(items))
-{}
-
-// Destructor
-// impl_ will be freed automatically with scoped_ptr
-CounterDictionary::~CounterDictionary() {}
-
-void
-CounterDictionary::addElement(const std::string& name) {
- impl_->addElement(name);
-}
-
-void
-CounterDictionary::deleteElement(const std::string& name) {
- impl_->deleteElement(name);
-}
-
-Counter&
-CounterDictionary::getElement(const std::string& name) const {
- return (impl_->getElement(name));
-}
-
-Counter&
-CounterDictionary::operator[](const std::string& name) const {
- return (impl_->getElement(name));
-}
-
-// Implementation detail class for CounterDictionary::ConstIterator
-class CounterDictionaryConstIteratorImpl {
- public:
- CounterDictionaryConstIteratorImpl();
- ~CounterDictionaryConstIteratorImpl();
- CounterDictionaryConstIteratorImpl(
- const CounterDictionaryConstIteratorImpl &other);
- CounterDictionaryConstIteratorImpl &operator=(
- const CounterDictionaryConstIteratorImpl &source);
- CounterDictionaryConstIteratorImpl(
- DictionaryMap::const_iterator iterator);
- public:
- void increment();
- const CounterDictionary::ConstIterator::value_type&
- dereference() const;
- bool equal(const CounterDictionaryConstIteratorImpl& other) const;
- private:
- DictionaryMap::const_iterator iterator_;
-};
-
-CounterDictionaryConstIteratorImpl::CounterDictionaryConstIteratorImpl() {}
-
-CounterDictionaryConstIteratorImpl::~CounterDictionaryConstIteratorImpl() {}
-
-// Copy constructor: deep copy of iterator_
-CounterDictionaryConstIteratorImpl::CounterDictionaryConstIteratorImpl(
- const CounterDictionaryConstIteratorImpl &other) :
- iterator_(other.iterator_)
-{}
-
-// Assignment operator: deep copy of iterator_
-CounterDictionaryConstIteratorImpl &
-CounterDictionaryConstIteratorImpl::operator=(
- const CounterDictionaryConstIteratorImpl &source)
-{
- iterator_ = source.iterator_;
- return (*this);
-}
-
-// Constructor from implementation detail DictionaryMap::const_iterator
-CounterDictionaryConstIteratorImpl::CounterDictionaryConstIteratorImpl(
- DictionaryMap::const_iterator iterator) :
- iterator_(iterator)
-{}
-
-CounterDictionaryConstIteratorImpl
-CounterDictionaryImpl::begin() const {
- return (CounterDictionaryConstIteratorImpl(dictionary_.begin()));
-}
-
-CounterDictionaryConstIteratorImpl
-CounterDictionaryImpl::end() const {
- return (CounterDictionaryConstIteratorImpl(dictionary_.end()));
-}
-
-void
-CounterDictionaryConstIteratorImpl::increment() {
- ++iterator_;
- return;
-}
-
-const CounterDictionary::ConstIterator::value_type&
-CounterDictionaryConstIteratorImpl::dereference() const {
- return (iterator_->first);
-}
-
-bool
-CounterDictionaryConstIteratorImpl::equal(
- const CounterDictionaryConstIteratorImpl& other) const
-{
- return (iterator_ == other.iterator_);
-}
-
-CounterDictionary::ConstIterator
-CounterDictionary::begin() const {
- return (CounterDictionary::ConstIterator(
- CounterDictionaryConstIteratorImpl(impl_->begin())));
-}
-
-CounterDictionary::ConstIterator
-CounterDictionary::end() const {
- return (CounterDictionary::ConstIterator(
- CounterDictionaryConstIteratorImpl(impl_->end())));
-}
-
-CounterDictionary::ConstIterator::ConstIterator() :
- impl_(new CounterDictionaryConstIteratorImpl())
-{}
-
-CounterDictionary::ConstIterator::~ConstIterator() {}
-
-// Copy constructor: deep copy of impl_
-CounterDictionary::ConstIterator::ConstIterator(
- const CounterDictionary::ConstIterator& source) :
- impl_(new CounterDictionaryConstIteratorImpl(*(source.impl_)))
-{}
-
-// Assignment operator: deep copy of impl_
-CounterDictionary::ConstIterator &
-CounterDictionary::ConstIterator::operator=(
- const CounterDictionary::ConstIterator &source)
-{
- *impl_ = *source.impl_;
- return (*this);
-}
-
-// The constructor from implementation detail
-CounterDictionary::ConstIterator::ConstIterator(
- const CounterDictionaryConstIteratorImpl& source) :
- impl_(new CounterDictionaryConstIteratorImpl(source))
-{}
-
-const CounterDictionary::ConstIterator::value_type&
-CounterDictionary::ConstIterator::dereference() const
-{
- return (impl_->dereference());
-}
-
-bool
-CounterDictionary::ConstIterator::equal(
- CounterDictionary::ConstIterator const& other) const
-{
- return (impl_->equal(*(other.impl_)));
-}
-
-void
-CounterDictionary::ConstIterator::increment() {
- impl_->increment();
- return;
-}
-
-} // namespace statistics
-} // namespace isc
diff --git a/src/lib/statistics/counter_dict.h b/src/lib/statistics/counter_dict.h
index e322119..3715fc2 100644
--- a/src/lib/statistics/counter_dict.h
+++ b/src/lib/statistics/counter_dict.h
@@ -15,67 +15,45 @@
#ifndef __COUNTER_DICT_H
#define __COUNTER_DICT_H 1
-#include <string>
-#include <vector>
-#include <utility>
+#include <statistics/counter.h>
+#include <exceptions/exceptions.h>
+
#include <boost/noncopyable.hpp>
#include <boost/scoped_ptr.hpp>
+#include <boost/shared_ptr.hpp>
#include <boost/iterator/iterator_facade.hpp>
-#include <exceptions/exceptions.h>
-#include <statistics/counter.h>
+#include <cassert>
+#include <stdexcept>
+#include <string>
+#include <vector>
+#include <map>
+#include <iterator>
+#include <utility>
+
+namespace {
+typedef boost::shared_ptr<isc::statistics::Counter> CounterPtr;
+typedef std::map<std::string, CounterPtr> DictionaryMap;
+}
namespace isc {
namespace statistics {
-class CounterDictionaryImpl;
-class CounterDictionaryConstIteratorImpl;
-
class CounterDictionary : boost::noncopyable {
private:
- boost::scoped_ptr<CounterDictionaryImpl> impl_;
+ DictionaryMap dictionary_;
+ std::vector<std::string> elements_;
+ const size_t items_;
// Default constructor is forbidden; number of counter items must be
// specified at the construction of this class.
CounterDictionary();
public:
- /// The constructor.
- /// This constructor is mostly exception free. But it may still throw
- /// a standard exception if memory allocation fails inside the method.
- ///
- /// \param items A number of counter items to hold (greater than 0)
- ///
- /// \throw isc::InvalidParameter \a items is 0
- CounterDictionary(const size_t items);
-
- /// The destructor.
- ///
- /// This method never throws an exception.
- ~CounterDictionary();
-
- /// \brief Add an element
- ///
- /// \throw isc::InvalidParameter \a element already exists.
- ///
- /// \param name A name of the element to append
- void addElement(const std::string& name);
-
- /// \brief Delete
- ///
- /// \throw isc::OutOfRange \a element does not exist.
- ///
- /// \param name A name of the element to delete
- void deleteElement(const std::string& name);
-
- /// \brief Lookup
- ///
- /// \throw isc::OutOfRange \a element does not exist.
- ///
- /// \param name A name of the element to get the counters
- Counter& getElement(const std::string &name) const;
-
- /// Same as getElement()
- Counter& operator[](const std::string &name) const;
-
+ explicit inline CounterDictionary(const size_t items);
+ inline ~CounterDictionary();
+ inline void addElement(const std::string& name);
+ inline void deleteElement(const std::string& name);
+ inline Counter& getElement(const std::string& name);
+ inline Counter& operator[](const std::string& name);
/// \brief \c ConstIterator is a constant iterator that provides an
/// interface for enumerating name of zones stored in CounterDictionary.
///
@@ -90,68 +68,134 @@ public:
const std::string,
boost::forward_traversal_tag>
{
- private:
- boost::scoped_ptr<CounterDictionaryConstIteratorImpl> impl_;
public:
/// The constructor.
///
/// This constructor is mostly exception free. But it may still
/// throw a standard exception if memory allocation fails
/// inside the method.
- ConstIterator();
+ inline ConstIterator() {}
/// The destructor.
///
/// This method never throws an exception.
- ~ConstIterator();
+ inline ~ConstIterator() {}
/// The assignment operator.
///
/// This method is mostly exception free. But it may still
/// throw a standard exception if memory allocation fails
/// inside the method.
- ConstIterator& operator=(const ConstIterator &source);
+ inline ConstIterator& operator=(const ConstIterator& source) {
+ iterator_ = source.iterator_;
+ return (*this);
+ }
+
/// The copy constructor.
///
/// This constructor is mostly exception free. But it may still
/// throw a standard exception if memory allocation fails
/// inside the method.
- ConstIterator(const ConstIterator& source);
- /// The constructor from implementation detail.
- ///
- /// This method is used to create an instance of ConstIterator
- /// by CounterDict::begin() and CounterDict::end().
- ///
- /// This constructor is mostly exception free. But it may still
- /// throw a standard exception if memory allocation fails
- /// inside the method.
- ConstIterator(
- const CounterDictionaryConstIteratorImpl& source);
+ inline ConstIterator(const ConstIterator& source) :
+ iterator_(source.iterator_)
+ {}
+ //
+ // Constructor from implementation detail DictionaryMap::const_iterator
+ inline ConstIterator(
+ DictionaryMap::const_iterator iterator) :
+ iterator_(iterator)
+ {}
+
private:
/// \brief An internal method to increment this iterator.
- void increment();
+ inline void increment() {
+ ++iterator_;
+ return;
+ }
+
/// \brief An internal method to check equality.
- bool equal(const ConstIterator& other) const;
+ inline bool equal(const ConstIterator& other) const {
+ return (iterator_ == other.iterator_);
+ }
+
/// \brief An internal method to dereference this iterator.
- const value_type& dereference() const;
+ inline const value_type& dereference() const {
+ return (iterator_->first);
+ }
+
private:
friend class boost::iterator_core_access;
+ DictionaryMap::const_iterator iterator_;
};
+ inline ConstIterator begin() const;
+ inline ConstIterator end() const;
+
typedef ConstIterator const_iterator;
+};
- /// \brief Return an iterator corresponding to the beginning of the
- /// elements stored in CounterDictionary.
- ///
- /// This method is mostly exception free. But it may still throw a
- /// standard exception if memory allocation fails inside the method.
- const_iterator begin() const;
- /// \brief Return an iterator corresponding to the end of the elements
- /// stored in CounterDictionary.
- ///
- /// This method is mostly exception free. But it may still throw a
- /// standard exception if memory allocation fails inside the method.
- const_iterator end() const;
-};
+inline CounterDictionary::ConstIterator
+CounterDictionary::begin() const {
+ return (CounterDictionary::ConstIterator(dictionary_.begin()));
+}
+
+inline CounterDictionary::ConstIterator
+CounterDictionary::end() const {
+ return (CounterDictionary::ConstIterator(dictionary_.end()));
+}
+
+// Constructor with number of items
+inline CounterDictionary::CounterDictionary(const size_t items) :
+ items_(items)
+{
+ // The number of items must not be 0
+ if (items == 0) {
+ isc_throw(isc::InvalidParameter, "Items must not be 0");
+ }
+}
+
+// Destructor
+inline CounterDictionary::~CounterDictionary() {}
+
+inline void
+CounterDictionary::addElement(const std::string& name) {
+ // throw if the element already exists
+ if (dictionary_.count(name) != 0) {
+ isc_throw(isc::InvalidParameter,
+ "Element " << name << " already exists");
+ }
+ assert(items_ != 0);
+ // Create a new Counter and add to the map
+ dictionary_.insert(
+ DictionaryMap::value_type(name, CounterPtr(new Counter(items_))));
+}
+
+inline void
+CounterDictionary::deleteElement(const std::string& name) {
+ size_t result = dictionary_.erase(name);
+ if (result != 1) {
+ // If an element with specified name does not exist, throw
+ // isc::OutOfRange.
+ isc_throw(isc::OutOfRange, "Element " << name << " does not exist");
+ }
+}
+
+inline Counter&
+CounterDictionary::getElement(const std::string& name) {
+ DictionaryMap::const_iterator i = dictionary_.find(name);
+ if (i != dictionary_.end()) {
+ // the key was found. return the element.
+ return (*(i->second));
+ } else {
+ // If an element with specified name does not exist, throw
+ // isc::OutOfRange.
+ isc_throw(isc::OutOfRange, "Element " << name << " does not exist");
+ }
+}
+
+inline Counter&
+CounterDictionary::operator[](const std::string& name) {
+ return (getElement(name));
+}
} // namespace statistics
} // namespace isc
diff --git a/src/lib/statistics/tests/Makefile.am b/src/lib/statistics/tests/Makefile.am
index c6e7cb8..09da827 100644
--- a/src/lib/statistics/tests/Makefile.am
+++ b/src/lib/statistics/tests/Makefile.am
@@ -28,7 +28,6 @@ run_unittests_SOURCES += counter_dict_unittest.cc
run_unittests_CPPFLAGS = $(AM_CPPFLAGS) $(GTEST_INCLUDES)
run_unittests_LDADD = $(GTEST_LDADD)
-run_unittests_LDADD += $(top_builddir)/src/lib/statistics/libstatistics.la
run_unittests_LDADD += $(top_builddir)/src/lib/log/liblog.la
run_unittests_LDADD += $(top_builddir)/src/lib/util/unittests/libutil_unittests.la
run_unittests_LDADD += $(top_builddir)/src/lib/exceptions/libexceptions.la
More information about the bind10-changes
mailing list