utils.hpp

Go to the documentation of this file.
00001 /*
00002  * 
00003  * Copyright (c) Kresimir Fresl 2003
00004  *
00005  * Distributed under the Boost Software License, Version 1.0.
00006  * (See accompanying file LICENSE_1_0.txt or copy at
00007  * http://www.boost.org/LICENSE_1_0.txt)
00008  *
00009  * Author acknowledges the support of the Faculty of Civil Engineering, 
00010  * University of Zagreb, Croatia.
00011  *
00012  */
00013 
00014 #ifndef BOOST_NUMERIC_BINDINGS_TRAITS_DETAIL_UTILS_HPP
00015 #define BOOST_NUMERIC_BINDINGS_TRAITS_DETAIL_UTILS_HPP
00016 
00017 // #include <cstring> 
00018 #include <iterator>
00019 #include <boost/numeric/bindings/traits/type_traits.hpp>
00020 
00021 namespace boost { namespace numeric { namespace bindings { namespace traits {
00022 
00023   namespace detail {
00024 
00025     // complex array => real & imaginary arrays
00026     template <typename CIt, typename RIt> 
00027     inline 
00028     void disentangle (CIt c, CIt c_end, RIt rr, RIt ri) {
00029       for (; c != c_end; ++c, ++rr, ++ri) {
00030         *rr = traits::real (*c); 
00031         *ri = traits::imag (*c); 
00032       }
00033     }
00034     // real & imaginary arrays => complex array
00035     template <typename RIt, typename CIt> 
00036     inline 
00037     void interlace (RIt r, RIt r_end, RIt ri, CIt c) {
00038       typedef typename std::iterator_traits<CIt>::value_type cmplx_t;
00039 #ifdef BOOST_NUMERIC_BINDINGS_BY_THE_BOOK
00040       for (; r != r_end; ++r, ++ri, ++c) 
00041         *c = cmplx_t (*r, *ri); 
00042 #else
00043       typedef typename type_traits<cmplx_t>::real_type real_t; 
00044       real_t *cp = reinterpret_cast<real_t*> (&*c);
00045       for (; r != r_end; ++r, ++ri) {
00046         *cp = *r; ++cp;
00047         *cp = *ri; ++cp;
00048       }
00049 #endif 
00050     }    
00051 
00052 
00053     // converts real/complex to int
00054     inline int to_int (float f) { return static_cast<int> (f); }
00055     inline int to_int (double d) { return static_cast<int> (d); }
00056     inline int to_int (traits::complex_f const& cf) { 
00057       return static_cast<int> (traits::real (cf)); 
00058     }
00059     inline int to_int (traits::complex_d const& cd) { 
00060       return static_cast<int> (traits::real (cd)); 
00061     }
00062 
00063   }
00064 
00065 }}}}
00066 
00067 #endif 

Generated on Wed Nov 23 19:00:56 2011 for FreeCAD by  doxygen 1.6.1