Milena (Olena)
User documentation 2.0a Id
|
00001 // Copyright (C) 2007, 2008, 2009 EPITA Research and Development Laboratory (LRDE) 00002 // 00003 // This file is part of Olena. 00004 // 00005 // Olena is free software: you can redistribute it and/or modify it under 00006 // the terms of the GNU General Public License as published by the Free 00007 // Software Foundation, version 2 of the License. 00008 // 00009 // Olena is distributed in the hope that it will be useful, 00010 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00011 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00012 // General Public License for more details. 00013 // 00014 // You should have received a copy of the GNU General Public License 00015 // along with Olena. If not, see <http://www.gnu.org/licenses/>. 00016 // 00017 // As a special exception, you may use this file as part of a free 00018 // software project without restriction. Specifically, if other files 00019 // instantiate templates or use macros or inline functions from this 00020 // file, or you compile this file and link it with other files to produce 00021 // an executable, this file does not by itself cause the resulting 00022 // executable to be covered by the GNU General Public License. This 00023 // exception does not however invalidate any other reasons why the 00024 // executable file might be covered by the GNU General Public License. 00025 00026 #ifndef MLN_CORE_CONCEPT_POINT_SITE_HH 00027 # define MLN_CORE_CONCEPT_POINT_SITE_HH 00028 00034 # include <mln/core/concept/object.hh> 00035 # include <mln/core/concept/delta_point_site.hh> 00036 # include <mln/core/grids.hh> 00037 # include <mln/trait/all.hh> 00038 00039 00040 00041 namespace mln 00042 { 00043 00044 // Fwd decls. 00045 template <typename E> struct Point_Site; 00046 00047 00048 00049 namespace trait 00050 { 00051 00052 template < typename P, typename D > 00053 struct set_binary_< op::plus, 00054 mln::Point_Site, P, mln::Delta_Point_Site, D > 00055 { 00056 typedef mln_point(P) ret; 00057 }; 00058 00059 template < typename P, typename D > 00060 struct set_binary_< op::minus, 00061 mln::Point_Site, P, mln::Delta_Point_Site, D > 00062 { 00063 typedef mln_point(P) ret; 00064 }; 00065 00066 template < typename L, typename R > 00067 struct set_binary_< op::minus, 00068 mln::Point_Site, L, mln::Point_Site, R > 00069 { 00070 typedef mln_dpoint(L) ret; 00071 }; 00072 00073 } // end of namespace mln::trait 00074 00075 00076 00077 00079 template <> 00080 struct Point_Site<void> 00081 { 00082 typedef Object<void> super; 00083 }; 00084 00085 00105 template <typename E> 00106 struct Point_Site : public Object<E> 00107 { 00108 typedef Point_Site<void> category; 00109 00110 /* 00111 enum { dim }; 00112 typedef mesh; 00113 00114 typedef point; 00115 typedef dpoint; 00116 typedef coord; 00117 00118 const point& to_point() const; 00119 00120 coord operator[](unsigned i) const; 00121 */ 00122 00123 protected: 00124 Point_Site(); 00125 }; 00126 00127 00142 template <typename L, typename R> 00143 bool operator==(const Point_Site<L>& lhs, const Point_Site<R>& rhs); 00144 00145 00167 template <typename L, typename R> 00168 mln_dpoint(L) 00169 operator-(const Point_Site<L>& lhs, const Point_Site<R>& rhs); 00170 00171 00185 template <typename P, typename D> 00186 mln_point(P) 00187 operator+(const Point_Site<P>& p, const Delta_Point_Site<D>& dp); 00189 00190 00204 template <typename P, typename D> 00205 mln_point(P) 00206 operator-(const Point_Site<P>& p, const Delta_Point_Site<D>& dp); 00208 00209 00219 template <typename P> 00220 std::ostream& operator<<(std::ostream& ostr, const Point_Site<P>& p); 00221 00222 00223 00224 00225 # ifndef MLN_INCLUDE_ONLY 00226 00227 template <typename E> 00228 inline 00229 Point_Site<E>::Point_Site() 00230 { 00231 int dim = E::dim; 00232 mln_invariant(dim > 0); 00233 dim = 0; 00234 typedef mln_mesh(E) mesh; 00235 typedef mln_point(E) point; 00236 typedef mln_dpoint(E) dpoint; 00237 typedef mln_coord(E) coord; 00238 const point& (E::*m1)() const = & E::to_point; 00239 m1 = 0; 00240 coord (E::*m2)(unsigned i) const = & E::operator[]; 00241 m2 = 0; 00242 } 00243 00244 00245 // Operators. 00246 00247 // FIXME: Remove, or factor in a lower class (Théo removed it from 00248 // the cleanup-2008 branch). 00249 template <typename L, typename R> 00250 inline 00251 bool operator==(const Point_Site<L>& lhs_, const Point_Site<R>& rhs_) 00252 { 00253 mln::metal::bool_<(int(L::dim) == int(R::dim))>::check(); 00254 const L& lhs = exact(lhs_); 00255 const R& rhs = exact(rhs_); 00256 for (unsigned i = 0; i < L::dim; ++i) 00257 if (lhs[i] != rhs[i]) 00258 return false; 00259 return true; 00260 } 00261 00262 // FIXME: Remove, or factor in a lower class (Théo removed it from 00263 // the cleanup-2008 branch). 00264 template <typename L, typename R> 00265 inline 00266 mln_dpoint(L) // FIXME: promote! 00267 operator-(const Point_Site<L>& lhs_, const Point_Site<R>& rhs_) 00268 { 00269 mln::metal::bool_<(int(L::dim) == int(R::dim))>::check(); 00270 const L& lhs = exact(lhs_); 00271 const R& rhs = exact(rhs_); 00272 mln_dpoint(L) tmp; 00273 for (unsigned i = 0; i < L::dim; ++i) 00274 tmp[i] = lhs[i] - rhs[i]; 00275 mln_postcondition(rhs_ + tmp == lhs_); 00276 return tmp; 00277 } 00278 00279 template <typename P, typename D> 00280 inline 00281 mln_point(P) // FIXME: promote! 00282 operator+(const Point_Site<P>& p_, const Delta_Point_Site<D>& dp_) 00283 { 00284 mln::metal::bool_<(int(P::dim) == int(D::dim))>::check(); 00285 const P& p = exact(p_); 00286 const D& dp = exact(dp_); 00287 mln_point(P) tmp; 00288 for (unsigned i = 0; i < P::dim; ++i) 00289 tmp[i] = p[i] + dp[i]; 00290 return tmp; 00291 } 00292 00293 template <typename P, typename D> 00294 inline 00295 mln_point(P) // FIXME: promote! 00296 operator-(const Point_Site<P>& p_, const Delta_Point_Site<D>& dp_) 00297 { 00298 mln::metal::bool_<(int(P::dim) == int(D::dim))>::check(); 00299 const P& p = exact(p_); 00300 const D& dp = exact(dp_); 00301 mln_point(P) tmp; 00302 for (unsigned i = 0; i < P::dim; ++i) 00303 tmp[i] = p[i] - dp[i]; 00304 return tmp; 00305 } 00306 00307 // FIXME: We shall not rely on a point object associted to the point 00308 // site! (Such an object does not always exist.) 00309 template <typename P> 00310 inline 00311 std::ostream& operator<<(std::ostream& ostr, const Point_Site<P>& p_) 00312 { 00313 const P& p = exact(p_); 00314 ostr << '('; 00315 for (unsigned i = 0; i < P::dim; ++i) 00316 ostr << p[i] << (i == P::dim - 1 ? ')' : ','); 00317 return ostr; 00318 } 00319 00320 # endif // ! MLN_INCLUDE_ONLY 00321 00322 } // end of namespace mln 00323 00324 00325 #endif // ! MLN_CORE_CONCEPT_POINT_SITE_HH