// $Id$ // // Copyright (C) 2010 // Fraunhofer Institute for Open Communication Systems (FOKUS) // // The contents of this file are subject to the Fraunhofer FOKUS Public License // Version 1.0 (the "License"); you may not use this file except in compliance // with the License. You may obtain a copy of the License at // http://senf.berlios.de/license.html // // The Fraunhofer FOKUS Public License Version 1.0 is based on, // but modifies the Mozilla Public License Version 1.1. // See the full license text for the amendments. // // Software distributed under the License is distributed on an "AS IS" basis, // WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License // for the specific language governing rights and limitations under the License. // // The Original Code is Fraunhofer FOKUS code. // // The Initial Developer of the Original Code is Fraunhofer-Gesellschaft e.V. // (registered association), Hansastraße 27 c, 80686 Munich, Germany. // All Rights Reserved. // // Contributor(s): // Mathias Kretschmer // Jens Moedeker /** \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_ 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_