AFF --- A container for numbers (array) by Friederich and Forbriger.
rms.h
Go to the documentation of this file.
1 
37 // include guard
38 #ifndef AFF_RMS_H_VERSION
39 
40 #define AFF_RMS_H_VERSION \
41  "AFF_RMS_H V1.2"
42 
43 #include<cmath>
44 #include<aff/lib/collector.h>
45 
46 namespace aff {
47 
48  namespace func {
49 
50  namespace util {
51 
59  template<class C>
60  class Extractrms {
61  typedef typename C::Tcoc Tcont;
62  typedef typename C::Tvalue Tvalue;
63  public:
64  typedef Tvalue Tretval;
66  Extractrms(const Tcont& c): Msum(0), Mn(0) { }
68  void operator() (const Tvalue& v) { Msum+=(v*v); ++Mn; }
70  Tretval result() const { return(std::sqrt(Msum/Tvalue(Mn))); }
71  private:
73  int Mn;
74  }; // class Extractrms
75 
76  } // namespace util
77 
78 /*----------------------------------------------------------------------*/
79 
90  template<class C>
91  typename C::Tvalue rms(const C& c)
92  {
93  return(aff::func::util::collect<C, aff::func::util::Extractrms>(c));
94  } // rms()
95 
96  } // namespace func
97 
98 } // namespace aff
99 
100 #endif // AFF_RMS_H_VERSION (includeguard)
101 
102 /* ----- END OF rms.h ----- */
Root namespace of library.
Definition: array.h:148
collect values (prototypes)
void operator()(const Tvalue &v)
collect another value
Definition: rms.h:68
C::Tvalue rms(const C &c)
Definition: rms.h:91
Extractrms(const Tcont &c)
initialize member data
Definition: rms.h:66
Tretval result() const
return result of operation
Definition: rms.h:70