]> granicus.if.org Git - icinga2/blob - lib/livestatus/invsumaggregator.cpp
Merge branch 'support/2.10'
[icinga2] / lib / livestatus / invsumaggregator.cpp
1 /* Icinga 2 | (c) 2012 Icinga GmbH | GPLv2+ */
2
3 #include "livestatus/invsumaggregator.hpp"
4
5 using namespace icinga;
6
7 InvSumAggregator::InvSumAggregator(String attr)
8         : m_InvSumAttr(std::move(attr))
9 { }
10
11 InvSumAggregatorState *InvSumAggregator::EnsureState(AggregatorState **state)
12 {
13         if (!*state)
14                 *state = new InvSumAggregatorState();
15
16         return static_cast<InvSumAggregatorState *>(*state);
17 }
18
19 void InvSumAggregator::Apply(const Table::Ptr& table, const Value& row, AggregatorState **state)
20 {
21         Column column = table->GetColumn(m_InvSumAttr);
22
23         Value value = column.ExtractValue(row);
24
25         InvSumAggregatorState *pstate = EnsureState(state);
26
27         pstate->InvSum += (1.0 / value);
28 }
29
30 double InvSumAggregator::GetResultAndFreeState(AggregatorState *state) const
31 {
32         InvSumAggregatorState *pstate = EnsureState(&state);
33         double result = pstate->InvSum;
34         delete pstate;
35
36         return result;
37 }