core/vnl/vnl_copy.cxx
Go to the documentation of this file.
00001 // This is core/vnl/vnl_copy.cxx
00002 #ifdef VCL_NEEDS_PRAGMA_INTERFACE
00003 #pragma implementation
00004 #endif
00005 //:
00006 // \file
00007 // \author fsm
00008 
00009 #include "vnl_copy.h"
00010 #include <vcl_cassert.h>
00011 #include <vcl_complex.h>
00012 #include <vnl/vnl_vector.h>
00013 #include <vnl/vnl_matrix.h>
00014 #include <vnl/vnl_diag_matrix.h>
00015 
00016 //-------------------------------------------------------------------
00017 
00018 template <class S, class T>
00019 void vnl_copy(S const *src, T *dst, unsigned n)
00020 {
00021   for (unsigned int i=0; i<n; ++i)
00022     dst[i] = T(src[i]);
00023 }
00024 
00025 template <class S, class T>
00026 void vnl_copy(S const &src, T &dst)
00027 {
00028   assert(src.size() == dst.size());
00029   vnl_copy(src.begin(), dst.begin(), src.size());
00030 }
00031 
00032 //------------------------------------------------------------------------
00033 
00034 // C arrays
00035 #define VNL_COPY_INSTANTIATE0(S, T) \
00036 template void vnl_copy(S const *, T *, unsigned )
00037 
00038 VNL_COPY_INSTANTIATE0(float, double);
00039 VNL_COPY_INSTANTIATE0(double, float);
00040 VNL_COPY_INSTANTIATE0(double, long double);
00041 #ifndef __hppa // assembler bug on HP?
00042 VNL_COPY_INSTANTIATE0(long double, double);
00043 #endif
00044 
00045 #define vnl_copy_macro(S, D) \
00046 VCL_DEFINE_SPECIALIZATION \
00047 void vnl_copy(vcl_complex<S> const *src, vcl_complex<D> *dst, unsigned n) \
00048 { \
00049   for (unsigned int i=0; i<n; ++i) \
00050     dst[i] = vcl_complex<D>((D)vcl_real(src[i]), (D)vcl_imag(src[i])); \
00051 }
00052 
00053 vnl_copy_macro(float, double);
00054 vnl_copy_macro(double, float);
00055 vnl_copy_macro(double, long double);
00056 vnl_copy_macro(long double, double);
00057 #undef vnl_copy_macro
00058 
00059 #define vnl_copy_dumb(S) \
00060 VCL_DEFINE_SPECIALIZATION \
00061 void vnl_copy(S const *src, S *dst, unsigned n) \
00062 { \
00063   for (unsigned int i=0; i<n; ++i) \
00064     dst[i] = src[i]; \
00065 }
00066 
00067 vnl_copy_dumb(float);
00068 vnl_copy_dumb(double);
00069 #undef vnl_copy_dumb
00070 
00071 // vnl_* containers
00072 #define VNL_COPY_INSTANTIATE(S, T) \
00073 template void vnl_copy(vnl_vector<S > const &, vnl_vector<T > &); \
00074 template void vnl_copy(vnl_matrix<S > const &, vnl_matrix<T > &); \
00075 template void vnl_copy(vnl_diag_matrix<S > const &, vnl_diag_matrix<T > &)
00076 
00077 VNL_COPY_INSTANTIATE(float, float);
00078 VNL_COPY_INSTANTIATE(double, double);
00079 
00080 #define VNL_COPY_INSTANTIATE_twoway(S, T) \
00081 VNL_COPY_INSTANTIATE(S, T); \
00082 VNL_COPY_INSTANTIATE(T, S)
00083 
00084 VNL_COPY_INSTANTIATE_twoway(float, double);
00085 VNL_COPY_INSTANTIATE_twoway(vcl_complex<float>, vcl_complex<double>);
00086 #ifndef __hppa // assembler bug on HP?
00087 VNL_COPY_INSTANTIATE_twoway(double, long double);
00088 VNL_COPY_INSTANTIATE_twoway(vcl_complex<double>, vcl_complex<long double>);
00089 #endif