/Src/Dependencies/Boost/boost/accumulators/statistics/rolling_sum.hpp

http://hadesmem.googlecode.com/ · C++ Header · 93 lines · 60 code · 15 blank · 18 comment · 1 complexity · 6f7e62751623776f6ec00440b76014b4 MD5 · raw file

  1. ///////////////////////////////////////////////////////////////////////////////
  2. // rolling_sum.hpp
  3. //
  4. // Copyright 2008 Eric Niebler. Distributed under the Boost
  5. // Software License, Version 1.0. (See accompanying file
  6. // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
  7. #ifndef BOOST_ACCUMULATORS_STATISTICS_ROLLING_SUM_HPP_EAN_26_12_2008
  8. #define BOOST_ACCUMULATORS_STATISTICS_ROLLING_SUM_HPP_EAN_26_12_2008
  9. #include <boost/mpl/placeholders.hpp>
  10. #include <boost/accumulators/framework/accumulator_base.hpp>
  11. #include <boost/accumulators/framework/extractor.hpp>
  12. #include <boost/accumulators/numeric/functional.hpp>
  13. #include <boost/accumulators/framework/parameters/sample.hpp>
  14. #include <boost/accumulators/framework/depends_on.hpp>
  15. #include <boost/accumulators/statistics_fwd.hpp>
  16. #include <boost/accumulators/statistics/rolling_window.hpp>
  17. namespace boost { namespace accumulators
  18. {
  19. namespace impl
  20. {
  21. ///////////////////////////////////////////////////////////////////////////////
  22. // rolling_sum_impl
  23. // returns the sum of the samples in the rolling window
  24. template<typename Sample>
  25. struct rolling_sum_impl
  26. : accumulator_base
  27. {
  28. typedef Sample result_type;
  29. template<typename Args>
  30. rolling_sum_impl(Args const &args)
  31. : sum_(args[sample | Sample()])
  32. {}
  33. template<typename Args>
  34. void operator ()(Args const &args)
  35. {
  36. if(is_rolling_window_plus1_full(args))
  37. {
  38. this->sum_ -= rolling_window_plus1(args).front();
  39. }
  40. this->sum_ += args[sample];
  41. }
  42. template<typename Args>
  43. result_type result(Args const &args) const
  44. {
  45. return this->sum_;
  46. }
  47. private:
  48. Sample sum_;
  49. };
  50. } // namespace impl
  51. ///////////////////////////////////////////////////////////////////////////////
  52. // tag::rolling_sum
  53. //
  54. namespace tag
  55. {
  56. struct rolling_sum
  57. : depends_on< rolling_window_plus1 >
  58. {
  59. /// INTERNAL ONLY
  60. ///
  61. typedef accumulators::impl::rolling_sum_impl< mpl::_1 > impl;
  62. #ifdef BOOST_ACCUMULATORS_DOXYGEN_INVOKED
  63. /// tag::rolling_window::window_size named parameter
  64. static boost::parameter::keyword<tag::rolling_window_size> const window_size;
  65. #endif
  66. };
  67. } // namespace tag
  68. ///////////////////////////////////////////////////////////////////////////////
  69. // extract::rolling_sum
  70. //
  71. namespace extract
  72. {
  73. extractor<tag::rolling_sum> const rolling_sum = {};
  74. BOOST_ACCUMULATORS_IGNORE_GLOBAL(rolling_sum)
  75. }
  76. using extract::rolling_sum;
  77. }} // namespace boost::accumulators
  78. #endif