[ VIGRA Homepage | Function Index | Class Index | Namespaces | File List | Main Page ]

inspector_passes.hxx |

1 #ifndef VIGRA_INSPECTOR_PASSES_HXX
2 #define VIGRA_INSPECTOR_PASSES_HXX
3
4 #include "metaprogramming.hxx"
5
6 namespace vigra {
7
8 // test and accomodate for functors that require extra passes over arrays / etc.
9
10 namespace detail {
11
12 template <bool>
13 struct extra_passes_selector
14 {
15 template <class Inspector, class Functor>
16 static void
17 call(Inspector, Functor &) {}
18 };
19 template <>
20 struct extra_passes_selector<true>
21 {
22 template <class Inspector, class Functor_n>
23 static void
24 call_n(Inspector g, Functor_n f_n)
25 {
26 g(f_n);
27 }
28 template <class Inspector, class Functor>
29 static void
30 call(Inspector g, Functor & f)
31 {
32 for (unsigned n = 2; n <= Functor::max_passes; ++n)
33 {
34 f.calc_sync();
35 call_n(g, f.pass_n(n));
36 }
37 }
38 };
39
40 template <class T>
41 struct has_extra_passes : public sfinae_test<T, has_extra_passes>
42 {
43 template <class U> has_extra_passes(U*, typename U::extra_passes* = 0);
44 };
45
46 template <class Functor, bool extra = has_extra_passes<Functor>::value>
47 struct get_extra_passes
48 : public VigraFalseType
49 {
50 void sync(Functor &) {}
51 };
52
53 template <class Functor>
54 struct get_extra_passes<Functor, true>
55 {
56 typedef get_extra_passes extra_passes;
57 static const unsigned max_passes = Functor::max_passes;
58 static const bool value = Functor::max_passes >= 2;
59
60 void sync(Functor & f)
61 {
62 f.calc_sync();
63 }
64 };
65
66 template <class Inspector, class Functor>
67 inline
68 void
69 extra_passes_select(Inspector g, Functor & f)
70 {
71 g(f);
72 extra_passes_selector<get_extra_passes<Functor>::value>::call(g, f);
73 }
74
75 } // namespace detail
76
77 } // namespace vigra
78
79 #endif // VIGRA_INSPECTOR_PASSES_HXX

© Ullrich Köthe (ullrich.koethe@iwr.uni-heidelberg.de) Heidelberg Collaboratory for Image Processing, University of Heidelberg, Germany | html generated using doxygen and Python vigra 1.11.1 (Fri May 19 2017)