summaryrefslogtreecommitdiffstats
path: root/lib/livestatus/countaggregator.cpp
blob: b8a7238f342b22eaa22b3c2137d4c54b3413d1ab (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
/* Icinga 2 | (c) 2012 Icinga GmbH | GPLv2+ */

#include "livestatus/countaggregator.hpp"

using namespace icinga;

CountAggregatorState *CountAggregator::EnsureState(AggregatorState **state)
{
	if (!*state)
		*state = new CountAggregatorState();

	return static_cast<CountAggregatorState *>(*state);
}

void CountAggregator::Apply(const Table::Ptr& table, const Value& row, AggregatorState **state)
{
	CountAggregatorState *pstate = EnsureState(state);

	if (GetFilter()->Apply(table, row))
		pstate->Count++;
}

double CountAggregator::GetResultAndFreeState(AggregatorState *state) const
{
	CountAggregatorState *pstate = EnsureState(&state);
	double result = pstate->Count;
	delete pstate;

	return result;
}