1 /* 2 [auto_generated] 3 libs/numeric/odeint/test/diagnostic_state_type.hpp 4 5 [begin_description] 6 tba. 7 [end_description] 8 9 Copyright 2012 Karsten Ahnert 10 Copyright 2012 Mario Mulansky 11 12 Distributed under the Boost Software License, Version 1.0. 13 (See accompanying file LICENSE_1_0.txt or 14 copy at http://www.boost.org/LICENSE_1_0.txt) 15 */ 16 17 18 #ifndef LIBS_NUMERIC_ODEINT_TEST_DIAGNOSTIC_STATE_TYPE_HPP_DEFINED 19 #define LIBS_NUMERIC_ODEINT_TEST_DIAGNOSTIC_STATE_TYPE_HPP_DEFINED 20 21 #include <boost/array.hpp> 22 #include <boost/numeric/odeint/util/is_resizeable.hpp> 23 #include <boost/numeric/odeint/util/same_size.hpp> 24 #include <boost/numeric/odeint/util/resize.hpp> 25 #include <boost/numeric/odeint/util/state_wrapper.hpp> 26 27 template< size_t N > 28 struct counter 29 { adjust_size_countcounter30 static size_t& adjust_size_count( void ) 31 { 32 static size_t m_adjust_size_count; 33 return m_adjust_size_count; 34 } 35 construct_countcounter36 static size_t& construct_count( void ) 37 { 38 static size_t m_construct_count; 39 return m_construct_count; 40 } 41 copy_countcounter42 static size_t& copy_count( void ) 43 { 44 static size_t m_copy_count; 45 return m_copy_count; 46 } 47 destroy_countcounter48 static size_t& destroy_count( void ) 49 { 50 static size_t m_destroy_count; 51 return m_destroy_count; 52 } 53 54 init_countercounter55 static void init_counter( void ) 56 { 57 counter< N >::adjust_size_count() = 0; 58 counter< N >::construct_count() = 0; 59 counter< N >::copy_count() = 0; 60 counter< N >::destroy_count() = 0; 61 } 62 }; 63 64 template< size_t N > 65 class diagnostic_type : public boost::array< double , 1 > { }; 66 67 68 typedef diagnostic_type< 0 > diagnostic_state_type; 69 typedef diagnostic_type< 1 > diagnostic_deriv_type; 70 typedef diagnostic_type< 2 > diagnostic_state_type2; 71 typedef diagnostic_type< 3 > diagnostic_deriv_type2; 72 73 typedef counter< 0 > counter_state; 74 typedef counter< 1 > counter_deriv; 75 typedef counter< 2 > counter_state2; 76 typedef counter< 3 > counter_deriv2; 77 78 79 80 namespace boost { 81 namespace numeric { 82 namespace odeint { 83 84 template< size_t N > 85 struct is_resizeable< diagnostic_type< N > > 86 { 87 typedef boost::true_type type; 88 const static bool value = type::value; 89 }; 90 91 template< size_t N , size_t M > 92 struct same_size_impl< diagnostic_type< N > , diagnostic_type< M > > 93 { same_sizeboost::numeric::odeint::same_size_impl94 static bool same_size( const diagnostic_type< N > &x1 , const diagnostic_type< M > &x2 ) 95 { 96 return false; 97 } 98 }; 99 100 template< size_t N , class State1 > 101 struct same_size_impl< diagnostic_type< N > , State1 > 102 { same_sizeboost::numeric::odeint::same_size_impl103 static bool same_size( const diagnostic_type< N > &x1 , const State1 &x2 ) 104 { 105 return false; 106 } 107 }; 108 109 template< class State1 , size_t N > 110 struct same_size_impl< State1 , diagnostic_type< N > > 111 { same_sizeboost::numeric::odeint::same_size_impl112 static bool same_size( const State1 &x1 , const diagnostic_type< N > &x2 ) 113 { 114 return false; 115 } 116 }; 117 118 119 120 template< size_t N , class StateIn > 121 struct resize_impl< diagnostic_type< N > , StateIn > 122 { resizeboost::numeric::odeint::resize_impl123 static void resize( diagnostic_type< N > &x1 , const StateIn &x2 ) 124 { 125 counter< N >::adjust_size_count()++; 126 } 127 }; 128 129 template< size_t N > 130 struct state_wrapper< diagnostic_type< N > > 131 { 132 typedef state_wrapper< diagnostic_type< N > > state_wrapper_type; 133 typedef diagnostic_type< N > state_type; 134 typedef double value_type; 135 136 state_type m_v; 137 state_wrapperboost::numeric::odeint::state_wrapper138 state_wrapper() : m_v() 139 { 140 counter< N >::construct_count()++; 141 } 142 state_wrapperboost::numeric::odeint::state_wrapper143 state_wrapper( const state_type &v ) : m_v( v ) 144 { 145 counter< N >::construct_count()++; 146 counter< N >::copy_count()++; 147 } 148 state_wrapperboost::numeric::odeint::state_wrapper149 state_wrapper( const state_wrapper_type &x ) : m_v( x.m_v ) 150 { 151 counter< N >::construct_count()++; 152 counter< N >::copy_count()++; 153 } 154 operator =boost::numeric::odeint::state_wrapper155 state_wrapper_type& operator=( const state_wrapper_type &x ) 156 { 157 counter< N >::copy_count()++; 158 return *this; 159 } 160 ~state_wrapperboost::numeric::odeint::state_wrapper161 ~state_wrapper() 162 { 163 counter< N >::destroy_count()++; 164 } 165 }; 166 167 168 } // namespace odeint 169 } // namespace numeric 170 } // namespace boost 171 172 #define TEST_COUNTERS( c , s1 , s2 , s3 ,s4 ) \ 173 BOOST_CHECK_EQUAL( c::adjust_size_count() , size_t( s1 ) ); \ 174 BOOST_CHECK_EQUAL( c::construct_count() , size_t( s2 ) ); \ 175 BOOST_CHECK_EQUAL( c::copy_count() , size_t( s3 ) ); \ 176 BOOST_CHECK_EQUAL( c::destroy_count() , size_t( s4 ) ); 177 178 #define TEST_COUNTERS_MSG( c , s1 , s2 , s3 ,s4 , msg ) \ 179 BOOST_CHECK_EQUAL( c::adjust_size_count() , size_t( s1 ) ); \ 180 BOOST_CHECK_EQUAL( c::construct_count() , size_t( s2 ) ); \ 181 BOOST_CHECK_EQUAL( c::copy_count() , size_t( s3 ) ); \ 182 BOOST_CHECK_EQUAL( c::destroy_count() , size_t( s4 ) ); 183 184 185 #endif // LIBS_NUMERIC_ODEINT_TEST_DIAGNOSTIC_STATE_TYPE_HPP_DEFINED 186