PageRenderTime 28ms CodeModel.GetById 14ms app.highlight 7ms RepoModel.GetById 5ms app.codeStats 0ms

/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
 8#ifndef BOOST_ACCUMULATORS_STATISTICS_ROLLING_SUM_HPP_EAN_26_12_2008
 9#define BOOST_ACCUMULATORS_STATISTICS_ROLLING_SUM_HPP_EAN_26_12_2008
10
11#include <boost/mpl/placeholders.hpp>
12#include <boost/accumulators/framework/accumulator_base.hpp>
13#include <boost/accumulators/framework/extractor.hpp>
14#include <boost/accumulators/numeric/functional.hpp>
15#include <boost/accumulators/framework/parameters/sample.hpp>
16#include <boost/accumulators/framework/depends_on.hpp>
17#include <boost/accumulators/statistics_fwd.hpp>
18#include <boost/accumulators/statistics/rolling_window.hpp>
19
20namespace boost { namespace accumulators
21{
22
23namespace impl
24{
25    ///////////////////////////////////////////////////////////////////////////////
26    // rolling_sum_impl
27    //    returns the sum of the samples in the rolling window
28    template<typename Sample>
29    struct rolling_sum_impl
30      : accumulator_base
31    {
32        typedef Sample result_type;
33
34        template<typename Args>
35        rolling_sum_impl(Args const &args)
36          : sum_(args[sample | Sample()])
37        {}
38
39        template<typename Args>
40        void operator ()(Args const &args)
41        {
42            if(is_rolling_window_plus1_full(args))
43            {
44                this->sum_ -= rolling_window_plus1(args).front();
45            }
46            this->sum_ += args[sample];
47        }
48
49        template<typename Args>
50        result_type result(Args const &args) const
51        {
52            return this->sum_;
53        }
54
55    private:
56        Sample sum_;
57    };
58} // namespace impl
59
60///////////////////////////////////////////////////////////////////////////////
61// tag::rolling_sum
62//
63namespace tag
64{
65    struct rolling_sum
66      : depends_on< rolling_window_plus1 >
67    {
68        /// INTERNAL ONLY
69        ///
70        typedef accumulators::impl::rolling_sum_impl< mpl::_1 > impl;
71
72        #ifdef BOOST_ACCUMULATORS_DOXYGEN_INVOKED
73        /// tag::rolling_window::window_size named parameter
74        static boost::parameter::keyword<tag::rolling_window_size> const window_size;
75        #endif
76    };
77} // namespace tag
78
79///////////////////////////////////////////////////////////////////////////////
80// extract::rolling_sum
81//
82namespace extract
83{
84    extractor<tag::rolling_sum> const rolling_sum = {};
85
86    BOOST_ACCUMULATORS_IGNORE_GLOBAL(rolling_sum)
87}
88
89using extract::rolling_sum;
90
91}} // namespace boost::accumulators
92
93#endif