ode_iterator_base.hpp 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199
  1. /*
  2. [auto_generated]
  3. boost/numeric/odeint/iterator/detail/ode_iterator_base.hpp
  4. [begin_description]
  5. Base class for const_step_iterator and adaptive_iterator.
  6. [end_description]
  7. Copyright 2012-2013 Karsten Ahnert
  8. Copyright 2012-2013 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_ITERATOR_DETAIL_ODE_ITERATOR_BASE_HPP_INCLUDED
  14. #define BOOST_NUMERIC_ODEINT_ITERATOR_DETAIL_ODE_ITERATOR_BASE_HPP_INCLUDED
  15. #include <boost/iterator/iterator_facade.hpp>
  16. #include <boost/numeric/odeint/util/unwrap_reference.hpp>
  17. #include <boost/numeric/odeint/util/detail/less_with_sign.hpp>
  18. namespace boost {
  19. namespace numeric {
  20. namespace odeint {
  21. namespace detail {
  22. struct ode_state_iterator_tag {};
  23. struct ode_state_time_iterator_tag {};
  24. template< class Iterator , class Stepper , class System , class State , typename Tag >
  25. class ode_iterator_base;
  26. /* Specialization for the state iterator that has only state_type as its value_type */
  27. template< class Iterator , class Stepper , class System , class State >
  28. class ode_iterator_base< Iterator , Stepper , System , State , ode_state_iterator_tag >
  29. : public boost::iterator_facade
  30. <
  31. Iterator ,
  32. typename traits::state_type< Stepper >::type const ,
  33. boost::single_pass_traversal_tag
  34. >
  35. {
  36. private:
  37. typedef Stepper stepper_type;
  38. typedef System system_type;
  39. typedef typename boost::numeric::odeint::unwrap_reference< stepper_type >::type unwrapped_stepper_type;
  40. typedef State state_type;
  41. typedef typename unwrapped_stepper_type::time_type time_type;
  42. typedef typename unwrapped_stepper_type::value_type ode_value_type;
  43. public:
  44. ode_iterator_base( stepper_type stepper , system_type sys , time_type t , time_type dt )
  45. : m_stepper( stepper ) , m_system( sys ) ,
  46. m_t( t ) , m_dt( dt ) , m_at_end( false )
  47. { }
  48. ode_iterator_base( stepper_type stepper , system_type sys )
  49. : m_stepper( stepper ) , m_system( sys ) ,
  50. m_t() , m_dt() , m_at_end( true )
  51. { }
  52. // this function is only for testing
  53. bool same( const ode_iterator_base &iter ) const
  54. {
  55. return (
  56. //( static_cast<Iterator>(*this).get_state() ==
  57. // static_cast<Iterator>(iter).get_state ) &&
  58. ( m_t == iter.m_t ) &&
  59. ( m_dt == iter.m_dt ) &&
  60. ( m_at_end == iter.m_at_end )
  61. );
  62. }
  63. protected:
  64. friend class boost::iterator_core_access;
  65. bool equal( ode_iterator_base const& other ) const
  66. {
  67. if( m_at_end == other.m_at_end )
  68. {
  69. return true;
  70. }
  71. else
  72. {
  73. return false;
  74. }
  75. }
  76. const state_type& dereference() const
  77. {
  78. return static_cast<const Iterator*>(this)->get_state();
  79. }
  80. protected:
  81. stepper_type m_stepper;
  82. system_type m_system;
  83. time_type m_t;
  84. time_type m_dt;
  85. bool m_at_end;
  86. };
  87. /* Specialization for the state-time iterator that has pair<state_type,time_type> as its value_type */
  88. template< class Iterator , class Stepper , class System , class State >
  89. class ode_iterator_base< Iterator , Stepper , System , State , ode_state_time_iterator_tag >
  90. : public boost::iterator_facade
  91. <
  92. Iterator ,
  93. std::pair< const State , const typename traits::time_type< Stepper >::type > ,
  94. boost::single_pass_traversal_tag ,
  95. std::pair< const State& , const typename traits::time_type< Stepper >::type& >
  96. >
  97. {
  98. private:
  99. typedef Stepper stepper_type;
  100. typedef System system_type;
  101. typedef typename boost::numeric::odeint::unwrap_reference< stepper_type >::type unwrapped_stepper_type;
  102. typedef State state_type;
  103. typedef typename unwrapped_stepper_type::time_type time_type;
  104. typedef typename unwrapped_stepper_type::value_type ode_value_type;
  105. public:
  106. ode_iterator_base( stepper_type stepper , system_type sys ,
  107. time_type t , time_type dt )
  108. : m_stepper( stepper ) , m_system( sys ) ,
  109. m_t( t ) , m_dt( dt ) , m_at_end( false )
  110. { }
  111. ode_iterator_base( stepper_type stepper , system_type sys )
  112. : m_stepper( stepper ) , m_system( sys ) , m_at_end( true )
  113. { }
  114. bool same( ode_iterator_base const& iter )
  115. {
  116. return (
  117. //( static_cast<Iterator>(*this).get_state() ==
  118. // static_cast<Iterator>(iter).get_state ) &&
  119. ( m_t == iter.m_t ) &&
  120. ( m_dt == iter.m_dt ) &&
  121. ( m_at_end == iter.m_at_end )
  122. );
  123. }
  124. protected:
  125. friend class boost::iterator_core_access;
  126. bool equal( ode_iterator_base const& other ) const
  127. {
  128. if( m_at_end == other.m_at_end )
  129. {
  130. return true;
  131. }
  132. else
  133. {
  134. return false;
  135. }
  136. }
  137. std::pair< const state_type& , const time_type& > dereference() const
  138. {
  139. return std::pair< const state_type & , const time_type & >(
  140. static_cast<const Iterator*>(this)->get_state() , m_t );
  141. }
  142. stepper_type m_stepper;
  143. system_type m_system;
  144. time_type m_t;
  145. time_type m_dt;
  146. bool m_at_end;
  147. };
  148. } // namespace detail
  149. } // namespace odeint
  150. } // namespace numeric
  151. } // namespace boost
  152. #endif // BOOST_NUMERIC_ODEINT_ITERATOR_DETAIL_ODE_ITERATOR_BASE_HPP_INCLUDED