Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:42:53

0001 
0002 /*
0003  [auto_generated]
0004  boost/numeric/odeint/iterator/detail/ode_iterator_base.hpp
0005 
0006  [begin_description]
0007  Base class for const_step_iterator and adaptive_iterator.
0008  [end_description]
0009 
0010  Copyright 2012-2013 Karsten Ahnert
0011  Copyright 2012-2013 Mario Mulansky
0012 
0013  Distributed under the Boost Software License, Version 1.0.
0014  (See accompanying file LICENSE_1_0.txt or
0015  copy at http://www.boost.org/LICENSE_1_0.txt)
0016  */
0017 
0018 
0019 #ifndef BOOST_NUMERIC_ODEINT_ITERATOR_DETAIL_ODE_ITERATOR_BASE_HPP_INCLUDED
0020 #define BOOST_NUMERIC_ODEINT_ITERATOR_DETAIL_ODE_ITERATOR_BASE_HPP_INCLUDED
0021 
0022 #include <boost/iterator/iterator_facade.hpp>
0023 
0024 #include <boost/numeric/odeint/util/unwrap_reference.hpp>
0025 #include <boost/numeric/odeint/util/detail/less_with_sign.hpp>
0026 
0027 namespace boost {
0028 namespace numeric {
0029 namespace odeint {
0030 namespace detail {
0031 
0032     struct ode_state_iterator_tag {};
0033     struct ode_state_time_iterator_tag {};
0034 
0035     template< class Iterator , class Stepper , class System , class State , typename Tag >
0036     class ode_iterator_base;
0037 
0038 
0039     /* Specialization for the state iterator that has only state_type as its value_type */
0040     template< class Iterator , class Stepper , class System , class State >
0041     class ode_iterator_base< Iterator , Stepper , System , State , ode_state_iterator_tag >
0042         : public boost::iterator_facade
0043           <
0044               Iterator ,
0045               typename traits::state_type< Stepper >::type const ,
0046               boost::single_pass_traversal_tag
0047           >
0048     {
0049     private:
0050 
0051         typedef Stepper stepper_type;
0052         typedef System system_type;
0053         typedef typename boost::numeric::odeint::unwrap_reference< stepper_type >::type unwrapped_stepper_type;
0054         typedef State state_type;
0055         typedef typename unwrapped_stepper_type::time_type time_type;
0056         typedef typename unwrapped_stepper_type::value_type ode_value_type;
0057 
0058     public:
0059    
0060         ode_iterator_base( stepper_type stepper , system_type sys , time_type t , time_type dt )
0061             : m_stepper( stepper ) , m_system( sys ) ,
0062               m_t( t ) , m_dt( dt ) , m_at_end( false )
0063         { }
0064 
0065         ode_iterator_base( stepper_type stepper , system_type sys )
0066             : m_stepper( stepper ) , m_system( sys ) ,
0067               m_t() , m_dt() , m_at_end( true )
0068         { }
0069 
0070         // this function is only for testing
0071         bool same( const ode_iterator_base &iter ) const
0072         {
0073             return (
0074                 //( static_cast<Iterator>(*this).get_state() ==
0075                 //  static_cast<Iterator>(iter).get_state ) &&
0076                 ( m_t == iter.m_t ) && 
0077                 ( m_dt == iter.m_dt ) &&
0078                 ( m_at_end == iter.m_at_end )
0079                 );
0080         }
0081 
0082 
0083     protected:
0084 
0085         friend class boost::iterator_core_access;
0086 
0087         bool equal( ode_iterator_base const& other ) const
0088         {
0089             if( m_at_end == other.m_at_end )
0090             {
0091                 return true;
0092             }
0093             else
0094             {
0095                 return false;
0096             }
0097         }
0098 
0099         const state_type& dereference() const
0100         {
0101             return static_cast<const Iterator*>(this)->get_state();
0102         }
0103 
0104     protected:
0105 
0106         stepper_type m_stepper;
0107         system_type m_system;
0108         time_type m_t;
0109         time_type m_dt;
0110         bool m_at_end;
0111     };
0112 
0113 
0114 
0115     /* Specialization for the state-time iterator that has pair<state_type,time_type> as its value_type */
0116 
0117     template< class Iterator , class Stepper , class System , class State >
0118     class ode_iterator_base< Iterator , Stepper , System , State , ode_state_time_iterator_tag >
0119         : public boost::iterator_facade
0120           <
0121               Iterator ,
0122               std::pair< const State , const typename traits::time_type< Stepper >::type > ,
0123               boost::single_pass_traversal_tag ,
0124               std::pair< const State& , const typename traits::time_type< Stepper >::type& >
0125           >
0126     {
0127     private:
0128 
0129         typedef Stepper stepper_type;
0130         typedef System system_type;
0131         typedef typename boost::numeric::odeint::unwrap_reference< stepper_type >::type unwrapped_stepper_type;
0132         typedef State state_type;
0133         typedef typename unwrapped_stepper_type::time_type time_type;
0134         typedef typename unwrapped_stepper_type::value_type ode_value_type;
0135 
0136     public:
0137 
0138         ode_iterator_base( stepper_type stepper , system_type sys ,
0139                            time_type t , time_type dt )
0140             : m_stepper( stepper ) , m_system( sys ) ,
0141               m_t( t ) , m_dt( dt ) , m_at_end( false )
0142         { }
0143 
0144         ode_iterator_base( stepper_type stepper , system_type sys )
0145             : m_stepper( stepper ) , m_system( sys ) , m_at_end( true )
0146         { }
0147 
0148         bool same( ode_iterator_base const& iter )
0149         {
0150             return (
0151                 //( static_cast<Iterator>(*this).get_state() ==
0152                 //  static_cast<Iterator>(iter).get_state ) &&
0153                 ( m_t == iter.m_t ) &&
0154                 ( m_dt == iter.m_dt ) &&
0155                 ( m_at_end == iter.m_at_end )
0156                 );
0157         }
0158 
0159 
0160     protected:
0161 
0162         friend class boost::iterator_core_access;
0163 
0164         bool equal( ode_iterator_base const& other ) const
0165         {
0166             if( m_at_end == other.m_at_end )
0167             {
0168                 return true;
0169             }
0170             else
0171             {
0172                 return false;
0173             }
0174         }
0175 
0176         std::pair< const state_type& , const time_type& > dereference() const
0177         {
0178             return std::pair< const state_type & , const time_type & >(
0179                     static_cast<const Iterator*>(this)->get_state() , m_t );
0180         }
0181 
0182         stepper_type m_stepper;
0183         system_type m_system;
0184         time_type m_t;
0185         time_type m_dt;
0186         bool m_at_end;
0187 
0188     };
0189 
0190 
0191 
0192 } // namespace detail
0193 } // namespace odeint
0194 } // namespace numeric
0195 } // namespace boost
0196 
0197 
0198 
0199 #endif // BOOST_NUMERIC_ODEINT_ITERATOR_DETAIL_ODE_ITERATOR_BASE_HPP_INCLUDED