Allolib  1.0
C++ Components For Interactive Multimedia
al_Analysis.hpp
1 #ifndef INCLUDE_AL_MATH_ANALYSIS_HPP
2 #define INCLUDE_AL_MATH_ANALYSIS_HPP
3 
4 /*
5  * AlloSphere Research Group / Media Arts & Technology, UCSB, 2009
6  */
7 
8 /*
9  Copyright (C) 2006-2008. The Regents of the University of California
10  (REGENTS). All Rights Reserved.
11 
12  Permission to use, copy, modify, distribute, and distribute modified versions
13  of this software and its documentation without fee and without a signed
14  licensing agreement, is hereby granted, provided that the above copyright
15  notice, the list of contributors, this paragraph and the following two
16  paragraphs appear in all copies, modifications, and distributions.
17 
18  IN NO EVENT SHALL REGENTS BE LIABLE TO ANY PARTY FOR DIRECT, INDIRECT,
19  SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, INCLUDING LOST PROFITS, ARISING
20  OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF REGENTS HAS
21  BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
22 
23  REGENTS SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
24  THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
25  PURPOSE. THE SOFTWARE AND ACCOMPANYING DOCUMENTATION, IF ANY, PROVIDED
26  HEREUNDER IS PROVIDED "AS IS". REGENTS HAS NO OBLIGATION TO PROVIDE
27  MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
28 
29  File description:
30  Math analysis utilities
31 
32  File author(s):
33  Graham Wakefield, 2010, grrrwaaa@gmail.com
34 */
35 
36 #include "al/math/al_Functions.hpp"
37 
38 #include <limits>
39 
40 namespace al {
41 
43 
47 template <typename T = double>
48 class MinMeanMax {
49  public:
50  MinMeanMax() { clear(); }
51 
52  void clear() {
53  minimum = std::numeric_limits<T>::infinity();
54  maximum = -std::numeric_limits<T>::infinity();
55  sum = T(0);
56  count = 0;
57  }
58 
59  // add another analysis point:
60  void operator()(T val) {
61  minimum = al::min(val, minimum);
62  maximum = al::max(val, maximum);
63  sum += val;
64  count++;
65  }
66 
67  // read analyses:
68  T min() const { return minimum; }
69  T max() const { return maximum; }
70  T mean() const { return sum / count; }
71 
72  protected:
73  T minimum, maximum, sum;
74  unsigned count;
75 };
76 
77 } // namespace al
78 #endif
T min(const T &v1, const T &v2, const T &v3)
T max(const T &v1, const T &v2, const T &v3)
Definition: al_App.hpp:23