]> granicus.if.org Git - icinga2/blob - lib/livestatus/countaggregator.cpp
Merge pull request #7185 from Icinga/bugfix/gelfwriter-wrong-log-facility
[icinga2] / lib / livestatus / countaggregator.cpp
1 /* Icinga 2 | (c) 2012 Icinga GmbH | GPLv2+ */
2
3 #include "livestatus/countaggregator.hpp"
4
5 using namespace icinga;
6
7 CountAggregatorState *CountAggregator::EnsureState(AggregatorState **state)
8 {
9         if (!*state)
10                 *state = new CountAggregatorState();
11
12         return static_cast<CountAggregatorState *>(*state);
13 }
14
15 void CountAggregator::Apply(const Table::Ptr& table, const Value& row, AggregatorState **state)
16 {
17         CountAggregatorState *pstate = EnsureState(state);
18
19         if (GetFilter()->Apply(table, row))
20                 pstate->Count++;
21 }
22
23 double CountAggregator::GetResultAndFreeState(AggregatorState *state) const
24 {
25         CountAggregatorState *pstate = EnsureState(&state);
26         double result = pstate->Count;
27         delete pstate;
28
29         return result;
30 }