Arduino Libraries
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros
mean_module.hpp
Go to the documentation of this file.
1 // Author: Mario S. Könz <mskoenz@gmx.net>
2 // Date: 20.07.2013 11:27:01 EDT
3 // File: mean_module.hpp
4 
5 /* This program is free software. It comes without any warranty, to
6  * the extent permitted by applicable law. You can redistribute it
7  * and/or modify it under the terms of the Do What The Fuck You Want
8  * To Public License, Version 2, as published by Sam Hocevar. See
9  * http://www.wtfpl.net/ or COPYING for more details. */
10 
11 #ifndef __MEAN_MODULE_HEADER
12 #define __MEAN_MODULE_HEADER
13 
14 #include "module.hpp"
15 #include "../../util/mean_trait.hpp"
16 
17 namespace ustd {
18  namespace detail {
19  template<>
20  struct requirement<tag::mean> {
21  typedef typename util::make_list<tag::count>::type type;
22  };
23  }//end namespace detail
24 
25  template<typename T, typename _base>
26  class module<T, tag::mean, _base>: public _base {
27  typedef _base base;
28  typedef typename util::mean_trait<T>::type mean_type;
29  public:
30  //------------------- ctor -------------------
31  module(): base(), sum_() {
32  }
33  //------------------- ops -------------------
34  void operator<<(T const & in) {
35  base::operator<<(in);
36  sum_ += in;
37  }
38  //------------------- fct -------------------
39  mean_type mean() const {
40  return sum_ / base::count();
41  }
42  void clear() {
43  base::clear();
44  sum_ = mean_type();
45  }
46  private:
47  mean_type sum_;
48  };
49 }//end namespace ustd
50 
51 #endif //__MEAN_MODULE_HEADER
S & operator<<(S &os, oss_class< D, max_buf > const &arg)
Definition: serializer.hpp:158
Definition: module.hpp:33
void clear()
Definition: mean_module.hpp:42
ustd::conditional< detail::use_double_identifier< T >::value, double, T >::type type
Definition: mean_trait.hpp:44
Definition: meta_list.hpp:17
void operator<<(T const &in)
Definition: mean_module.hpp:34
module()
Definition: mean_module.hpp:31
mean_type mean() const
Definition: mean_module.hpp:39