Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:28:20

0001 ///////////////////////////////////////////////////////////////////////////////
0002 // rolling_sum.hpp
0003 //
0004 // Copyright 2008 Eric Niebler. Distributed under the Boost
0005 // Software License, Version 1.0. (See accompanying file
0006 // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
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     // rolling_sum_impl
0026     //    returns the sum of the samples in the rolling window
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 & /*args*/) const
0050         {
0051             return this->sum_;
0052         }
0053 
0054         // make this accumulator serializeable
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 } // namespace impl
0065 
0066 ///////////////////////////////////////////////////////////////////////////////
0067 // tag::rolling_sum
0068 //
0069 namespace tag
0070 {
0071     struct rolling_sum
0072       : depends_on< rolling_window_plus1 >
0073     {
0074         /// INTERNAL ONLY
0075         ///
0076         typedef accumulators::impl::rolling_sum_impl< mpl::_1 > impl;
0077 
0078         #ifdef BOOST_ACCUMULATORS_DOXYGEN_INVOKED
0079         /// tag::rolling_window::window_size named parameter
0080         static boost::parameter::keyword<tag::rolling_window_size> const window_size;
0081         #endif
0082     };
0083 } // namespace tag
0084 
0085 ///////////////////////////////////////////////////////////////////////////////
0086 // extract::rolling_sum
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 }} // namespace boost::accumulators
0097 
0098 #endif