File indexing completed on 2025-01-18 09:28:20
0001
0002
0003
0004
0005
0006
0007
0008 #ifndef BOOST_ACCUMULATORS_STATISTICS_ROLLING_SUM_HPP_EAN_26_12_2008
0009 #define BOOST_ACCUMULATORS_STATISTICS_ROLLING_SUM_HPP_EAN_26_12_2008
0010
0011 #include <boost/mpl/placeholders.hpp>
0012 #include <boost/accumulators/framework/accumulator_base.hpp>
0013 #include <boost/accumulators/framework/extractor.hpp>
0014 #include <boost/accumulators/numeric/functional.hpp>
0015 #include <boost/accumulators/framework/parameters/sample.hpp>
0016 #include <boost/accumulators/framework/depends_on.hpp>
0017 #include <boost/accumulators/statistics_fwd.hpp>
0018 #include <boost/accumulators/statistics/rolling_window.hpp>
0019
0020 namespace boost { namespace accumulators
0021 {
0022 namespace impl
0023 {
0024
0025
0026
0027 template<typename Sample>
0028 struct rolling_sum_impl
0029 : accumulator_base
0030 {
0031 typedef Sample result_type;
0032
0033 template<typename Args>
0034 rolling_sum_impl(Args const &args)
0035 : sum_(args[sample | Sample()])
0036 {}
0037
0038 template<typename Args>
0039 void operator ()(Args const &args)
0040 {
0041 if(is_rolling_window_plus1_full(args))
0042 {
0043 this->sum_ -= rolling_window_plus1(args).front();
0044 }
0045 this->sum_ += args[sample];
0046 }
0047
0048 template<typename Args>
0049 result_type result(Args const & ) const
0050 {
0051 return this->sum_;
0052 }
0053
0054
0055 template<class Archive>
0056 void serialize(Archive & ar, const unsigned int file_version)
0057 {
0058 ar & sum_;
0059 }
0060
0061 private:
0062 Sample sum_;
0063 };
0064 }
0065
0066
0067
0068
0069 namespace tag
0070 {
0071 struct rolling_sum
0072 : depends_on< rolling_window_plus1 >
0073 {
0074
0075
0076 typedef accumulators::impl::rolling_sum_impl< mpl::_1 > impl;
0077
0078 #ifdef BOOST_ACCUMULATORS_DOXYGEN_INVOKED
0079
0080 static boost::parameter::keyword<tag::rolling_window_size> const window_size;
0081 #endif
0082 };
0083 }
0084
0085
0086
0087
0088 namespace extract
0089 {
0090 extractor<tag::rolling_sum> const rolling_sum = {};
0091
0092 BOOST_ACCUMULATORS_IGNORE_GLOBAL(rolling_sum)
0093 }
0094
0095 using extract::rolling_sum;
0096 }}
0097
0098 #endif