Milena (Olena)
User documentation 2.0a Id
|
00001 // Copyright (C) 2007, 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_DELTA_POINT_SITE_HH 00027 # define MLN_CORE_CONCEPT_DELTA_POINT_SITE_HH 00028 00034 # include <mln/core/concept/object.hh> 00035 # include <mln/core/grids.hh> 00036 # include <mln/trait/all.hh> 00037 00038 00039 namespace mln 00040 { 00041 00042 // Fwd decl. 00043 template <typename E> struct Delta_Point_Site; 00044 00045 00046 00047 namespace trait 00048 { 00049 00050 template < typename L, typename R > 00051 struct set_binary_< op::plus, 00052 mln::Delta_Point_Site, L, mln::Delta_Point_Site, R > 00053 { 00054 typedef mln_dpoint(L) ret; 00055 }; 00056 00057 template < typename L, typename R > 00058 struct set_binary_< op::minus, 00059 mln::Delta_Point_Site, L, mln::Delta_Point_Site, R > 00060 { 00061 typedef mln_dpoint(L) ret; 00062 }; 00063 00064 } // end of namespace mln::trait 00065 00066 00067 00069 template <> 00070 struct Delta_Point_Site<void> 00071 { 00072 typedef Object<void> super; 00073 }; 00074 00075 00078 template <typename E> 00079 struct Delta_Point_Site : public Object<E> 00080 { 00081 typedef Delta_Point_Site<void> category; 00082 00083 /* 00084 enum { dim }; 00085 typedef mesh; 00086 00087 typedef point; 00088 typedef dpoint; 00089 typedef coord; 00090 00091 const dpoint& to_dpoint() const; 00092 coord operator[](unsigned i) const; 00093 */ 00094 00095 protected: 00096 Delta_Point_Site(); 00097 }; 00098 00099 00100 00101 // Operators. 00102 00103 template <typename D> 00104 std::ostream& 00105 operator<<(std::ostream& ostr, const Delta_Point_Site<D>& dp); 00106 00107 00108 template <typename L, typename R> 00109 bool 00110 operator==(const Delta_Point_Site<L>& lhs, const Delta_Point_Site<R>& rhs); 00111 00112 template <typename L, typename R> 00113 bool 00114 operator<(const Delta_Point_Site<L>& lhs, const Delta_Point_Site<R>& rhs); 00115 00116 00117 template <typename L, typename R> 00118 mln_dpoint(L) // FIXME: promote! 00119 operator+(const Delta_Point_Site<L>& lhs, const Delta_Point_Site<R>& rhs); 00120 00121 template <typename L, typename R> 00122 mln_dpoint(L) // FIXME: promote! 00123 operator-(const Delta_Point_Site<L>& lhs, const Delta_Point_Site<R>& rhs); 00124 00125 00126 00127 00128 # ifndef MLN_INCLUDE_ONLY 00129 00130 template <typename E> 00131 inline 00132 Delta_Point_Site<E>::Delta_Point_Site() 00133 { 00134 int dim = E::dim; 00135 mln_invariant(dim > 0); 00136 dim = 0; 00137 typedef mln_mesh(E) mesh; 00138 typedef mln_point(E) point; 00139 typedef mln_dpoint(E) dpoint; 00140 typedef mln_coord(E) coord; 00141 const dpoint& (E::*m1)() const = & E::to_dpoint; 00142 m1 = 0; 00143 coord (E::*m2)(unsigned i) const = & E::operator[]; 00144 m2 = 0; 00145 } 00146 00147 00148 template <typename D> 00149 inline 00150 std::ostream& operator<<(std::ostream& ostr, const Delta_Point_Site<D>& dp_) 00151 { 00152 const D& dp = exact(dp_); 00153 ostr << '('; 00154 for (unsigned i = 0; i < D::dim; ++i) 00155 ostr << dp[i] << (i == D::dim - 1 ? ')' : ','); 00156 return ostr; 00157 } 00158 00159 00160 template <typename L, typename R> 00161 inline 00162 bool operator==(const Delta_Point_Site<L>& lhs_, const Delta_Point_Site<R>& rhs_) 00163 { 00164 mln::metal::bool_<(int(L::dim) == int(R::dim))>::check(); 00165 const L& lhs = exact(lhs_); 00166 const R& rhs = exact(rhs_); 00167 for (unsigned i = 0; i < L::dim; ++i) 00168 if (lhs[i] != rhs[i]) 00169 return false; 00170 return true; 00171 } 00172 00173 template <typename L, typename R> 00174 inline 00175 bool operator<(const Delta_Point_Site<L>& lhs_, const Delta_Point_Site<R>& rhs_) 00176 { 00177 mln::metal::bool_<(int(L::dim) == int(R::dim))>::check(); 00178 const L& lhs = exact(lhs_); 00179 const R& rhs = exact(rhs_); 00180 for (unsigned i = 0; i < L::dim; ++i) 00181 { 00182 if (lhs[i] == rhs[i]) 00183 continue; 00184 return lhs[i] < rhs[i]; 00185 } 00186 return false; 00187 } 00188 00189 template <typename L, typename R> 00190 inline 00191 mln_dpoint(L) // FIXME: promote! 00192 operator+(const Delta_Point_Site<L>& lhs_, const Delta_Point_Site<R>& rhs_) 00193 { 00194 mln::metal::bool_<(int(L::dim) == int(R::dim))>::check(); 00195 const L& lhs = exact(lhs_); 00196 const R& rhs = exact(rhs_); 00197 mln_dpoint(L) tmp; 00198 for (unsigned i = 0; i < L::dim; ++i) 00199 tmp[i] = lhs[i] + rhs[i]; 00200 return tmp; 00201 } 00202 00203 template <typename L, typename R> 00204 inline 00205 mln_dpoint(L) // FIXME: promote! 00206 operator-(const Delta_Point_Site<L>& lhs_, const Delta_Point_Site<R>& rhs_) 00207 { 00208 mln::metal::bool_<(int(L::dim) == int(R::dim))>::check(); 00209 const L& lhs = exact(lhs_); 00210 const R& rhs = exact(rhs_); 00211 mln_dpoint(L) tmp; 00212 for (unsigned i = 0; i < L::dim; ++i) 00213 tmp[i] = lhs[i] - rhs[i]; 00214 return tmp; 00215 } 00216 00217 # endif // ! MLN_INCLUDE_ONLY 00218 00219 } // end of namespace mln 00220 00221 00222 #endif // ! MLN_CORE_CONCEPT_DELTA_POINT_SITE_HH