$extrastylesheet
Olena  User documentation 2.1
An Image Processing Platform
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
internal/check/image_fastest.hh
1 // Copyright (C) 2007, 2008, 2009, 2011, 2012, 2013 EPITA Research and
2 // Development Laboratory (LRDE)
3 //
4 // This file is part of Olena.
5 //
6 // Olena is free software: you can redistribute it and/or modify it under
7 // the terms of the GNU General Public License as published by the Free
8 // Software Foundation, version 2 of the License.
9 //
10 // Olena is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 // General Public License for more details.
14 //
15 // You should have received a copy of the GNU General Public License
16 // along with Olena. If not, see <http://www.gnu.org/licenses/>.
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
20 // instantiate templates or use macros or inline functions from this
21 // file, or you compile this file and link it with other files to produce
22 // an executable, this file does not by itself cause the resulting
23 // executable to be covered by the GNU General Public License. This
24 // exception does not however invalidate any other reasons why the
25 // executable file might be covered by the GNU General Public License.
26 
27 #ifndef MLN_CORE_INTERNAL_CHECK_IMAGE_FASTEST_HH
28 # define MLN_CORE_INTERNAL_CHECK_IMAGE_FASTEST_HH
29 
36 
37 # include <mln/metal/bool.hh>
38 # include <mln/core/macros.hh>
39 # include <mln/core/trait/pixter.hh>
40 # include <mln/core/trait/qlf_value.hh>
41 # include <mln/core/internal/force_exact.hh>
42 
43 
44 namespace mln
45 {
46 
47  namespace internal
48  {
49 
50  namespace check
51  {
52 
54  template < typename E, typename B = metal::true_ >
55  struct image_fastest_
56  {
57 
68  template <typename P>
69  unsigned
70  offset_of_point(const P& p) const;
71 
72  protected:
73  image_fastest_();
74  };
75 
76 
77  template <typename E>
78  struct image_fastest_< E, metal::false_ >
79  {
80  // Nothing.
81  };
82 
83 
84 # ifndef MLN_INCLUDE_ONLY
85 
86  template <typename E, typename B>
87  inline
88  image_fastest_<E,B>::image_fastest_()
89  {
90  typedef mln_site(E) site;
91  typedef mln_psite(E) psite;
92  typedef mln_delta(psite) dpsite;
93 
94 
95  typedef mln_fwd_pixter(E) fwd_pixter;
96  typedef mln_bkd_pixter(E) bkd_pixter;
97 
98  int (E::*m1)(const dpsite&) const = & E::delta_offset;
99  (void) m1;
100  site (E::*m2)(unsigned) const = & E::point_at_offset;
101  (void) m2;
102  unsigned (E::*m3)() const = & E::border;
103  (void) m3;
104 
105  typedef mln_value(E) value;
106 
107  mln_qlf_value(E)* (E::*m4)() = & E::buffer;
108  (void) m4;
109  const value* (E::*m5)() const = & E::buffer;
110  (void) m5;
111 
112  typedef mln_rvalue(E) rvalue;
113  typedef mln_lvalue(E) lvalue;
114 
115  rvalue (E::*m6)(unsigned) const = & E::element;
116  (void) m6;
117  lvalue (E::*m7)(unsigned) = & E::element;
118  (void) m7;
119 
120  unsigned (E::*m8)() const = & E::nelements;
121  (void) m8;
122 
123 # if (defined(__GNUC__) && __GNUC__ >= 3) && !defined(__INTEL_COMPILER)
124  unsigned (E::*m9)(const psite& p) const = & E::offset_of_point;
125  (void) m9;
126 # endif
127 
128  // FIXME: how to check that qixter are defined when W is unknown!
129  }
130 
131  template <typename E, typename B>
132  template <typename P>
133  inline
134  unsigned
135  image_fastest_<E,B>::offset_of_point(const P& p) const
136  {
137  const E* this_ = & internal::force_exact<E>(*this);
138  mln_precondition(this_->is_valid());
139  mln_precondition(this_->has(p));
140 
141  unsigned i = & this_->operator()(p) - this_->buffer();
142  mln_postcondition(p == this_->point_at_offset(i));
143  return i;
144  }
145 
146 # endif // ! MLN_INCLUDE_ONLY
147 
148  } // end of namespace mln::internal::check
149 
150  } // end of namespace mln::internal
151 
152 } // end of namespace mln
153 
154 
155 #endif // ! MLN_CORE_INTERNAL_CHECK_IMAGE_FASTEST_HH