rolling_sum.h
Go to the documentation of this file.
1 #ifndef ROLLING_SUM_H
2 #define ROLLING_SUM_H
3 
4 #include <boost/circular_buffer.hpp>
5 
6 // Boost.Accumulators' rolling_sum is in 1.38 :(
7 template <typename T>
8 class RollingSum
9 {
10 public:
11  RollingSum(size_t capacity)
12  : buffer_(capacity), sum_(0)
13  {
14  buffer_.push_back(0);
15  }
16 
17  void add(T sample)
18  {
19  sum_ += sample;
20  sum_ -= buffer_[0];
21  buffer_.push_back(sample);
22  }
23 
24  T sum()
25  {
26  return sum_;
27  }
28 
29 private:
30  boost::circular_buffer<T> buffer_;
31  T sum_;
32 };
33 
34 #endif
void add(T sample)
Definition: rolling_sum.h:17
RollingSum(size_t capacity)
Definition: rolling_sum.h:11
boost::circular_buffer< T > buffer_
Definition: rolling_sum.h:30


prosilica_camera
Author(s): Maintained by William Woodall - wwoodall@willowgarage.com, Contributions by Allison Thackston - allison.thackston@nasa.gov
autogenerated on Mon Jun 10 2019 14:20:19