/* * $Rev: 4687 $ * Author: Jesse Perla (c) 2010 * Use, modification and distribution are subject to 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) */ #include #include #include #include //Bindings for access to the data #include #include #include #include #include #include #include //Need to translate between data types and a C #define for storage. #define MAT_C_DOUBLE 1 //This is the sort of thing that is in matio... would come in the headers #define MAT_C_FLOAT 2 //This is the sort of thing that is in matio template struct get_matio_type; template<> struct get_matio_type : boost::mpl::int_{}; template<> struct get_matio_type : boost::mpl::int_{}; //This would have the pointers to the archive stream struct matlab_archive{}; //Specialization for vectors with contiguous memory template typename boost::enable_if_c< boost::numeric::bindings::rank::value == 1 && boost::numeric::bindings::has_linear_array::value, matlab_archive& >::type operator&( matlab_archive& arch, const boost::serialization::nvp& t ) { //Can Get the value_type: typedef typename boost::numeric::bindings::value_type::type value_type; const static int matio_value_type = get_matio_type::value; //Using the following pointers auto p_begin = boost::numeric::bindings::begin(t.value()); auto p_end = boost::numeric::bindings::end(t.value()); std::cout << "Vector Name:" << t.name() << std::endl << "Value:" << t.value() << std::endl; return arch; } //Specialization for row major matrices with contiguous memory template typename boost::enable_if_c< boost::numeric::bindings::rank::value == 2 && boost::numeric::bindings::is_row_major::value && boost::numeric::bindings::has_linear_array::value, matlab_archive& >::type operator&( matlab_archive& arch, const boost::serialization::nvp& t ) { //Can Get the value_type: typedef typename boost::numeric::bindings::value_type::type value_type; const static int matio_value_type = get_matio_type::value; T& mat = t.value(); //Using the following pointers //How do I use begin/end in the bindings with matrices? //auto p_begin = boost::numeric::bindings::begin(mat); //auto p_end = boost::numeric::bindings::end(mat); std::cout << "Matrix Name:" << t.name() << std::endl << "Value:" << mat << std::endl; return arch; } //Specialization for column major matrices with contiguous memory template typename boost::enable_if_c< boost::numeric::bindings::rank::value == 2 && boost::numeric::bindings::is_column_major::value && boost::numeric::bindings::has_linear_array::value, matlab_archive& >::type operator&( matlab_archive& arch, const boost::serialization::nvp& t ) { //Can Get the value_type: typedef typename boost::numeric::bindings::value_type::type value_type; const static int matio_value_type = get_matio_type::value; T& mat = t.value(); //I will probably have to do a transpose before writing. matio doesn't seem to support fortran ordering. //Using the following pointers //How do I use begin/end in the bindings with matrices? //auto p_begin = boost::numeric::bindings::begin(mat); //auto p_end = boost::numeric::bindings::end(mat); std::cout << "Matrix Name:" << t.name() << std::endl << "Value:" << mat << std::endl; return arch; } int main(int argc, char* argv[]) { using boost::serialization::make_nvp; using namespace boost::numeric::ublas; matrix m(2,2); matlab_archive ar; //THis would also take care of the file stuff. ar & make_nvp("myvec", vector(2)) & make_nvp("mymat", matrix(2,2)) & make_nvp("mymat2", matrix(2,2)); }