// $Id$ // // Copyright (C) 2010 // Fraunhofer Institute for Open Communication Systems (FOKUS) // Competence Center NETwork research (NET), St. Augustin, GERMANY // Thorsten Horstmann // // This program is free software; you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by // the Free Software Foundation; either version 2 of the License, or // (at your option) any later version. // // This program is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. // // You should have received a copy of the GNU General Public License // along with this program; if not, write to the // Free Software Foundation, Inc., // 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. /** \file \brief StatisticAccumulator non-inline template implementation */ // Custom includes #define prefix_ ///////////////////////////////ct.p//////////////////////////////////////// /////////////////////////////////////////////////////////////////////////// // senf::StatisticAccumulator template prefix_ senf::StatisticAccumulator::StatisticAccumulator( ) : sum_squared_(0), sum_(0), min_(0), max_(0), last_avg_(0), count_(0) { } //template //prefix_ senf::StatisticAccumulator::~StatisticAccumulator() //{ } template prefix_ float senf::StatisticAccumulator::stddev() const { if (count_ == 0) { return NAN; } else if (count_ == 1) { return 0.0; } float _avg (avg()); return sqrt( ( float(sum_squared_) / float( count_) ) - (_avg * _avg) ); } template prefix_ void senf::StatisticAccumulator::setLastAvg( T value) { last_avg_ = value; } template prefix_ void senf::StatisticAccumulator::accumulate( T value) { if (count_ == 0) { min_ = max_ = sum_ = value; sum_squared_ = value * value; count_++; return; } sum_ += value; sum_squared_ += value * value; count_++; if (value < min_) min_ = value; else if (value > max_) max_ = value; } template prefix_ void senf::StatisticAccumulator::clear() { if( count_ > 0){ last_avg_ = avg(); count_ = 0; sum_squared_ = 0; sum_ = min_ = max_ = 0; } } template prefix_ void senf::StatisticAccumulator::data( StatisticsData &data_) const { if( count_ == 0){ data_.min = data_.avg = data_.max = last_avg_; data_.stddev = 0.0; data_.count = 0; } else{ data_.min = (float) min_; data_.avg = avg(); data_.max = (float) max_; data_.stddev = stddev(); data_.count = count_; } } ///////////////////////////////ct.e//////////////////////////////////////// #undef prefix_