4 boost/numeric/odeint/iterator/detail/ode_iterator_base.hpp
7 Base class for const_step_iterator and adaptive_iterator.
10 Copyright 2012-2013 Karsten Ahnert
11 Copyright 2012-2013 Mario Mulansky
13 Distributed under the Boost Software License, Version 1.0.
14 (See accompanying file LICENSE_1_0.txt or
15 copy at http://www.boost.org/LICENSE_1_0.txt)
19 #ifndef BOOST_NUMERIC_ODEINT_ITERATOR_DETAIL_ODE_ITERATOR_BASE_HPP_INCLUDED
20 #define BOOST_NUMERIC_ODEINT_ITERATOR_DETAIL_ODE_ITERATOR_BASE_HPP_INCLUDED
22 #include <boost/iterator/iterator_facade.hpp>
24 #include <boost/numeric/odeint/util/unwrap_reference.hpp>
25 #include <boost/numeric/odeint/util/detail/less_with_sign.hpp>
32 struct ode_state_iterator_tag {};
33 struct ode_state_time_iterator_tag {};
35 template< class Iterator , class Stepper , class System , class State , typename Tag >
36 class ode_iterator_base;
39 /* Specialization for the state iterator that has only state_type as its value_type */
40 template< class Iterator , class Stepper , class System , class State >
41 class ode_iterator_base< Iterator , Stepper , System , State , ode_state_iterator_tag >
42 : public boost::iterator_facade
45 typename traits::state_type< Stepper >::type const ,
46 boost::single_pass_traversal_tag
51 typedef Stepper stepper_type;
52 typedef System system_type;
53 typedef typename boost::numeric::odeint::unwrap_reference< stepper_type >::type unwrapped_stepper_type;
54 typedef State state_type;
55 typedef typename unwrapped_stepper_type::time_type time_type;
56 typedef typename unwrapped_stepper_type::value_type ode_value_type;
60 ode_iterator_base( stepper_type stepper , system_type sys , time_type t , time_type dt )
61 : m_stepper( stepper ) , m_system( sys ) ,
62 m_t( t ) , m_dt( dt ) , m_at_end( false )
65 ode_iterator_base( stepper_type stepper , system_type sys )
66 : m_stepper( stepper ) , m_system( sys ) ,
67 m_t() , m_dt() , m_at_end( true )
70 // this function is only for testing
71 bool same( const ode_iterator_base &iter ) const
74 //( static_cast<Iterator>(*this).get_state() ==
75 // static_cast<Iterator>(iter).get_state ) &&
76 ( m_t == iter.m_t ) &&
77 ( m_dt == iter.m_dt ) &&
78 ( m_at_end == iter.m_at_end )
85 friend class boost::iterator_core_access;
87 bool equal( ode_iterator_base const& other ) const
89 if( m_at_end == other.m_at_end )
99 const state_type& dereference() const
101 return static_cast<const Iterator*>(this)->get_state();
106 stepper_type m_stepper;
107 system_type m_system;
115 /* Specialization for the state-time iterator that has pair<state_type,time_type> as its value_type */
117 template< class Iterator , class Stepper , class System , class State >
118 class ode_iterator_base< Iterator , Stepper , System , State , ode_state_time_iterator_tag >
119 : public boost::iterator_facade
122 std::pair< const State , const typename traits::time_type< Stepper >::type > ,
123 boost::single_pass_traversal_tag ,
124 std::pair< const State& , const typename traits::time_type< Stepper >::type& >
129 typedef Stepper stepper_type;
130 typedef System system_type;
131 typedef typename boost::numeric::odeint::unwrap_reference< stepper_type >::type unwrapped_stepper_type;
132 typedef State state_type;
133 typedef typename unwrapped_stepper_type::time_type time_type;
134 typedef typename unwrapped_stepper_type::value_type ode_value_type;
138 ode_iterator_base( stepper_type stepper , system_type sys ,
139 time_type t , time_type dt )
140 : m_stepper( stepper ) , m_system( sys ) ,
141 m_t( t ) , m_dt( dt ) , m_at_end( false )
144 ode_iterator_base( stepper_type stepper , system_type sys )
145 : m_stepper( stepper ) , m_system( sys ) , m_at_end( true )
148 bool same( ode_iterator_base const& iter )
151 //( static_cast<Iterator>(*this).get_state() ==
152 // static_cast<Iterator>(iter).get_state ) &&
153 ( m_t == iter.m_t ) &&
154 ( m_dt == iter.m_dt ) &&
155 ( m_at_end == iter.m_at_end )
162 friend class boost::iterator_core_access;
164 bool equal( ode_iterator_base const& other ) const
166 if( m_at_end == other.m_at_end )
176 std::pair< const state_type& , const time_type& > dereference() const
178 return std::pair< const state_type & , const time_type & >(
179 static_cast<const Iterator*>(this)->get_state() , m_t );
182 stepper_type m_stepper;
183 system_type m_system;
192 } // namespace detail
193 } // namespace odeint
194 } // namespace numeric
199 #endif // BOOST_NUMERIC_ODEINT_ITERATOR_DETAIL_ODE_ITERATOR_BASE_HPP_INCLUDED