• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  [auto_generated]
3  boost/numeric/odeint/stepper/detail/rotating_buffer.hpp
4 
5  [begin_description]
6  Implemetation of a rotating (cyclic) buffer for use in the Adam Bashforth stepper
7  [end_description]
8 
9  Copyright 2011 Karsten Ahnert
10  Copyright 2011 Mario Mulansky
11 
12  Distributed under the Boost Software License, Version 1.0.
13  (See accompanying file LICENSE_1_0.txt or
14  copy at http://www.boost.org/LICENSE_1_0.txt)
15  */
16 
17 
18 #ifndef BOOST_NUMERIC_ODEINT_STEPPER_DETAIL_ROTATING_BUFFER_HPP_INCLUDED
19 #define BOOST_NUMERIC_ODEINT_STEPPER_DETAIL_ROTATING_BUFFER_HPP_INCLUDED
20 
21 #include <boost/array.hpp>
22 
23 namespace boost {
24 namespace numeric {
25 namespace odeint {
26 namespace detail {
27 
28 template< class T , size_t N >
29 class rotating_buffer
30 {
31 public:
32 
33     typedef T value_type;
34     const static size_t dim = N;
35 
rotating_buffer(void)36     rotating_buffer( void ) : m_first( 0 )
37     { }
38 
size(void) const39     size_t size( void ) const
40     {
41         return dim;
42     }
43 
operator [](size_t i)44     value_type& operator[]( size_t i )
45     {
46         return m_data[ get_index( i ) ];
47     }
48 
operator [](size_t i) const49     const value_type& operator[]( size_t i ) const
50     {
51         return m_data[ get_index( i ) ];
52     }
53 
rotate(void)54     void rotate( void )
55     {
56         if( m_first == 0 )
57             m_first = dim-1;
58         else
59             --m_first;
60     }
61 
62 protected:
63 
64     value_type m_data[N];
65 
66 private:
67 
get_index(size_t i) const68     size_t get_index( size_t i ) const
69     {
70         return ( ( i + m_first ) % dim );
71     }
72 
73     size_t m_first;
74 
75 };
76 
77 
78 } // detail
79 } // odeint
80 } // numeric
81 } // boost
82 
83 
84 #endif // BOOST_NUMERIC_ODEINT_STEPPER_DETAIL_ROTATING_BUFFER_HPP_INCLUDED
85