Milena (Olena)  User documentation 2.0a Id
 All Classes Namespaces Functions Variables Typedefs Enumerator Groups Pages
point2d.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_ALIAS_POINT2D_HH
27 # define MLN_CORE_ALIAS_POINT2D_HH
28 
33 
34 # include <mln/core/point.hh>
35 // For site_const_impl and site_mutable_impl.
36 # include <mln/core/concept/site_proxy.hh>
37 # include <mln/core/internal/force_exact.hh>
38 
39 
40 namespace mln
41 {
42 
46 
50 
51 
52  namespace internal
53  {
54 
55  // Specialization.
56 
57  template <typename C, typename E>
58  struct subject_impl< const point<grid::square, C>, E >
59  {
60  typedef C coord;
61  enum { dim = 2 };
62 
63  typedef const C& row_t;
64  const C& row() const;
65 
66  typedef const C& col_t;
67  const C& col() const;
68 
69  const C& operator[](unsigned i) const;
70  const C& last_coord() const;
71  private:
72  const E& exact_() const;
73  };
74 
75 
76  // Specialization for point<M,C>.
77 
78  template <typename C, typename E>
79  struct subject_impl< point<grid::square, C>, E > :
80  subject_impl< const point<grid::square, C>, E >
81  {
82  private:
83  typedef subject_impl< const point<grid::square, C>, E > super_;
84  E& exact_();
85  public:
86  using super_::row;
87  C& row();
88  using super_::col;
89  C& col();
90  using super_::operator[];
91  C& operator[](unsigned i);
92  };
93 
94 
95 
96 # ifndef MLN_INCLUDE_ONLY
97 
98  // subject_impl
99 
100  template <typename C, typename E>
101  inline
102  const C&
103  subject_impl< const point<grid::square, C>, E >::row() const
104  {
105  return exact_().get_subject().row();
106  }
107 
108  template <typename C, typename E>
109  inline
110  const C&
111  subject_impl< const point<grid::square, C>, E >::col() const
112  {
113  return exact_().get_subject().col();
114  }
115 
116  template <typename C, typename E>
117  inline
118  const C&
119  subject_impl< const point<grid::square, C>, E >::operator[](unsigned i) const
120  {
121  mln_precondition(i < 2);
122  return exact_().get_subject()[i];
123  }
124 
125  template <typename C, typename E>
126  inline
127  const C&
128  subject_impl< const point<grid::square, C>, E >::last_coord() const
129  {
130  return this->col();
131  }
132 
133  template <typename C, typename E>
134  inline
135  const E&
136  subject_impl< const point<grid::square, C>, E >::exact_() const
137  {
138  return internal::force_exact<const E>(*this);
139  }
140 
141  // subject_impl
142 
143  template <typename C, typename E>
144  inline
145  C&
146  subject_impl< point<grid::square, C>, E >::row()
147  {
148  return exact_().get_subject().row();
149  }
150 
151  template <typename C, typename E>
152  inline
153  C&
154  subject_impl< point<grid::square, C>, E >::col()
155  {
156  return exact_().get_subject().col();
157  }
158 
159  template <typename C, typename E>
160  inline
161  C&
162  subject_impl< point<grid::square, C>, E >::operator[](unsigned i)
163  {
164  mln_precondition(i < 2);
165  return exact_().get_subject()[i];
166  }
167 
168  template <typename C, typename E>
169  inline
170  E&
171  subject_impl< point<grid::square, C>, E >::exact_()
172  {
173  return internal::force_exact<E>(*this);
174  }
175 
176 # endif // ! MLN_INCLUDE_ONLY
177 
178  } // end of namespace mln::internal
179 
180 
181 } // end of namespace mln
182 
183 
184 # include <mln/core/alias/dpoint2d.hh>
185 
186 
187 #endif // ! MLN_CORE_ALIAS_POINT2D_HH