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