fwd.hh 3.22 KB
Newer Older
1
2
// Copyright (C) 2007, 2008, 2009, 2011 EPITA Research and Development
// Laboratory (LRDE)
Thierry Geraud's avatar
Thierry Geraud committed
3
//
4
// This file is part of Olena.
Thierry Geraud's avatar
Thierry Geraud committed
5
//
6
7
8
9
10
// Olena is free software: you can redistribute it and/or modify it under
// the terms of the GNU General Public License as published by the Free
// Software Foundation, version 2 of the License.
//
// Olena is distributed in the hope that it will be useful,
Thierry Geraud's avatar
Thierry Geraud committed
11
12
13
14
15
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
// General Public License for more details.
//
// You should have received a copy of the GNU General Public License
16
// along with Olena.  If not, see <http://www.gnu.org/licenses/>.
Thierry Geraud's avatar
Thierry Geraud committed
17
18
//
// As a special exception, you may use this file as part of a free
19
// software project without restriction.  Specifically, if other files
Thierry Geraud's avatar
Thierry Geraud committed
20
// instantiate templates or use macros or inline functions from this
21
22
23
24
25
// file, or you compile this file and link it with other files to produce
// an executable, this file does not by itself cause the resulting
// executable to be covered by the GNU General Public License.  This
// exception does not however invalidate any other reasons why the
// executable file might be covered by the GNU General Public License.
Thierry Geraud's avatar
Thierry Geraud committed
26

Thierry Geraud's avatar
Thierry Geraud committed
27
28
29
#ifndef MLN_CANVAS_BROWSING_FWD_HH
# define MLN_CANVAS_BROWSING_FWD_HH

30
/// \file
31
32
///
/// Canvas for forward browsing.
Thierry Geraud's avatar
Thierry Geraud committed
33

Thierry Geraud's avatar
Thierry Geraud committed
34
35
# include <mln/core/concept/browsing.hh>
# include <mln/core/concept/image.hh>
Thierry Geraud's avatar
Thierry Geraud committed
36
37


Thierry Geraud's avatar
Thierry Geraud committed
38
namespace mln
Thierry Geraud's avatar
Thierry Geraud committed
39
40
{

Thierry Geraud's avatar
Thierry Geraud committed
41
  namespace canvas
Thierry Geraud's avatar
Thierry Geraud committed
42
43
  {

Thierry Geraud's avatar
Thierry Geraud committed
44
45
    namespace browsing
    {
Thierry Geraud's avatar
Thierry Geraud committed
46

47
      /// Canvas for forward browsing
48
49
50
51
52
53
54
55
56
57
      /*!
       * This canvas browse all the points of an image 'input' of type
       * 'I' from left to right and from top to bottom
       *
       * The fonctor should provide (In addition of 'I' and 'input')
       * three methods :
       *   - init() : Will be called at the beginning.
       *   - next() : Will be called at each point 'p' (also provided by
       * the functor).
       *   - final(): Will be called at the end.
Thierry Geraud's avatar
Thierry Geraud committed
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
       *
       * F shall feature: \n
       * { \n
       *   --- as typedef: \n
       *   I; \n
       *   --as attributes: \n
       *   input; \n
       *   p; \n
       *   --- as method: \n
       *   void init(); \n
       *   void next(); \n
       *   void final(); \n
       * } \n
       *
       */
      struct fwd_t : public Browsing< fwd_t >
      {
75
76
77
78
	// This default constructor is needed for compilation with gcc
	// 4.6.0, gcc 4.6.1 and Clang.
	fwd_t();

Thierry Geraud's avatar
Thierry Geraud committed
79
80
	template <typename F>
	void operator()(F& f) const;
81
      };
Thierry Geraud's avatar
Thierry Geraud committed
82

83
      extern const fwd_t fwd;
Thierry Geraud's avatar
Thierry Geraud committed
84
85
86

# ifndef MLN_INCLUDE_ONLY

87
88
#  ifndef MLN_WO_GLOBAL_VARS

89
90
      const fwd_t fwd;

91
92
93
94
#  endif // ! MLN_WO_GLOBAL_VARS


      inline
95
96
97
98
      fwd_t::fwd_t()
      {
      }

Thierry Geraud's avatar
Thierry Geraud committed
99
      template <typename F>
100
      inline
Thierry Geraud's avatar
Thierry Geraud committed
101
102
103
      void
      fwd_t::operator()(F& f) const
      {
104
	trace::entering("canvas::browsing::fwd");
105
	mln_precondition(f.input.is_valid());
Thierry Geraud's avatar
Thierry Geraud committed
106
107
108
109
110
111
112
113
114
	typedef typename F::I I;
	mln_fwd_piter(I) p(f.input.domain());
	f.init();
	for_all(p)
	  {
	    f.p = p;
	    f.next();
	  }
	f.final();
115
	trace::exiting("canvas::browsing::fwd");
Thierry Geraud's avatar
Thierry Geraud committed
116
117
118
119
120
121
122
123
124
      }

# endif // ! MLN_INCLUDE_ONLY

    } // end of namespace mln::canvas::browsing

  } // end of namespace mln::canvas

} // end of namespace mln
Thierry Geraud's avatar
Thierry Geraud committed
125
126


Thierry Geraud's avatar
Thierry Geraud committed
127
#endif // ! MLN_CANVAS_BROWSING_FWD_HH