rotating_buffer.hpp 1.5 KB

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