Branch data Line data Source code
1 : : #include <vector>
2 : :
3 : : #include <boost/noncopyable.hpp>
4 : :
5 : : #include <statistics/counter.h>
6 : :
7 : : namespace {
8 : : const unsigned int InitialValue = 0;
9 : : } // namespace
10 : :
11 : : namespace isc {
12 : : namespace statistics {
13 : :
14 : : class CounterImpl : boost::noncopyable {
15 : : private:
16 : : std::vector<Counter::Value> counters_;
17 : : public:
18 : : CounterImpl(const size_t nelements);
19 : : ~CounterImpl();
20 : : void inc(const Counter::Type&);
21 : : const Counter::Value& get(const Counter::Type&) const;
22 : : };
23 : :
24 : 448 : CounterImpl::CounterImpl(const size_t items) :
25 : 449 : counters_(items, InitialValue)
26 : : {
27 [ + + ]: 448 : if (items == 0) {
28 [ + - ][ + - ]: 2 : isc_throw(isc::InvalidParameter, "Items must not be 0");
29 : : }
30 : 447 : }
31 : :
32 : 447 : CounterImpl::~CounterImpl() {}
33 : :
34 : : void
35 : 620 : CounterImpl::inc(const Counter::Type& type) {
36 [ + + ]: 620 : if(type >= counters_.size()) {
37 [ + - ]: 6 : isc_throw(isc::OutOfRange, "Counter type is out of range");
38 : : }
39 : 1234 : ++counters_.at(type);
40 : 617 : return;
41 : : }
42 : :
43 : : const Counter::Value&
44 : 785 : CounterImpl::get(const Counter::Type& type) const {
45 [ + + ]: 785 : if(type >= counters_.size()) {
46 [ + - ]: 2 : isc_throw(isc::OutOfRange, "Counter type is out of range");
47 : : }
48 : 784 : return (counters_.at(type));
49 : : }
50 : :
51 [ + + ]: 448 : Counter::Counter(const size_t items) : impl_(new CounterImpl(items))
52 : 447 : {}
53 : :
54 : 447 : Counter::~Counter() {}
55 : :
56 : : void
57 : 620 : Counter::inc(const Type& type) {
58 : 620 : impl_->inc(type);
59 : 617 : return;
60 : : }
61 : :
62 : : const Counter::Value&
63 : 785 : Counter::get(const Type& type) const {
64 : 785 : return (impl_->get(type));
65 : : }
66 : :
67 : : } // namespace statistics
68 : 5551 : } // namespace isc
|