1
2/*
3 [auto_generated]
4 boost/numeric/odeint/iterator/detail/ode_iterator_base.hpp
5
6 [begin_description]
7 Base class for const_step_iterator and adaptive_iterator.
8 [end_description]
9
10 Copyright 2012-2013 Karsten Ahnert
11 Copyright 2012-2013 Mario Mulansky
12
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)
16 */
17
18
19#ifndef BOOST_NUMERIC_ODEINT_ITERATOR_DETAIL_ODE_ITERATOR_BASE_HPP_INCLUDED
20#define BOOST_NUMERIC_ODEINT_ITERATOR_DETAIL_ODE_ITERATOR_BASE_HPP_INCLUDED
21
22#include <boost/iterator/iterator_facade.hpp>
23
24#include <boost/numeric/odeint/util/unwrap_reference.hpp>
25#include <boost/numeric/odeint/util/detail/less_with_sign.hpp>
26
27namespace boost {
28namespace numeric {
29namespace odeint {
30namespace detail {
31
32 struct ode_state_iterator_tag {};
33 struct ode_state_time_iterator_tag {};
34
35 template< class Iterator , class Stepper , class System , class State , typename Tag >
36 class ode_iterator_base;
37
38
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
43 <
44 Iterator ,
45 typename traits::state_type< Stepper >::type const ,
46 boost::single_pass_traversal_tag
47 >
48 {
49 private:
50
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;
57
58 public:
59
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 )
63 { }
64
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 )
68 { }
69
70 // this function is only for testing
71 bool same( const ode_iterator_base &iter ) const
72 {
73 return (
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 )
79 );
80 }
81
82
83 protected:
84
85 friend class boost::iterator_core_access;
86
87 bool equal( ode_iterator_base const& other ) const
88 {
89 if( m_at_end == other.m_at_end )
90 {
91 return true;
92 }
93 else
94 {
95 return false;
96 }
97 }
98
99 const state_type& dereference() const
100 {
101 return static_cast<const Iterator*>(this)->get_state();
102 }
103
104 protected:
105
106 stepper_type m_stepper;
107 system_type m_system;
108 time_type m_t;
109 time_type m_dt;
110 bool m_at_end;
111 };
112
113
114
115 /* Specialization for the state-time iterator that has pair<state_type,time_type> as its value_type */
116
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
120 <
121 Iterator ,
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& >
125 >
126 {
127 private:
128
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;
135
136 public:
137
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 )
142 { }
143
144 ode_iterator_base( stepper_type stepper , system_type sys )
145 : m_stepper( stepper ) , m_system( sys ) , m_at_end( true )
146 { }
147
148 bool same( ode_iterator_base const& iter )
149 {
150 return (
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 )
156 );
157 }
158
159
160 protected:
161
162 friend class boost::iterator_core_access;
163
164 bool equal( ode_iterator_base const& other ) const
165 {
166 if( m_at_end == other.m_at_end )
167 {
168 return true;
169 }
170 else
171 {
172 return false;
173 }
174 }
175
176 std::pair< const state_type& , const time_type& > dereference() const
177 {
178 return std::pair< const state_type & , const time_type & >(
179 static_cast<const Iterator*>(this)->get_state() , m_t );
180 }
181
182 stepper_type m_stepper;
183 system_type m_system;
184 time_type m_t;
185 time_type m_dt;
186 bool m_at_end;
187
188 };
189
190
191
192} // namespace detail
193} // namespace odeint
194} // namespace numeric
195} // namespace boost
196
197
198
199#endif // BOOST_NUMERIC_ODEINT_ITERATOR_DETAIL_ODE_ITERATOR_BASE_HPP_INCLUDED
200

source code of boost/boost/numeric/odeint/iterator/detail/ode_iterator_base.hpp