$extrastylesheet
Olena  User documentation 2.1
An Image Processing Platform
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
element.hh
1 // Copyright (C) 2009, 2010, 2011 EPITA Research and Development
2 // 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_OPT_ELEMENT_HH
28 # define MLN_OPT_ELEMENT_HH
29 
33 
34 # include <mln/core/concept/image.hh>
35 # include <mln/trait/images.hh>
36 
37 namespace mln
38 {
39 
40  namespace opt
41  {
42 
43  template <typename I>
44  inline
45  mln_rvalue(I) element(const Image<I>& ima, unsigned index);
46 
47  template <typename I>
48  inline
49  mln_lvalue(I) element(Image<I>& ima, unsigned index);
50 
51  template <typename I>
52  inline
53  unsigned nelements(const Image<I>& ima);
54 
55 
56 # ifndef MLN_INCLUDE_ONLY
57 
58  namespace impl
59  {
60 
61  template <typename I>
62  inline
63  mln_rvalue(I) element_impl(trait::image::category::domain_morpher,
64  const Image<I>& ima, unsigned index)
65  {
66  (void) index;
67  return element(*exact(ima).delegatee_());
68  }
69 
70  template <typename I>
71  inline
72  mln_rvalue(I) element_impl(trait::image::category::any,
73  const Image<I>& ima, unsigned index)
74  {
75  mlc_and(mlc_is(mln_trait_image_value_storage(I),
76  trait::image::value_storage::one_block),
77  mlc_is(mln_trait_image_value_access(I),
78  trait::image::value_access::direct))::check();
79 
80  return exact(ima).element(index);
81  }
82 
83 
84  template <typename I>
85  inline
86  mln_lvalue(I) element_impl(trait::image::category::domain_morpher,
87  Image<I>& ima, unsigned index)
88  {
89  (void) index;
90  return element(*exact(ima).delegatee_());
91  }
92 
93  template <typename I>
94  inline
95  mln_lvalue(I) element_impl(trait::image::category::any,
96  Image<I>& ima, unsigned index)
97  {
98  mlc_and(mlc_is(mln_trait_image_value_storage(I),
99  trait::image::value_storage::one_block),
100  mlc_is(mln_trait_image_value_access(I),
101  trait::image::value_access::direct))::check();
102 
103  return exact(ima).element(index);
104  }
105 
106 
107 
108 
109  template <typename I>
110  inline
111  unsigned nelements_impl(trait::image::category::domain_morpher,
112  const Image<I>& ima)
113  {
114  return nelements(*exact(ima).delegatee_());
115  }
116 
117  template <typename I>
118  inline
119  unsigned nelements_impl(trait::image::category::any,
120  const Image<I>& ima)
121  {
122  mlc_is(mln_trait_image_value_storage(I),
123  trait::image::value_storage::one_block)::check();
124 
125  return exact(ima).nelements();
126  }
127 
128 
129 
130 
131 
132 
133  } // end of namespace mln::opt::impl
134 
135 
136  template <typename I>
137  inline
138  mln_rvalue(I) element(const Image<I>& ima, unsigned index)
139  {
140  return impl::element_impl(mln_trait_image_category(I)(), ima, index);
141  }
142 
143  template <typename I>
144  inline
145  mln_lvalue(I) element(Image<I>& ima, unsigned index)
146  {
147  return impl::element_impl(mln_trait_image_category(I)(), ima, index);
148  }
149 
150 
151  template <typename I>
152  inline
153  unsigned nelements(const Image<I>& ima)
154  {
155  return impl::nelements_impl(mln_trait_image_category(I)(), ima);
156  }
157 
158 # endif // ! MLN_INCLUDE_ONLY
159 
160  } // end of namespace mln::opt
161 
162 } // end of namespace mln
163 
164 
165 #endif // ! MLN_OPT_ELEMENT_HH