1 /* 2 Copyright 2011 Mario Mulansky 3 Copyright 2012 Karsten Ahnert 4 5 Distributed under the Boost Software License, Version 1.0. 6 (See accompanying file LICENSE_1_0.txt or 7 copy at http://www.boost.org/LICENSE_1_0.txt) 8 */ 9 10 11 /* reserved vector */ 12 13 #ifndef VECTOR_VECTOR_RESIZE_HPP 14 #define VECTOR_VECTOR_RESIZE_HPP 15 16 #include <vector> 17 18 #include <boost/range.hpp> 19 20 namespace boost { namespace numeric { namespace odeint { 21 22 template<> 23 struct is_resizeable< std::vector< std::vector< double > > > 24 { 25 typedef boost::true_type type; 26 const static bool value = type::value; 27 }; 28 29 template<> 30 struct same_size_impl< std::vector< std::vector< double > > , std::vector< std::vector< double > > > 31 { 32 typedef std::vector< std::vector< double > > state_type; 33 same_sizeboost::numeric::odeint::same_size_impl34 static bool same_size( const state_type &x1 , 35 const state_type &x2 ) 36 { 37 bool same = ( boost::size( x1 ) == boost::size( x2 ) ); 38 if( !same ) 39 return false; 40 typename state_type::const_iterator begin1 = boost::begin( x1 ); 41 typename state_type::const_iterator begin2 = boost::begin( x2 ); 42 while( begin1 != boost::end( x1 ) ) 43 same &= ( boost::size( *begin1++ ) == boost::size( *begin2++ ) ); 44 return same; 45 } 46 }; 47 48 template<> 49 struct resize_impl< std::vector< std::vector< double > > , std::vector< std::vector< double > > > 50 { 51 typedef std::vector< std::vector< double > > state_type; 52 resizeboost::numeric::odeint::resize_impl53 static void resize( state_type &x1 , const state_type &x2 ) 54 { 55 x1.resize( boost::size( x2 ) ); 56 typename state_type::iterator begin1 = boost::begin( x1 ); 57 typename state_type::const_iterator begin2 = boost::begin( x2 ); 58 while( begin1 != boost::end( x1 ) ) 59 (*begin1++).resize( boost::size( *begin2++ ) ); 60 } 61 }; 62 63 template<> 64 struct state_wrapper< std::vector< std::vector< double > > > 65 { 66 typedef std::vector< std::vector< double > > state_type; 67 typedef state_wrapper< state_type > state_wrapper_type; 68 typedef boost::true_type is_resizeable; 69 70 state_type m_v; 71 72 template< class State > same_sizeboost::numeric::odeint::state_wrapper73 bool same_size( const State &x ) 74 { 75 bool same = ( boost::size( m_v ) == boost::size( x ) ); 76 if( !same ) 77 return false; 78 typename state_type::iterator begin1 = boost::begin( m_v ); 79 typename State::const_iterator begin2 = boost::begin( x ); 80 while( begin1 != boost::end( m_v ) ) 81 same &= ( boost::size( *begin1++ ) == boost::size( *begin2++ ) ); 82 return same; 83 } 84 85 template< class State > resizeboost::numeric::odeint::state_wrapper86 bool resize( const State &x ) 87 { 88 if( !same_size( x ) ) 89 { 90 m_v.resize( boost::size( x ) ); 91 typename state_type::iterator begin1 = boost::begin( m_v ); 92 typename State::const_iterator begin2 = boost::begin( x ); 93 while( begin1 != boost::end( m_v ) ) 94 (*begin1++).resize( boost::size( *begin2++ ) ); 95 96 return true; 97 } else 98 return false; 99 } 100 101 }; 102 103 } } } 104 105 #endif 106