00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
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
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 }
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
00085
00086
00087
00088
00089
00090
00091
00092
00093
00094
00095 protected:
00096 Delta_Point_Site();
00097 };
00098
00099
00100
00101
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)
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)
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)
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)
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 }
00220
00221
00222 #endif // ! MLN_CORE_CONCEPT_DELTA_POINT_SITE_HH