2006-09-15 Thierry GERAUD <theo(a)tegucigalpa.lrde.epita.fr>
Add operator- to n-dimensional dpoint types.
* oln/core/traits_id.hh (op_uminus_dpointnd): New.
* oln/core/abstract/dpoint_nd.hh (operator-): New.
(impl_less): New.
(case_): New case for operator-.
* oln/core/2d/dpoint2d.hh (dpoint2d_): New ctor.
Index: oln/core/traits_id.hh
===================================================================
--- oln/core/traits_id.hh (revision 543)
+++ oln/core/traits_id.hh (working copy)
@@ -39,7 +39,7 @@
/// \{
- /// Identifiers for oln operators +.
+ /// Identifiers for oln binary operators +.
enum {
op_plus_pointnd_dpointnd = 1
@@ -50,7 +50,7 @@
/// \{
- /// Identifiers for oln operators -.
+ /// Identifiers for oln binary operators -.
enum {
op_minus_pointnd_pointnd = 1,
@@ -60,6 +60,17 @@
/// \}
+
+ /// \{
+ /// Identifiers for oln unary operators -.
+
+ enum {
+ op_uminus_dpointnd = 1
+ };
+
+ /// \}
+
+
} // end of namespace oln::id
} // end of namespace oln
Index: oln/core/abstract/dpoint_nd.hh
===================================================================
--- oln/core/abstract/dpoint_nd.hh (revision 543)
+++ oln/core/abstract/dpoint_nd.hh (working copy)
@@ -31,6 +31,7 @@
# include <mlc/value.hh>
# include <xtd/vec.hh>
+# include <stc/exact.hh>
# include <oln/core/abstract/dpoint.hh>
@@ -55,6 +56,7 @@
template <typename E>
class dpoint_nd : public abstract::dpoint<E>
{
+ typedef E exact_t;
typedef dpoint_nd<E> self_t;
typedef oln_type_of(E, dim) dim;
typedef oln_type_of(E, coord) coord_t;
@@ -85,6 +87,17 @@
return v_;
}
+ exact_t operator-() const
+ {
+ exact_t tmp(-v_);
+ return tmp;
+ }
+
+ bool impl_less(const self_t& rhs) const
+ {
+ return xtd::lexi_less(v_, rhs.vec());
+ }
+
protected:
/// Ctor.
@@ -102,6 +115,18 @@
} // end of namespace oln::abstract
+
+ /// - abstract::dpoint_nd
+ template <typename D>
+ struct case_ < xtd::op_uminus, D,
+ oln::id::op_uminus_dpointnd >
+ : where_< mlc_is_a(D, abstract::dpoint_nd) >
+ {
+ typedef stc_to_exact(D) ret;
+ };
+
+
+
} // end of namespace oln
Index: oln/core/2d/dpoint2d.hh
===================================================================
--- oln/core/2d/dpoint2d.hh (revision 543)
+++ oln/core/2d/dpoint2d.hh (working copy)
@@ -79,6 +79,12 @@
{
}
+ /// Ctor.
+ dpoint2d_(coord_t row, coord_t col)
+ : super_t(xtd::mk_vec(row, col))
+ {
+ }
+
coord_t row() const { return v_[0]; }
coord_t& row() { return v_[0]; }