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_GDPOINT_HH 00027 # define MLN_CORE_CONCEPT_GDPOINT_HH 00028 00032 00033 # include <mln/core/concept/object.hh> 00034 # include <mln/core/grids.hh> 00035 # include <mln/trait/all.hh> 00036 # include <mln/value/scalar.hh> 00037 # include <mln/debug/format.hh> 00038 00039 00040 namespace mln 00041 { 00042 00043 // Forward declaration. 00044 template <typename E> struct Gdpoint; 00045 00046 00047 00048 namespace trait 00049 { 00050 00051 // FIXME: Add promotion. 00052 00053 template < typename L, typename R > 00054 struct set_binary_< op::plus, 00055 mln::Gdpoint, L, mln::Gdpoint, R > 00056 { 00057 typedef L ret; 00058 }; 00059 00060 template < typename L, typename R > 00061 struct set_binary_< op::minus, 00062 mln::Gdpoint, L, mln::Gdpoint, R > 00063 { 00064 typedef L ret; 00065 }; 00066 00067 template < typename D, typename S > 00068 struct set_binary_< op::times, 00069 mln::Gdpoint, D, 00070 mln::value::Scalar, S > 00071 { 00072 typedef D ret; 00073 }; 00074 00075 template <typename D> 00076 struct set_unary_< op::ord, mln::Gdpoint, D > 00077 { 00078 typedef mln::internal::ord_vec< D > ret; 00079 }; 00080 00081 } // end of namespace mln::trait 00082 00083 00084 00086 template <> 00087 struct Gdpoint<void> 00088 { 00089 typedef Object<void> super; 00090 }; 00091 00092 00094 template <typename E> 00095 struct Gdpoint : public Object<E> 00096 { 00097 typedef Gdpoint<void> category; 00098 00099 /* 00100 typedef grid; 00101 typedef vec; 00102 const vec& to_vec() const; 00103 */ 00104 00105 protected: 00106 Gdpoint(); 00107 }; 00108 00109 00110 00111 // Operators. 00112 00113 template <typename D> 00114 std::ostream& 00115 operator<<(std::ostream& ostr, const Gdpoint<D>& dp); 00116 00117 00118 template <typename L, typename R> 00119 bool 00120 operator==(const Gdpoint<L>& lhs, const Gdpoint<R>& rhs); 00121 00122 00123 template <typename L, typename R> 00124 L // FIXME: promote! 00125 operator+(const Gdpoint<L>& lhs, const Gdpoint<R>& rhs); 00126 00127 template <typename L, typename R> 00128 L // FIXME: promote! 00129 operator-(const Gdpoint<L>& lhs, const Gdpoint<R>& rhs); 00130 00131 template <typename D, typename S> 00132 D // FIXME: promote! 00133 operator*(const Gdpoint<D>& lhs, const value::Scalar<S>& rhs); 00134 00135 00136 00137 namespace convert 00138 { 00139 00140 namespace over_load 00141 { 00142 00143 template <typename D> 00144 void 00145 from_to_(const Gdpoint<D>& from, mln_site(D)& to); 00146 00147 // template <typename D, unsigned n, typename T> 00148 // void 00149 // from_to_(const Gdpoint<D>& from, algebra::vec<n,T>& to); 00150 00151 // template <unsigned n, typename T, typename D> 00152 // void 00153 // from_to_(const algebra::vec<n,T>& from, Gdpoint<D>& to); 00154 00155 } // end of namespace mln::convert::over_load 00156 00157 } // end of namespace mln::convert 00158 00159 00160 # ifndef MLN_INCLUDE_ONLY 00161 00162 template <typename E> 00163 inline 00164 Gdpoint<E>::Gdpoint() 00165 { 00166 typedef mln_grid(E) grid; 00167 typedef mln_vec(E) vec; 00168 vec (E::*m)() const = & E::to_vec; 00169 m = 0; 00170 } 00171 00172 00173 template <typename D> 00174 inline 00175 std::ostream& operator<<(std::ostream& ostr, const Gdpoint<D>& dp) 00176 { 00177 enum { n = D::dim }; 00178 ostr << '('; 00179 for (unsigned i = 0; i < n; ++i) 00180 ostr << debug::format(exact(dp)[i]) << (i == n - 1 ? ')' : ','); 00181 return ostr; 00182 } 00183 00184 00185 template <typename L, typename R> 00186 inline 00187 bool operator==(const Gdpoint<L>& lhs, const Gdpoint<R>& rhs) 00188 { 00189 mlc_equal(mln_grid(L), mln_grid(R))::check(); 00190 return exact(lhs).to_vec() == exact(rhs).to_vec(); 00191 } 00192 00193 template <typename L, typename R> 00194 inline 00195 L // FIXME: promote! 00196 operator+(const Gdpoint<L>& lhs, const Gdpoint<R>& rhs) 00197 { 00198 mlc_equal(mln_grid(L), mln_grid(R))::check(); 00199 L tmp = exact(lhs).to_vec() + exact(rhs).to_vec(); 00200 return tmp; 00201 } 00202 00203 template <typename L, typename R> 00204 inline 00205 L // FIXME: promote! 00206 operator-(const Gdpoint<L>& lhs, const Gdpoint<R>& rhs) 00207 { 00208 mlc_equal(mln_grid(L), mln_grid(R))::check(); 00209 L tmp = exact(lhs).to_vec() - exact(rhs).to_vec(); 00210 return tmp; 00211 } 00212 00213 template <typename D, typename S> 00214 D // FIXME: promote! 00215 operator*(const Gdpoint<D>& lhs, const value::Scalar<S>& rhs) 00216 { 00217 D tmp = exact(lhs).to_vec() * exact(rhs); 00218 return tmp; 00219 } 00220 00221 00222 namespace convert 00223 { 00224 00225 namespace over_load 00226 { 00227 00228 template <typename D> 00229 inline 00230 void 00231 from_to_(const Gdpoint<D>& dp_, mln_site(D)& p) 00232 { 00233 enum { n = D::dim }; 00234 const D& dp = exact(dp_); 00235 for (unsigned i = 0; i < n; ++i) 00236 p[i] = dp[i]; 00237 } 00238 00239 } // end of namespace mln::convert::over_load 00240 00241 } // end of namespace mln::convert 00242 00243 # endif // ! MLN_INCLUDE_ONLY 00244 00245 } // end of namespace mln 00246 00247 00248 #endif // ! MLN_CORE_CONCEPT_GDPOINT_HH