Rev 1221 | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
671 | werner | 1 | /******************************************************************************************** |
2 | ** iLand - an individual based forest landscape and disturbance model |
||
3 | ** http://iland.boku.ac.at |
||
4 | ** Copyright (C) 2009- Werner Rammer, Rupert Seidl |
||
5 | ** |
||
6 | ** This program is free software: you can redistribute it and/or modify |
||
7 | ** it under the terms of the GNU General Public License as published by |
||
8 | ** the Free Software Foundation, either version 3 of the License, or |
||
9 | ** (at your option) any later version. |
||
10 | ** |
||
11 | ** This program is distributed in the hope that it will be useful, |
||
12 | ** but WITHOUT ANY WARRANTY; without even the implied warranty of |
||
13 | ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
||
14 | ** GNU General Public License for more details. |
||
15 | ** |
||
16 | ** You should have received a copy of the GNU General Public License |
||
17 | ** along with this program. If not, see <http://www.gnu.org/licenses/>. |
||
18 | ********************************************************************************************/ |
||
19 | |||
214 | werner | 20 | #ifndef FLOATINGAVERAGE_H |
21 | #define FLOATINGAVERAGE_H |
||
678 | werner | 22 | #include <QVector> |
214 | werner | 23 | /** Helper class for floating averages. |
24 | Use add(new_value) to add a value (and get the the current average). average() returns the current average |
||
25 | and sum() the total sum of stored values. Use setup() to setup place for "size" values. */ |
||
26 | class FloatingAverage |
||
27 | { |
||
28 | public: |
||
29 | FloatingAverage(); |
||
30 | FloatingAverage(int size) { setup(size); } |
||
31 | void setup(const int size, const double InitValue = 0.); |
||
32 | double add(double add_value); ///< add a value and return current average |
||
33 | |||
486 | werner | 34 | double average() const {return mCurrentAverage; } ///< retrieve current average |
214 | werner | 35 | double sum() const; ///< retrieve total sum of values. |
36 | private: |
||
37 | double mCurrentAverage; |
||
38 | QVector<double> mData; |
||
39 | int mSize; |
||
40 | int mPos; |
||
41 | bool mFilled; |
||
42 | double mInitValue; |
||
43 | |||
44 | }; |
||
45 | #endif // FLOATINGAVERAGE_H |