Search:

SENF Extensible Network Framework

  • Home
  • Download
  • Wiki
  • BerliOS
  • ChangeLog
  • Browse SVN
  • Bug Tracker
  • Overview
  • Examples
  • HowTos
  • Glossary
  • PPI
  • Packets
  • Scheduler
  • Socket
  • Utils
  • Console
  • Daemon
  • Logger
  • Termlib
  • Main Page
  • Related Pages
  • Modules
  • Namespaces
  • Classes
  • Files
  • File List
  • File Members

StatisticAccumulator.hh

Go to the documentation of this file.
00001 // $Id: StatisticAccumulator.hh 1788 2011-05-16 15:00:22Z mtk $
00002 //
00003 // Copyright (C) 2010
00004 // Fraunhofer (FOKUS)
00005 // Competence Center NETwork research (NET), St. Augustin, GERMANY
00006 //     Thorsten Horstmann <thorsten.horstmann@fit.fraunhofer.de>
00007 //
00008 // This program is free software; you can redistribute it and/or modify
00009 // it under the terms of the GNU General Public License as published by
00010 // the Free Software Foundation; either version 2 of the License, or
00011 // (at your option) any later version.
00012 //
00013 // This program is distributed in the hope that it will be useful,
00014 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00015 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00016 // GNU General Public License for more details.
00017 //
00018 // You should have received a copy of the GNU General Public License
00019 // along with this program; if not, write to the
00020 // Free Software Foundation, Inc.,
00021 // 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
00022 
00026 #ifndef HH_SENF_Utils_StatisticAccumulator_
00027 #define HH_SENF_Utils_StatisticAccumulator_ 1
00028 
00029 // Custom includes
00030 #include <math.h>
00031 #include <boost/cstdint.hpp>
00033 namespace senf {
00034 
00035      struct StatisticsData
00036      {
00037          StatisticsData( float min_, float avg_, float max_, float stddev_, boost::uint32_t count_)
00038              : min(min_), avg(avg_), max(max_), stddev(stddev_), count(count_){
00039          };
00040          StatisticsData( StatisticsData const & other)
00041              : min(other.min), avg(other.avg), max(other.max), stddev(other.stddev), count(other.count){
00042          };
00043          StatisticsData()
00044              : min(0.0), avg(0.0), max(0.0), stddev(0.0), count(0){
00045          };
00046 
00047          float min;
00048          float avg;
00049          float max;
00050          float stddev;
00051          boost::uint32_t count;
00052      };
00053 
00068     template <class T>
00069     class StatisticAccumulator
00070     {
00071     public:
00072         StatisticAccumulator();
00073 //        virtual ~StatisticAccumulator();
00074 
00075         void clear();
00077 
00078         void accumulate(T value);
00080 
00082         void setLastAvg(T value);
00084 
00087     public:
00088         T     min() const;
00090 
00091         T     max() const;
00093 
00094         float avg() const;
00096 
00097         float last_avg() const;
00099 
00100         float stddev() const;
00102 
00103         boost::uint32_t count() const;
00105 
00106         void data( StatisticsData & data_) const;
00108 
00110     private:
00111         T sum_squared_;
00112         T sum_;
00113         T min_;
00114         T max_;
00115         float last_avg_;
00116         boost::uint32_t count_;
00117 
00118 
00119     };
00120 
00121 
00122     typedef StatisticAccumulator<int> StatisticAccumulatorInt;
00123     typedef StatisticAccumulator<float> StatisticAccumulatorFloat;
00124 
00125 }
00127 //#include "StatisticAccumulator.cci"
00128 #include "StatisticAccumulator.ct"
00129 #include "StatisticAccumulator.cti"
00130 #endif
00131 

Contact: senf-dev@lists.berlios.de | © 2006-2010 Fraunhofer Institute for Open Communication Systems, Network Research