//Copyright (c) 2008-2016 Emil Dotchevski and Reverge Studios, Inc. //Distributed under the Boost Software License, Version 1.0. (See accompanying //file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) #ifndef UUID_90273D9C0E5911E281B7981F6288709B #define UUID_90273D9C0E5911E281B7981F6288709B #include #include #include #include #include #include namespace boost { namespace qvm { //////////////////////////////////////////////// namespace qvm_detail { template struct mat_index_read_defined { static bool const value=false; }; template struct matrix_r { template static BOOST_QVM_INLINE_CRITICAL typename mat_traits::scalar_type read_element_idx( A const & a, int r, int c ) { return (I/mat_traits::cols)==r && (I%mat_traits::cols)==c? mat_traits::template read_element::cols,I%mat_traits::cols>(a) : matrix_r::read_element_idx(a,r,c); } }; template struct matrix_r { template static BOOST_QVM_INLINE_TRIVIAL typename mat_traits::scalar_type read_element_idx( A const & a, int, int ) { BOOST_QVM_ASSERT(0); return mat_traits::template read_element<0,0>(a); } }; } template BOOST_QVM_INLINE_TRIVIAL typename boost::enable_if_c< is_mat::value && !qvm_detail::mat_index_read_defined::rows,mat_traits::cols>::value, typename mat_traits::scalar_type>::type mat_index_read( A const & a, int r, int c ) { return qvm_detail::matrix_r<0,mat_traits::rows*mat_traits::cols>::read_element_idx(a,r,c); } //////////////////////////////////////////////// namespace qvm_detail { template struct mat_index_write_defined { static bool const value=false; }; template struct matrix_w { template static BOOST_QVM_INLINE_CRITICAL typename mat_traits::scalar_type & write_element_idx( A & a, int r, int c ) { return (I/mat_traits::cols)==r && (I%mat_traits::cols)==c? mat_traits::template write_element::cols,I%mat_traits::cols>(a) : matrix_w::write_element_idx(a,r,c); } }; template struct matrix_w { template static BOOST_QVM_INLINE_TRIVIAL typename mat_traits::scalar_type & write_element_idx( A & a, int, int ) { BOOST_QVM_ASSERT(0); return mat_traits::template write_element<0,0>(a); } }; } template BOOST_QVM_INLINE_TRIVIAL typename boost::enable_if_c< is_mat::value && !qvm_detail::mat_index_write_defined::rows,mat_traits::cols>::value, typename mat_traits::scalar_type &>::type mat_index_write( A & a, int r, int c ) { return qvm_detail::matrix_w<0,mat_traits::rows*mat_traits::cols>::write_element_idx(a,r,c); } //////////////////////////////////////////////// namespace sfinae { using ::boost::qvm::mat_index_read; using ::boost::qvm::mat_index_write; } //////////////////////////////////////////////// } } #endif