Milena (Olena)  User documentation 2.0a Id
 All Classes Namespaces Functions Variables Typedefs Enumerator Groups Pages
delta_point_site.hh
1 // Copyright (C) 2007, 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_CONCEPT_DELTA_POINT_SITE_HH
27 # define MLN_CORE_CONCEPT_DELTA_POINT_SITE_HH
28 
34 # include <mln/core/concept/object.hh>
35 # include <mln/core/grids.hh>
36 # include <mln/trait/all.hh>
37 
38 
39 namespace mln
40 {
41 
42  // Fwd decl.
43  template <typename E> struct Delta_Point_Site;
44 
45 
46 
47  namespace trait
48  {
49 
50  template < typename L, typename R >
51  struct set_binary_< op::plus,
53  {
54  typedef mln_dpoint(L) ret;
55  };
56 
57  template < typename L, typename R >
58  struct set_binary_< op::minus,
59  mln::Delta_Point_Site, L, mln::Delta_Point_Site, R >
60  {
61  typedef mln_dpoint(L) ret;
62  };
63 
64  } // end of namespace mln::trait
65 
66 
67 
69  template <>
70  struct Delta_Point_Site<void>
71  {
72  typedef Object<void> super;
73  };
74 
75 
78  template <typename E>
79  struct Delta_Point_Site : public Object<E>
80  {
82 
83  /*
84  enum { dim };
85  typedef mesh;
86 
87  typedef point;
88  typedef dpoint;
89  typedef coord;
90 
91  const dpoint& to_dpoint() const;
92  coord operator[](unsigned i) const;
93  */
94 
95  protected:
96  Delta_Point_Site();
97  };
98 
99 
100 
101  // Operators.
102 
103  template <typename D>
104  std::ostream&
105  operator<<(std::ostream& ostr, const Delta_Point_Site<D>& dp);
106 
107 
108  template <typename L, typename R>
109  bool
110  operator==(const Delta_Point_Site<L>& lhs, const Delta_Point_Site<R>& rhs);
111 
112  template <typename L, typename R>
113  bool
114  operator<(const Delta_Point_Site<L>& lhs, const Delta_Point_Site<R>& rhs);
115 
116 
117  template <typename L, typename R>
118  mln_dpoint(L) // FIXME: promote!
119  operator+(const Delta_Point_Site<L>& lhs, const Delta_Point_Site<R>& rhs);
120 
121  template <typename L, typename R>
122  mln_dpoint(L) // FIXME: promote!
123  operator-(const Delta_Point_Site<L>& lhs, const Delta_Point_Site<R>& rhs);
124 
125 
126 
127 
128 # ifndef MLN_INCLUDE_ONLY
129 
130  template <typename E>
131  inline
133  {
134  int dim = E::dim;
135  mln_invariant(dim > 0);
136  dim = 0;
137  typedef mln_mesh(E) mesh;
138  typedef mln_point(E) point;
139  typedef mln_dpoint(E) dpoint;
140  typedef mln_coord(E) coord;
141  const dpoint& (E::*m1)() const = & E::to_dpoint;
142  m1 = 0;
143  coord (E::*m2)(unsigned i) const = & E::operator[];
144  m2 = 0;
145  }
146 
147 
148  template <typename D>
149  inline
150  std::ostream& operator<<(std::ostream& ostr, const Delta_Point_Site<D>& dp_)
151  {
152  const D& dp = exact(dp_);
153  ostr << '(';
154  for (unsigned i = 0; i < D::dim; ++i)
155  ostr << dp[i] << (i == D::dim - 1 ? ')' : ',');
156  return ostr;
157  }
158 
159 
160  template <typename L, typename R>
161  inline
162  bool operator==(const Delta_Point_Site<L>& lhs_, const Delta_Point_Site<R>& rhs_)
163  {
164  mln::metal::bool_<(int(L::dim) == int(R::dim))>::check();
165  const L& lhs = exact(lhs_);
166  const R& rhs = exact(rhs_);
167  for (unsigned i = 0; i < L::dim; ++i)
168  if (lhs[i] != rhs[i])
169  return false;
170  return true;
171  }
172 
173  template <typename L, typename R>
174  inline
175  bool operator<(const Delta_Point_Site<L>& lhs_, const Delta_Point_Site<R>& rhs_)
176  {
177  mln::metal::bool_<(int(L::dim) == int(R::dim))>::check();
178  const L& lhs = exact(lhs_);
179  const R& rhs = exact(rhs_);
180  for (unsigned i = 0; i < L::dim; ++i)
181  {
182  if (lhs[i] == rhs[i])
183  continue;
184  return lhs[i] < rhs[i];
185  }
186  return false;
187  }
188 
189  template <typename L, typename R>
190  inline
191  mln_dpoint(L) // FIXME: promote!
192  operator+(const Delta_Point_Site<L>& lhs_, const Delta_Point_Site<R>& rhs_)
193  {
194  mln::metal::bool_<(int(L::dim) == int(R::dim))>::check();
195  const L& lhs = exact(lhs_);
196  const R& rhs = exact(rhs_);
197  mln_dpoint(L) tmp;
198  for (unsigned i = 0; i < L::dim; ++i)
199  tmp[i] = lhs[i] + rhs[i];
200  return tmp;
201  }
202 
203  template <typename L, typename R>
204  inline
205  mln_dpoint(L) // FIXME: promote!
206  operator-(const Delta_Point_Site<L>& lhs_, const Delta_Point_Site<R>& rhs_)
207  {
208  mln::metal::bool_<(int(L::dim) == int(R::dim))>::check();
209  const L& lhs = exact(lhs_);
210  const R& rhs = exact(rhs_);
211  mln_dpoint(L) tmp;
212  for (unsigned i = 0; i < L::dim; ++i)
213  tmp[i] = lhs[i] - rhs[i];
214  return tmp;
215  }
216 
217 # endif // ! MLN_INCLUDE_ONLY
218 
219 } // end of namespace mln
220 
221 
222 #endif // ! MLN_CORE_CONCEPT_DELTA_POINT_SITE_HH