00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012 #ifndef MTL_SHIFT_BLOCKS_DETAIL_INCLUDE
00013 #define MTL_SHIFT_BLOCKS_DETAIL_INCLUDE
00014
00015 #include <algorithm>
00016 #include <boost/numeric/mtl/utility/exception.hpp>
00017
00018 namespace mtl { namespace operations { namespace detail {
00019
00020
00021
00022
00023 template <typename Size, typename Starts, typename NewStarts, typename Ends, typename Data>
00024 inline void copy_blocks_forward(Size& i, Size blocks, Starts const& starts, NewStarts const& new_starts,
00025 Ends const& ends, Data& data)
00026 {
00027 using std::copy;
00028
00029
00030 for (; i < blocks && starts[i] >= new_starts[i]; ++i)
00031 if (starts[i] > new_starts[i])
00032 copy(&data[0] + starts[i], &data[0] + ends[i], &data[0] + new_starts[i]);
00033 }
00034
00035 template <typename Size, typename Starts, typename NewStarts, typename Ends, typename Data>
00036 inline void copy_blocks_backward(Size& i, Size blocks, Starts const& starts, NewStarts const& new_starts,
00037 Ends const& ends, Data& data)
00038 {
00039 using std::copy;
00040 using std::copy_backward;
00041
00042 Size first = i;
00043
00044 while (i < blocks && starts[i] < new_starts[i]) ++i;
00045
00046 for (Size j = i; j-- > first; )
00047 if (ends[j] <= new_starts[j])
00048 copy(&data[0] + starts[j], &data[0] + ends[j], &data[0] + new_starts[j]);
00049 else
00050 copy_backward(&data[0] + starts[j], &data[0] + ends[j], &data[0] + (new_starts[j]+ends[j]-starts[j]));
00051 }
00052
00053 }}}
00054
00055 #endif // MTL_SHIFT_BLOCKS_DETAIL_INCLUDE