User Manual, Developers Guide and API Documentation

TimeWeightedAverage.hpp

Go to the documentation of this file.
00001 /*******************************************************************************
00002  * This file is part of openWNS (open Wireless Network Simulator)
00003  * _____________________________________________________________________________
00004  *
00005  * Copyright (C) 2004-2007
00006  * Chair of Communication Networks (ComNets)
00007  * Kopernikusstr. 5, D-52074 Aachen, Germany
00008  * phone: ++49-241-80-27910,
00009  * fax: ++49-241-80-22242
00010  * email: info@openwns.org
00011  * www: http://www.openwns.org
00012  * _____________________________________________________________________________
00013  *
00014  * openWNS is free software; you can redistribute it and/or modify it under the
00015  * terms of the GNU Lesser General Public License version 2 as published by the
00016  * Free Software Foundation;
00017  *
00018  * openWNS is distributed in the hope that it will be useful, but WITHOUT ANY
00019  * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
00020  * A PARTICULAR PURPOSE.  See the GNU Lesser General Public License for more
00021  * details.
00022  *
00023  * You should have received a copy of the GNU Lesser General Public License
00024  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
00025  *
00026  ******************************************************************************/
00027 
00028 #ifndef WNS_TIMEWEIGHTEDAVERAGE_HPP
00029 #define WNS_TIMEWEIGHTEDAVERAGE_HPP
00030 
00031 #include <WNS/Exception.hpp>
00032 #include <WNS/WeightedAverage.hpp>
00033 
00034 namespace wns {
00039     template <typename T,
00040           typename Clock>
00041     class TimeWeightedAverage
00042         : public WeightedAverage<T>
00043     {
00044     public:
00048         TimeWeightedAverage()
00049             : WeightedAverage<T>(),
00050               lastTime(0.0),
00051               c(NULL)
00052         {};
00053 
00057         TimeWeightedAverage(Clock* _c)
00058             : WeightedAverage<T>(),
00059               lastTime(0.0),
00060               c(_c)
00061         {};
00062 
00067         void setClock(Clock* _c)
00068         {
00069             c=_c;
00070         }
00071 
00075         virtual void reset()
00076         {
00077             assert(c);
00078             lastTime = c->getTime();
00079             WeightedAverage<T>::reset();
00080         };
00081 
00085         virtual void put(const T&, double)
00086         {
00087             throw(Exception("This method should not be used!"));
00088         }
00089 
00093         virtual void put(const T& t)
00094         {
00095             assert(c);
00096             double newTime = c->getTime();
00097             double weight = newTime - lastTime;
00098             WeightedAverage<T>::put(t, weight);
00099             lastTime = newTime;
00100         };
00101 
00102     private:
00106         double lastTime;
00107 
00111         Clock* c;
00112     };
00113 }
00114 
00115 #endif // WNS_TIMEWEIGHTEDAVERAGE_HPP
00116 
00117 

Generated on Sat May 26 03:31:53 2012 for openWNS by  doxygen 1.5.5