diagnostic_state_type.hpp 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185
  1. /*
  2. [auto_generated]
  3. libs/numeric/odeint/test/diagnostic_state_type.hpp
  4. [begin_description]
  5. tba.
  6. [end_description]
  7. Copyright 2012 Karsten Ahnert
  8. Copyright 2012 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 LIBS_NUMERIC_ODEINT_TEST_DIAGNOSTIC_STATE_TYPE_HPP_DEFINED
  14. #define LIBS_NUMERIC_ODEINT_TEST_DIAGNOSTIC_STATE_TYPE_HPP_DEFINED
  15. #include <boost/array.hpp>
  16. #include <boost/numeric/odeint/util/is_resizeable.hpp>
  17. #include <boost/numeric/odeint/util/same_size.hpp>
  18. #include <boost/numeric/odeint/util/resize.hpp>
  19. #include <boost/numeric/odeint/util/state_wrapper.hpp>
  20. template< size_t N >
  21. struct counter
  22. {
  23. static size_t& adjust_size_count( void )
  24. {
  25. static size_t m_adjust_size_count;
  26. return m_adjust_size_count;
  27. }
  28. static size_t& construct_count( void )
  29. {
  30. static size_t m_construct_count;
  31. return m_construct_count;
  32. }
  33. static size_t& copy_count( void )
  34. {
  35. static size_t m_copy_count;
  36. return m_copy_count;
  37. }
  38. static size_t& destroy_count( void )
  39. {
  40. static size_t m_destroy_count;
  41. return m_destroy_count;
  42. }
  43. static void init_counter( void )
  44. {
  45. counter< N >::adjust_size_count() = 0;
  46. counter< N >::construct_count() = 0;
  47. counter< N >::copy_count() = 0;
  48. counter< N >::destroy_count() = 0;
  49. }
  50. };
  51. template< size_t N >
  52. class diagnostic_type : public boost::array< double , 1 > { };
  53. typedef diagnostic_type< 0 > diagnostic_state_type;
  54. typedef diagnostic_type< 1 > diagnostic_deriv_type;
  55. typedef diagnostic_type< 2 > diagnostic_state_type2;
  56. typedef diagnostic_type< 3 > diagnostic_deriv_type2;
  57. typedef counter< 0 > counter_state;
  58. typedef counter< 1 > counter_deriv;
  59. typedef counter< 2 > counter_state2;
  60. typedef counter< 3 > counter_deriv2;
  61. namespace boost {
  62. namespace numeric {
  63. namespace odeint {
  64. template< size_t N >
  65. struct is_resizeable< diagnostic_type< N > >
  66. {
  67. typedef boost::true_type type;
  68. const static bool value = type::value;
  69. };
  70. template< size_t N , size_t M >
  71. struct same_size_impl< diagnostic_type< N > , diagnostic_type< M > >
  72. {
  73. static bool same_size( const diagnostic_type< N > &x1 , const diagnostic_type< M > &x2 )
  74. {
  75. return false;
  76. }
  77. };
  78. template< size_t N , class State1 >
  79. struct same_size_impl< diagnostic_type< N > , State1 >
  80. {
  81. static bool same_size( const diagnostic_type< N > &x1 , const State1 &x2 )
  82. {
  83. return false;
  84. }
  85. };
  86. template< class State1 , size_t N >
  87. struct same_size_impl< State1 , diagnostic_type< N > >
  88. {
  89. static bool same_size( const State1 &x1 , const diagnostic_type< N > &x2 )
  90. {
  91. return false;
  92. }
  93. };
  94. template< size_t N , class StateIn >
  95. struct resize_impl< diagnostic_type< N > , StateIn >
  96. {
  97. static void resize( diagnostic_type< N > &x1 , const StateIn &x2 )
  98. {
  99. counter< N >::adjust_size_count()++;
  100. }
  101. };
  102. template< size_t N >
  103. struct state_wrapper< diagnostic_type< N > >
  104. {
  105. typedef state_wrapper< diagnostic_type< N > > state_wrapper_type;
  106. typedef diagnostic_type< N > state_type;
  107. typedef double value_type;
  108. state_type m_v;
  109. state_wrapper() : m_v()
  110. {
  111. counter< N >::construct_count()++;
  112. }
  113. state_wrapper( const state_type &v ) : m_v( v )
  114. {
  115. counter< N >::construct_count()++;
  116. counter< N >::copy_count()++;
  117. }
  118. state_wrapper( const state_wrapper_type &x ) : m_v( x.m_v )
  119. {
  120. counter< N >::construct_count()++;
  121. counter< N >::copy_count()++;
  122. }
  123. state_wrapper_type& operator=( const state_wrapper_type &x )
  124. {
  125. counter< N >::copy_count()++;
  126. return *this;
  127. }
  128. ~state_wrapper()
  129. {
  130. counter< N >::destroy_count()++;
  131. }
  132. };
  133. } // namespace odeint
  134. } // namespace numeric
  135. } // namespace boost
  136. #define TEST_COUNTERS( c , s1 , s2 , s3 ,s4 ) \
  137. BOOST_CHECK_EQUAL( c::adjust_size_count() , size_t( s1 ) ); \
  138. BOOST_CHECK_EQUAL( c::construct_count() , size_t( s2 ) ); \
  139. BOOST_CHECK_EQUAL( c::copy_count() , size_t( s3 ) ); \
  140. BOOST_CHECK_EQUAL( c::destroy_count() , size_t( s4 ) );
  141. #define TEST_COUNTERS_MSG( c , s1 , s2 , s3 ,s4 , msg ) \
  142. BOOST_CHECK_EQUAL( c::adjust_size_count() , size_t( s1 ) ); \
  143. BOOST_CHECK_EQUAL( c::construct_count() , size_t( s2 ) ); \
  144. BOOST_CHECK_EQUAL( c::copy_count() , size_t( s3 ) ); \
  145. BOOST_CHECK_EQUAL( c::destroy_count() , size_t( s4 ) );
  146. #endif // LIBS_NUMERIC_ODEINT_TEST_DIAGNOSTIC_STATE_TYPE_HPP_DEFINED