00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012 #ifndef MTL_FOR_EACH_INCLUDE
00013 #define MTL_FOR_EACH_INCLUDE
00014
00015 namespace mtl { namespace recursion {
00016
00017
00018 template <typename Matrix, typename Function, typename BaseCaseTest>
00019 void for_each(matrix::recursator<Matrix> const& recursator, Function const& f, BaseCaseTest const& is_base)
00020 {
00021 if (recursator.is_empty())
00022 return;
00023
00024 if (is_base(recursator)) {
00025 f(*recursator);
00026 return;
00027 }
00028
00029 for_each(recursator.north_west(), f, is_base);
00030 for_each(recursator.south_west(), f, is_base);
00031 for_each(recursator.north_east(), f, is_base);
00032 for_each(recursator.south_east(), f, is_base);
00033 }
00034
00035
00036
00037 template <typename Matrix, typename Function, typename BaseCaseTest>
00038 void for_each(matrix::recursator<Matrix>& recursator, Function const& f, BaseCaseTest const& is_base)
00039 {
00040 typedef matrix::recursator<Matrix> recursator_type;
00041
00042 if (recursator.is_empty())
00043 return;
00044
00045 if (is_base(recursator)) {
00046 f(recursator.get_value());
00047 return;
00048 }
00049
00050 recursator_type tmp_nw(recursator.north_west()), tmp_sw(recursator.south_west()),
00051 tmp_ne(recursator.north_east()), tmp_se(recursator.south_east());
00052 for_each(tmp_nw, f, is_base);
00053 for_each(tmp_sw, f, is_base);
00054 for_each(tmp_ne, f, is_base);
00055 for_each(tmp_se, f, is_base);
00056 }
00057
00058
00059 }}
00060
00061
00062 #endif // MTL_FOR_EACH_INCLUDE