[ 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
6namespace vigra {
7
8// test and accomodate for functors that require extra passes over arrays / etc.
9
10namespace detail {
11
12template <bool>
13struct extra_passes_selector
14{
15 template <class Inspector, class Functor>
16 static void
17 call(Inspector, Functor &) {}
18};
19template <>
20struct 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
40template <class T>
41struct 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
46template <class Functor, bool extra = has_extra_passes<Functor>::value>
47struct get_extra_passes
48 : public VigraFalseType
49{
50 void sync(Functor &) {}
51};
52
53template <class Functor>
54struct 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
66template <class Inspector, class Functor>
67inline
68void
69extra_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