6c08c41097deae6bf0986ba495274bd8084cca7d
[senf.git] / senf / Utils / StatisticAccumulator.hh
1 // $Id$
2 //
3 // Copyright (C) 2010
4 // Fraunhofer Institute for Open Communication Systems (FOKUS)
5 // Competence Center NETwork research (NET), St. Augustin, GERMANY
6 //     Thorsten Horstmann <thorsten.horstmann@fokus.fraunhofer.de>
7 //
8 // This program is free software; you can redistribute it and/or modify
9 // it under the terms of the GNU General Public License as published by
10 // the Free Software Foundation; either version 2 of the License, or
11 // (at your option) any later version.
12 //
13 // This program is distributed in the hope that it will be useful,
14 // but WITHOUT ANY WARRANTY; without even the implied warranty of
15 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16 // GNU General Public License for more details.
17 //
18 // You should have received a copy of the GNU General Public License
19 // along with this program; if not, write to the
20 // Free Software Foundation, Inc.,
21 // 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
22
23 /** \file
24     \brief StatisticAccumulator public header */
25
26 #ifndef HH_SENF_Utils_StatisticAccumulator_
27 #define HH_SENF_Utils_StatisticAccumulator_ 1
28
29 // Custom includes
30 #include <math.h>
31 #include <boost/cstdint.hpp>
32 ///////////////////////////////hh.p////////////////////////////////////////
33 namespace senf {
34     /** \brief Accumulate measurement values
35
36         The accumulator mainly do the prelimenary work for the senf::Statistic class.
37         It accumulates certain values with in an interval to be used by senf::Statistics
38
39         \li the senf::Statistics class
40         \li statistics sources
41
42         This class provides the average, standard deviation, min, max values over one
43         interval, means until clear() is called. It rather directly calculates the results
44         then collection all single values provided by calling accumulate().
45         \see senf::Statistics to process accumulated values
46         \ingroup senf_statistics
47         */
48
49     template <class T>
50     class StatisticAccumulator
51     {
52     public:
53         StatisticAccumulator( T defaultvalue = 0);
54 //        virtual ~StatisticAccumulator();
55
56         void clear();
57         ///< Reset accumulated values.
58         /**< This member reset all avg/min/max values to the given \a
59              defaultvalue and the count to zero. */
60         void accumulate(T value);
61         ///< Gather value to be accumulated.
62         /**< This method accumulate a value.
63              \param[in] value to be accumulated value*/
64
65     public:
66         T     min() const;
67         ///< Returns current minimal value.
68         /**< This method returns the minimal value of the current accumulation.*/
69         T     max() const;
70         ///< Returns current maximal value.
71         /**< This method returns the maximal value of the current accumulation.*/
72         float avg() const;
73         ///< Returns average value.
74         /**< This method returns the average value of the current accumulation.*/
75         float last_avg() const;
76         ///< Returns former average value.
77         /**< This method returns the average value of the former accumulation period.*/
78         float stddev() const;
79         ///< Returns standard deviation value.
80         /**< This method returns the standard deviation value of the current accumulation.*/
81         boost::uint32_t count() const;
82         ///< Returns count of accumulated values.
83         /**< This method returns count of accumulated values of the current accumulation.*/
84
85     private:
86         T defaultvalue_;
87         T sum_squared_;
88         T sum_;
89         T min_;
90         T max_;
91         float last_avg_;
92         boost::uint32_t count_;
93
94
95     };
96
97
98     typedef StatisticAccumulator<int> StatisticAccumulatorInt;
99     typedef StatisticAccumulator<float> StatisticAccumulatorFloat;
100
101
102 }
103 ///////////////////////////////hh.e////////////////////////////////////////
104 //#include "StatisticAccumulator.cci"
105 #include "StatisticAccumulator.ct"
106 #include "StatisticAccumulator.cti"
107 #endif
108