• Main Page
  • Related Pages
  • Modules
  • Namespaces
  • Classes
  • Files
  • File List
  • File Members

MatrixConvert.h

Go to the documentation of this file.
00001 // GMTL is (C) Copyright 2001-2010 by Allen Bierbaum
00002 // Distributed under the GNU Lesser General Public License 2.1 with an
00003 // addendum covering inlined code. (See accompanying files LICENSE and
00004 // LICENSE.addendum or http://www.gnu.org/copyleft/lesser.txt)
00005 
00006 #ifndef _GMTL_MATRIX_CONVERT_H_
00007 #define _GMTL_MATRIX_CONVERT_H_
00008 
00009 #include <boost/mpl/for_each.hpp>
00010 #include <boost/mpl/range_c.hpp>
00011 #include <boost/lambda/lambda.hpp>
00012 #include <gmtl/Matrix.h>
00013 
00014 
00015 namespace gmtl
00016 {
00017 
00036 template<typename DATA_TYPE_OUT, typename DATA_TYPE_IN, unsigned ROWS, unsigned COLS>
00037 inline gmtl::Matrix<DATA_TYPE_OUT, ROWS, COLS>
00038 convertTo(const gmtl::Matrix<DATA_TYPE_IN, ROWS, COLS>& in)
00039 {
00040    using namespace boost::lambda;
00041 
00042    gmtl::Matrix<DATA_TYPE_OUT, ROWS, COLS> out;
00043 
00044    // Accessing in.mData and out.mData in this way allows for use of
00045    // Boost.Lambda so that a separate helper function is not required to do
00046    // the assignment.
00047    const DATA_TYPE_IN* in_data(in.mData);
00048    DATA_TYPE_OUT* out_data(out.mData);
00049 
00050    // This relies on implicit casting between data types.
00051    boost::mpl::for_each< boost::mpl::range_c<unsigned int, 0, ROWS * COLS> >(
00052       *(out_data + boost::lambda::_1) = *(in_data + boost::lambda::_1)
00053    );
00054 
00055    return out;
00056 }
00057 
00058 }
00059 
00060 
00061 #endif /* _GMTL_MATRIX_CONVERT_H_ */

Generated on Sun Sep 19 2010 14:35:14 for GenericMathTemplateLibrary by  doxygen 1.7.1