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_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   
00044   template <typename E> struct Gdpoint;
00045 
00046 
00047 
00048   namespace trait
00049   {
00050 
00051     
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   } 
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 
00101 
00102 
00103 
00104 
00105   protected:
00106     Gdpoint();
00107   };
00108 
00109 
00110 
00111   
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 
00125   operator+(const Gdpoint<L>& lhs, const Gdpoint<R>& rhs);
00126 
00127   template <typename L, typename R>
00128   L 
00129   operator-(const Gdpoint<L>& lhs, const Gdpoint<R>& rhs);
00130 
00131   template <typename D, typename S>
00132   D 
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 
00148 
00149 
00150 
00151 
00152 
00153 
00154 
00155     } 
00156 
00157   } 
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 
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 
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 
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     } 
00240 
00241   } 
00242 
00243 # endif // ! MLN_INCLUDE_ONLY
00244 
00245 } 
00246 
00247 
00248 #endif // ! MLN_CORE_CONCEPT_GDPOINT_HH