00001 #ifndef __FIBER_MULTICOPY_HPP
00002 #define __FIBER_MULTICOPY_HPP
00003
00004 #include "MultiArray.hpp"
00005 #include "Iterator.hpp"
00006
00007 namespace Fiber
00008 {
00009
00010 struct ValueConvert
00011 {
00012 static void copy(unsigned char&result, double value)
00013 {
00014 result = (unsigned char)(0xFF*value);
00015 }
00016
00017 static void copy(unsigned short&result, double value)
00018 {
00019 result = (unsigned short)(0xFFFF*value);
00020 }
00021 };
00022
00023
00024 struct PlainCopyConvert
00025 {
00026 template <class dst, class src>
00027 static void copy(dst&result, src value)
00028 {
00029 result = dst(value);
00030 }
00031
00032 template <class dst, class src>
00033 static void copy(ElementProxy<Iterator<dst> > result, const ElementProxy<Iterator<src> >&value)
00034 {
00035 result = dst(value);
00036 }
00037 };
00038
00039
00045 template <class Dest, class Source, int N, class Converter>
00046 void Copy(MultiArray<N, Dest>&DestArray, const MultiArray<N, Source>&SrcArray, const Converter&C)
00047 {
00048 MultiIndex<3> I;
00049 do
00050 {
00051 C.copy( DestArray[ I ], SrcArray[ I ]);
00052 }
00053 while( I.inc(SrcArray.Size() ) );
00054 }
00055
00056
00057
00063 template <class Dest, class Source, int N, class Converter>
00064 void Copy(MultiArray<N, Dest>&DestArray, const MultiIndex<N>&DestOffset,
00065 const MultiArray<N, Source>&SrcArray, const Converter&C )
00066 {
00067 MultiIndex<N> I;
00068 do
00069 {
00070 C.copy( DestArray[ I+DestOffset ], SrcArray[ I ]);
00071 }
00072 while( I.inc(SrcArray.Size() ) );
00073 }
00074
00080 template <class Dest, class Source, int N, class Converter>
00081 void Copy(MultiArray<N, Dest>&DestArray,
00082 const MultiArray<N, Source>&SrcArray, const MultiIndex<N>&SrcOffset,
00083 const Converter&C )
00084 {
00085 MultiIndex<N> I;
00086 do
00087 {
00088 C.copy( DestArray[ I ], SrcArray[ I+SrcOffset ]);
00089 }
00090 while( I.inc(SrcArray.Size() ) );
00091 }
00092
00098 template <class Dest, class Source, int N, class Converter>
00099 void Copy(MultiArray<N, Dest>&DestArray, const MultiIndex<N>&DestOffset,
00100 const MultiArray<N, Source>&SrcArray, const MultiIndex<N>&SrcOffset,
00101 const Converter&C)
00102 {
00103 MultiIndex<N> I;
00104 do
00105 {
00106 C.copy( DestArray[ I+DestOffset ], SrcArray[ I+SrcOffset ]);
00107 }
00108 while( I.inc(SrcArray.Size() ) );
00109 }
00110
00114 template <class Dest, class Source, int N, class Converter>
00115 void CopySubset(const MultiIndex<N>&HowMany, MultiArray<N, Dest>&DestArray, const MultiIndex<N>&DestOffset,
00116 const MultiArray<N, Source>&SrcArray, const MultiIndex<N>&SrcOffset,
00117 const Converter&C)
00118 {
00119 MultiIndex<N> I;
00120 do
00121 {
00122 C.copy( DestArray[ I+DestOffset ], SrcArray[ I+SrcOffset ]);
00123
00124 }
00125 while( I.inc( HowMany ) );
00126 }
00127
00128 }
00129
00130 #endif
00131