
2006-08-31 Thierry GERAUD <theo@tegucigalpa.lrde.epita.fr> Add dpoint, oln traits, and operators on point/dpoint. * oln/core/type.hh: New. * oln/core/traits_id.hh: New. * oln/core/abstract/dpoint.hh: New. * oln/core/abstract/dpoint_nd.hh: New. * oln/core/traits.hh: New. * oln/core/2d/dpoint2d.hh: New. * oln/core/abstract/point.hh (point): Add inheritance to oln::type. (operators): New. * oln/core/abstract/point_nd.hh (point_): New meta-function. (impl_eq): Rename as... (impl_equal): ...this. (coord): Rename as... (coord_t): ...this. (impl_less): New. (impl_plus_equal, impl_plus): New. (impl_minus_equal, impl_minus, impl_minus): New. (vec): New. (case_): New specializations. (point_nd): New ctor. * oln/core/2d/point2d.hh: Update forward declarations. (point_, dpoint_): New specializations. (point2d): New ctor. (coord): Rename as... (coord_t): ...this. Index: ChangeLog =================================================================== --- ChangeLog (revision 509) +++ ChangeLog (working copy) @@ -1,5 +1,7 @@ 2006-08-30 Thierry GERAUD <theo@tegucigalpa.lrde.epita.fr> + Start point hierarchy. + * oln/core/typedefs.hh (oln_type_of): New macro. (dim_type): New typedef decl. * oln/core/abstract/point.hh: New. Index: oln/core/type.hh =================================================================== --- oln/core/type.hh (revision 0) +++ oln/core/type.hh (revision 0) @@ -0,0 +1,44 @@ +// Copyright (C) 2006 EPITA Research and Development Laboratory +// +// This file is part of the Olena Library. This library is free +// software; you can redistribute it and/or modify it under the terms +// of the GNU General Public License version 2 as published by the +// Free Software Foundation. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this library; see the file COPYING. If not, write to +// the Free Software Foundation, 51 Franklin Street, Fifth Floor, +// Boston, MA 02111-1307, USA. +// +// As a special exception, you may use this file as part of a free +// software library without restriction. Specifically, if other files +// instantiate templates or use macros or inline functions from this +// file, or you compile this file and link it with other files to +// produce an executable, this file does not by itself cause the +// resulting executable to be covered by the GNU General Public +// License. This exception does not however invalidate any other +// reasons why the executable file might be covered by the GNU General +// Public License. + +#ifndef OLENA_CORE_TYPE_HH +# define OLENA_CORE_TYPE_HH + + +namespace oln +{ + + struct type + { + protected: + type() {} + }; + +} // end of namespace oln + + +#endif // ! OLENA_CORE_TYPE_HH Index: oln/core/traits_id.hh =================================================================== --- oln/core/traits_id.hh (revision 0) +++ oln/core/traits_id.hh (revision 0) @@ -0,0 +1,69 @@ +// Copyright (C) 2006 EPITA Research and Development Laboratory +// +// This file is part of the Olena Library. This library is free +// software; you can redistribute it and/or modify it under the terms +// of the GNU General Public License version 2 as published by the +// Free Software Foundation. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this library; see the file COPYING. If not, write to +// the Free Software Foundation, 51 Franklin Street, Fifth Floor, +// Boston, MA 02111-1307, USA. +// +// As a special exception, you may use this file as part of a free +// software library without restriction. Specifically, if other files +// instantiate templates or use macros or inline functions from this +// file, or you compile this file and link it with other files to +// produce an executable, this file does not by itself cause the +// resulting executable to be covered by the GNU General Public +// License. This exception does not however invalidate any other +// reasons why the executable file might be covered by the GNU General +// Public License. + +#ifndef OLENA_CORE_TRAITS_ID_HH +# define OLENA_CORE_TRAITS_ID_HH + +# include <oln/core/traits.hh> + + +namespace oln +{ + + namespace id + { + + + /// \{ + /// Identifiers for oln operators +. + + enum { + op_plus_pointnd_dpointnd = 1 + }; + + /// \} + + + + /// \{ + /// Identifiers for oln operators -. + + enum { + op_minus_pointnd_pointnd = 1, + op_minus_pointnd_dpointnd = 2 + }; + + /// \} + + + } // end of namespace oln::id + +} // end of namespace oln + + + +#endif // ! OLENA_CORE_TRAITS_ID_HH Index: oln/core/abstract/point.hh =================================================================== --- oln/core/abstract/point.hh (revision 509) +++ oln/core/abstract/point.hh (working copy) @@ -34,28 +34,264 @@ # include <stc/any.hh> # include <stc/vtypes.hh> +# include <stc/exact.hh> +# include <oln/core/type.hh> # include <oln/core/typedefs.hh> +# include <oln/core/abstract/dpoint.hh> +# include <oln/core/traits_id.hh> + namespace oln { + + namespace ERROR + { + struct OPERANDS_ARE_NOT_COMPATIBLE; + + } // end of namespace oln::ERROR + + + namespace abstract { + /// Abstract point class. template <typename E> - class point : public stc::any__simple<E> + class point : public stc::any__simple<E>, + public oln::type { + typedef E exact_t; + typedef oln_type_of(E, dpoint) dpoint_t; + public: - bool operator==(const abstract::point<E>& rhs) const + + /// \{ + /// Operator ==. + + bool operator==(const exact_t& rhs) const { - return this->exact().impl_eq(rhs.exact()); + return this->exact().impl_equal(rhs); } + template <typename P> + bool operator==(const abstract::point<P>& rhs) const + { + mlc::assert_equal_< oln_type_of(E, grid), + oln_type_of(P, grid), + oln::ERROR::OPERANDS_ARE_NOT_COMPATIBLE >::check(); + return this->exact().impl_equal(rhs.exact()); + } + + /// \} + + + /// \{ + /// Operator !=. + + bool operator!=(const exact_t& rhs) const + { + return not (*this == rhs); + } + + template <typename P> + bool operator!=(const abstract::point<P>& rhs) const + { + mlc::assert_equal_< oln_type_of(E, grid), + oln_type_of(P, grid), + oln::ERROR::OPERANDS_ARE_NOT_COMPATIBLE >::check(); + return not (*this == rhs); + } + + /// \} + + + /// \{ + /// Operator <. + + bool operator<(const exact_t& rhs) const + { + return this->exact().impl_less(rhs); + } + + template <typename P> + bool operator<(const abstract::point<P>& rhs) const + { + mlc::assert_equal_< oln_type_of(E, grid), + oln_type_of(P, grid), + oln::ERROR::OPERANDS_ARE_NOT_COMPATIBLE >::check(); + return this->exact().impl_less(rhs.exact()); + } + + /// \} + + + /// \{ + /// Operator >. + + bool operator>(const exact_t& rhs) const + { + return rhs < *this; + } + + template <typename P> + bool operator>(const abstract::point<P>& rhs) const + { + mlc::assert_equal_< oln_type_of(E, grid), + oln_type_of(P, grid), + oln::ERROR::OPERANDS_ARE_NOT_COMPATIBLE >::check(); + return rhs < *this; + } + + /// \} + + + /// \{ + /// Operator >=. + + bool operator>=(const exact_t& rhs) const + { + return not (*this < rhs); + } + + template <typename P> + bool operator>=(const abstract::point<P>& rhs) const + { + mlc::assert_equal_< oln_type_of(E, grid), + oln_type_of(P, grid), + oln::ERROR::OPERANDS_ARE_NOT_COMPATIBLE >::check(); + return not (*this < rhs); + } + + /// \} + + + /// \{ + /// Operator <=. + + bool operator<=(const exact_t& rhs) const + { + return not (rhs < *this); + } + + template <typename P> + bool operator<=(const abstract::point<P>& rhs) const + { + mlc::assert_equal_< oln_type_of(E, grid), + oln_type_of(P, grid), + oln::ERROR::OPERANDS_ARE_NOT_COMPATIBLE >::check(); + return not (rhs < *this); + } + + /// \} + + + /// \{ + /// Operator +=. + + exact_t& operator+=(const dpoint_t& rhs) + { + return this->exact().impl_plus_equal(rhs); + } + + template <typename D> + exact_t& operator+=(const abstract::dpoint<D>& rhs) + { + mlc::assert_equal_< oln_type_of(E, grid), + oln_type_of(D, grid), + oln::ERROR::OPERANDS_ARE_NOT_COMPATIBLE >::check(); + return this->exact().impl_plus_equal(rhs.exact()); + } + + /// \} + + + /// \{ + /// Operator +. + + exact_t operator+(const dpoint_t& rhs) const + { + return this->exact().impl_plus(rhs); + } + + template <typename D> + xtd_op_plus_trait(E,D) operator+(const abstract::dpoint<D>& rhs) + { + mlc::assert_equal_< oln_type_of(E, grid), + oln_type_of(D, grid), + oln::ERROR::OPERANDS_ARE_NOT_COMPATIBLE >::check(); + return this->exact().impl_plus(rhs.exact()); + } + + /// \} + + + /// \{ + /// Operator -=. + + exact_t& operator-=(const dpoint_t& rhs) + { + return this->exact().impl_minus_equal(rhs); + } + + template <typename D> + exact_t& operator-=(const abstract::dpoint<D>& rhs) const + { + mlc::assert_equal_< oln_type_of(E, grid), + oln_type_of(D, grid), + oln::ERROR::OPERANDS_ARE_NOT_COMPATIBLE >::check(); + return this->exact().impl_minus_equal(rhs.exact()); + } + + /// \} + + + /// \{ + /// Operator -. + + exact_t operator-(const dpoint_t& rhs) const + { + return this->exact().impl_minus(rhs); + } + + template <typename D> + xtd_op_minus_trait(E, D) operator-(const abstract::dpoint<D>& rhs) const + { + mlc::assert_equal_< oln_type_of(E, grid), + oln_type_of(D, grid), + oln::ERROR::OPERANDS_ARE_NOT_COMPATIBLE >::check(); + return this->exact().impl_minus(rhs.exact()); + } + + /// \} + + + /// \{ + /// Operator -. + + dpoint_t operator-(const exact_t& rhs) const + { + return this->exact().impl_minus(rhs); + } + + template <typename P> + xtd_op_minus_trait(E, P) operator-(const abstract::point<P>& rhs) const + { + mlc::assert_equal_< oln_type_of(E, grid), + oln_type_of(P, grid), + oln::ERROR::OPERANDS_ARE_NOT_COMPATIBLE >::check(); + return this->exact().impl_minus(rhs.exact()); + } + + /// \} + + protected: + point() {} @@ -69,6 +305,8 @@ } // end of namespace oln::abstract + + } // end of namespace oln Index: oln/core/abstract/point_nd.hh =================================================================== --- oln/core/abstract/point_nd.hh (revision 509) +++ oln/core/abstract/point_nd.hh (working copy) @@ -30,52 +30,164 @@ # define OLENA_CORE_ABSTRACT_POINT_ND_HH # include <mlc/value.hh> + # include <xtd/vec.hh> +# include <xtd/optraits.hh> + +# include <oln/core/traits_id.hh> # include <oln/core/abstract/point.hh> +# include <oln/core/abstract/dpoint_nd.hh> namespace oln { + + + /// Function "point_ : (n, coord) -> point type". + template <unsigned n, typename C> + struct point_ + { + typedef mlc::undefined ret; + }; + + + namespace abstract { template <typename E> class point_nd : public abstract::point<E> { - typedef point_nd<E> self; + typedef point_nd<E> self_t; typedef oln_type_of(E, dim) dim; - typedef oln_type_of(E, coord) coord; + typedef oln_type_of(E, coord) coord_t; + typedef oln_type_of(E, dpoint) dpoint_t; public: enum { n = mlc_value(dim) }; - - bool impl_eq(const self& rhs) const - { - return v_ == rhs.v_; - } - const coord operator[](unsigned i) const + coord_t operator[](unsigned i) const { assert(i < n); return v_[i]; } - coord& operator[](unsigned i) + coord_t& operator[](unsigned i) { assert(i < n); return v_[i]; } + bool impl_equal(const self_t& rhs) const + { + return v_ == rhs.vec(); + } + + bool impl_less(const self_t& rhs) const + { + return xtd::lexi(v_, rhs.vec()); + } + + E& impl_plus_equal(const dpoint_t& rhs) + { + v_ += rhs.vec(); + return this->exact(); + } + + E impl_plus(const dpoint_t& rhs) const + { + E tmp(v_ + rhs.vec()); + return tmp; + } + + E& impl_minus_equal(const dpoint_t& rhs) + { + v_ += rhs.vec(); + return this->exact(); + } + + E impl_minus(const dpoint_t& rhs) const + { + E tmp(v_ - rhs.vec()); + return tmp; + } + + dpoint_t impl_minus(const self_t& rhs) const + { + dpoint_t tmp(v_ - rhs.vec()); + return tmp; + } + + const xtd::vec<n,coord_t>& vec() const + { + return v_; + } + protected: - xtd::vec<n,coord> v_; + /// Ctor. + point_nd() + {} + + /// Ctor. + point_nd(const xtd::vec<n,coord_t>& v) : + v_(v) + {} + + xtd::vec<n,coord_t> v_; }; } // end of namespace oln::abstract + + /// abstract::point_nd + abstract::dpoint_nd + template <typename P, typename D> + struct case_ < xtd::op_plus, mlc::pair_<P,D>, + oln::id::op_plus_pointnd_dpointnd > + : where_< mlc::and_< mlc_is_a(P, abstract::point_nd), + mlc_is_a(D, abstract::dpoint_nd) > > + { + typedef oln_type_of(P, coord) P_coord; + typedef oln_type_of(D, coord) D_coord; + typedef xtd_op_plus_trait(P_coord, D_coord) coord; + typedef oln_type_of(P, dim) dim; + typedef typename point_<mlc_value(dim), coord>::ret ret; + }; + + + /// abstract::point_nd - abstract::dpoint_nd + template <typename P, typename D> + struct case_ < xtd::op_minus, mlc::pair_<P,D>, + oln::id::op_minus_pointnd_dpointnd > + : where_< mlc::and_< mlc_is_a(P, abstract::point_nd), + mlc_is_a(D, abstract::dpoint_nd) > > + { + typedef oln_type_of(P, coord) P_coord; + typedef oln_type_of(D, coord) D_coord; + typedef xtd_op_minus_trait(P_coord, D_coord) coord; + typedef oln_type_of(P, dim) dim; + typedef typename point_<mlc_value(dim), coord>::ret ret; + }; + + + /// abstract::point_nd - abstract::point_nd + template <typename P1, typename P2> + struct case_ < xtd::op_minus, mlc::pair_<P1,P2>, + oln::id::op_minus_pointnd_pointnd > + : where_< mlc::and_< mlc_is_a(P1, abstract::point_nd), + mlc_is_a(P2, abstract::point_nd) > > + { + typedef oln_type_of(P1, coord) P1_coord; + typedef oln_type_of(P2, coord) P2_coord; + typedef xtd_op_minus_trait(P1_coord, P2_coord) coord; + typedef oln_type_of(P1, dim) dim; + typedef typename dpoint_<mlc_value(dim), coord>::ret ret; + }; + + } // end of namespace oln Index: oln/core/abstract/dpoint.hh =================================================================== --- oln/core/abstract/dpoint.hh (revision 0) +++ oln/core/abstract/dpoint.hh (revision 0) @@ -0,0 +1,100 @@ +// Copyright (C) 2001, 2002, 2003, 2004, 2006 EPITA Research and +// Development Laboratory +// +// This file is part of the Olena Library. This library is free +// software; you can redistribute it and/or modify it under the terms +// of the GNU General Public License version 2 as published by the +// Free Software Foundation. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this library; see the file COPYING. If not, write to +// the Free Software Foundation, 51 Franklin Street, Fifth Floor, +// Boston, MA 02111-1307, USA. +// +// As a special exception, you may use this file as part of a free +// software library without restriction. Specifically, if other files +// instantiate templates or use macros or inline functions from this +// file, or you compile this file and link it with other files to +// produce an executable, this file does not by itself cause the +// resulting executable to be covered by the GNU General Public +// License. This exception does not however invalidate any other +// reasons why the executable file might be covered by the GNU General +// Public License. + +#ifndef OLENA_CORE_ABSTRACT_DPOINT_HH +# define OLENA_CORE_ABSTRACT_DPOINT_HH + +# include <mlc/assert.hh> +# include <mlc/cmp.hh> + +# include <stc/any.hh> +# include <stc/vtypes.hh> + +# include <oln/core/type.hh> +# include <oln/core/typedefs.hh> + + + + +namespace oln +{ + + + /// Function "dpoint_ : (n, coord) -> dpoint type". + template <unsigned n, typename C> + struct dpoint_ + { + typedef mlc::undefined ret; + }; + + + namespace abstract + { + + /// Abstract dpoint class. + template <typename E> + class dpoint : public stc::any__simple<E>, + public oln::type + { + public: + + bool operator==(const abstract::dpoint<E>& rhs) const + { + return this->exact().impl_eq(rhs.exact()); + } + + bool operator!=(const abstract::dpoint<E>& rhs) const { return not (*this == rhs); } + + bool operator<(const abstract::dpoint<E>& rhs) const + { + return this->exact().impl_less(rhs.exact()); + } + + bool operator> (const abstract::dpoint<E>& rhs) const { return rhs < *this; } + bool operator>=(const abstract::dpoint<E>& rhs) const { return not (*this < rhs); } + bool operator<=(const abstract::dpoint<E>& rhs) const { return not (rhs < *this); } + + protected: + dpoint() + {} + + ~dpoint() { + mlc::assert_defined_< oln_type_of(E, grid) >::check(); + mlc::assert_defined_< oln_type_of(E, point) >::check(); + mlc::assert_defined_< oln_type_of(E, coord) >::check(); + mlc::assert_defined_< oln_type_of(E, dim) >::check(); + } + }; + + + } // end of namespace oln::abstract + +} // end of namespace oln + + +#endif // ! OLENA_CORE_ABSTRACT_DPOINT_HH Index: oln/core/abstract/dpoint_nd.hh =================================================================== --- oln/core/abstract/dpoint_nd.hh (revision 0) +++ oln/core/abstract/dpoint_nd.hh (revision 0) @@ -0,0 +1,96 @@ +// Copyright (C) 2001, 2002, 2003, 2004, 2006 EPITA Research and +// Development Laboratory +// +// This file is part of the Olena Library. This library is free +// software; you can redistribute it and/or modify it under the terms +// of the GNU General Public License version 2 as published by the +// Free Software Foundation. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this library; see the file COPYING. If not, write to +// the Free Software Foundation, 51 Franklin Street, Fifth Floor, +// Boston, MA 02111-1307, USA. +// +// As a special exception, you may use this file as part of a free +// software library without restriction. Specifically, if other files +// instantiate templates or use macros or inline functions from this +// file, or you compile this file and link it with other files to +// produce an executable, this file does not by itself cause the +// resulting executable to be covered by the GNU General Public +// License. This exception does not however invalidate any other +// reasons why the executable file might be covered by the GNU General +// Public License. + +#ifndef OLENA_CORE_ABSTRACT_DPOINT_ND_HH +# define OLENA_CORE_ABSTRACT_DPOINT_ND_HH + +# include <mlc/value.hh> +# include <xtd/vec.hh> +# include <oln/core/abstract/dpoint.hh> + + +namespace oln +{ + + namespace abstract + { + + template <typename E> + class dpoint_nd : public abstract::dpoint<E> + { + typedef dpoint_nd<E> self_t; + typedef oln_type_of(E, dim) dim; + typedef oln_type_of(E, coord) coord_t; + + public: + + enum { n = mlc_value(dim) }; + + bool impl_equal(const self_t& rhs) const + { + return v_ == rhs.v_; + } + + coord_t operator[](unsigned i) const + { + assert(i < n); + return v_[i]; + } + + coord_t& operator[](unsigned i) + { + assert(i < n); + return v_[i]; + } + + const xtd::vec<n,coord_t>& vec() const + { + return v_; + } + + protected: + + /// Ctor. + dpoint_nd() + {} + + /// Ctor. + dpoint_nd(const xtd::vec<n,coord_t>& v) : + v_(v) + {} + + xtd::vec<n,coord_t> v_; + }; + + } // end of namespace oln::abstract + + +} // end of namespace oln + + +#endif // ! OLENA_CORE_ABSTRACT_DPOINT_ND_HH Index: oln/core/traits.hh =================================================================== --- oln/core/traits.hh (revision 0) +++ oln/core/traits.hh (revision 0) @@ -0,0 +1,95 @@ +// Copyright (C) 2006 EPITA Research and Development Laboratory +// +// This file is part of the Olena Library. This library is free +// software; you can redistribute it and/or modify it under the terms +// of the GNU General Public License version 2 as published by the +// Free Software Foundation. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this library; see the file COPYING. If not, write to +// the Free Software Foundation, 51 Franklin Street, Fifth Floor, +// Boston, MA 02111-1307, USA. +// +// As a special exception, you may use this file as part of a free +// software library without restriction. Specifically, if other files +// instantiate templates or use macros or inline functions from this +// file, or you compile this file and link it with other files to +// produce an executable, this file does not by itself cause the +// resulting executable to be covered by the GNU General Public +// License. This exception does not however invalidate any other +// reasons why the executable file might be covered by the GNU General +// Public License. + +#ifndef OLENA_CORE_TRAITS_HH +# define OLENA_CORE_TRAITS_HH + + +# include <mlc/assert.hh> +# include <mlc/case.hh> +# include <mlc/abort.hh> +# include <xtd/optraits.hh> +# include <stc/exact.hh> + +# include <oln/core/type.hh> + + +mlc_case_equipment_for_namespace(oln); + + + +namespace oln +{ + + template <typename data> struct default_case_ < xtd::op_eq, data > { typedef bool ret; }; + template <typename data> struct default_case_ < xtd::op_neq, data > { typedef bool ret; }; + template <typename data> struct default_case_ < xtd::op_less, data > { typedef bool ret; }; + template <typename data> struct default_case_ < xtd::op_leq, data > { typedef bool ret; }; + template <typename data> struct default_case_ < xtd::op_greater, data > { typedef bool ret; }; + template <typename data> struct default_case_ < xtd::op_geq, data > { typedef bool ret; }; + +} // end of namespace oln + + + +namespace xtd +{ + + static const unsigned oln_xtd_case_op_id = 2; + + + template <typename name, + typename T> + struct case_ < xtd::op_<name>, T, + oln_xtd_case_op_id > : public mlc::where_< mlc_is_a(T, oln::type) > + { + struct protected_ { + typedef typename oln::switch_< xtd::op_<name>, + stc_to_exact(T) >::ret ret; + }; + }; + + + template <typename name, + typename L, typename R> + struct case_ < xtd::op_<name>, mlc::pair_<L, R>, + oln_xtd_case_op_id > : public mlc::where_< mlc::or_<mlc_is_a(L, oln::type), + mlc_is_a(R, oln::type)> > + { + struct protected_ { + typedef typename oln::switch_< xtd::op_<name>, + mlc::pair_<stc_to_exact(L), + stc_to_exact(R)> >::ret ret; + }; + }; + + +} // end of namespace xtd + + + +#endif // ! OLENA_CORE_TRAITS_HH Index: oln/core/2d/dpoint2d.hh =================================================================== --- oln/core/2d/dpoint2d.hh (revision 0) +++ oln/core/2d/dpoint2d.hh (revision 0) @@ -0,0 +1,95 @@ +// Copyright (C) 2001, 2002, 2003, 2004, 2006 EPITA Research and Development Laboratory +// +// This file is part of the Olena Library. This library is free +// software; you can redistribute it and/or modify it under the terms +// of the GNU General Public License version 2 as published by the +// Free Software Foundation. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this library; see the file COPYING. If not, write to +// the Free Software Foundation, 51 Franklin Street, Fifth Floor, +// Boston, MA 02111-1307, USA. +// +// As a special exception, you may use this file as part of a free +// software library without restriction. Specifically, if other files +// instantiate templates or use macros or inline functions from this +// file, or you compile this file and link it with other files to +// produce an executable, this file does not by itself cause the +// resulting executable to be covered by the GNU General Public +// License. This exception does not however invalidate any other +// reasons why the executable file might be covered by the GNU General +// Public License. + +#ifndef OLENA_CORE_2D_DPOINT2D_HH +# define OLENA_CORE_2D_DPOINT2D_HH + +# include <mlc/int.hh> +# include <oln/core/2d/point2d.hh> +# include <oln/core/abstract/dpoint_nd.hh> + + +namespace oln +{ + + +// /// Super type. +// template<typename C> +// struct set_super_type< dpoint2d_<C> > +// { +// typedef abstract::dpoint< dpoint2d_<C> > ret; +// }; + + + /// Virtual types associated to oln::abstract::image. + template <typename C> + struct vtypes_< dpoint2d_<C> > + { + typedef grid2d grid_type; + typedef point2d point_type; + typedef C coord_type; + typedef mlc::uint_<2> dim_type; + }; + + + /// General 2D dpoint class. + template <typename C> + class dpoint2d_ : public abstract::dpoint_nd< dpoint2d_<C> > // FIXME: stc_get_super_(dpoint2d_<C>) + { + typedef dpoint2d_<C> self_t; + typedef abstract::dpoint_nd<self_t> super_t; // FIXME: stc_get_super(self) + typedef oln_type_of(self_t, coord) coord_t; + + using super_t::v_; + + public: + + /// Ctor. + dpoint2d_() + { + } + + /// Ctor. + dpoint2d_(const xtd::vec<2,coord_t>& v) : + super_t(v) + { + } + + coord_t row() const { return v_[0]; } + coord_t& row() { return v_[0]; } + + coord_t col() const { return v_[1]; } + coord_t& col() { return v_[1]; } + }; + + + + +} // end of namespace oln + + +#endif // ! OLENA_CORE_2D_DPOINT2D_HH Index: oln/core/2d/point2d.hh =================================================================== --- oln/core/2d/point2d.hh (revision 509) +++ oln/core/2d/point2d.hh (working copy) @@ -28,6 +28,8 @@ #ifndef OLENA_CORE_2D_POINT2D_HH # define OLENA_CORE_2D_POINT2D_HH +# include <string> + # include <mlc/int.hh> # include <oln/core/abstract/point_nd.hh> @@ -35,20 +37,36 @@ namespace oln { - // Forward declarations. + + /// \{ + /// Forward declarations. template <typename C> class point2d_; - class dpoint2d; + template <typename C> class dpoint2d_; class grid2d; + /// \} -// /// Super type. -// template<typename C> -// struct set_super_type< point2d_<C> > -// { -// typedef abstract::point< point2d_<C> > ret; -// }; + /// \{ + /// Classical 2D point classes. + typedef point2d_<int> point2d; + typedef point2d_<float> point2df; + /// \} + /// \{ + /// Classical 2D point classes. + typedef dpoint2d_<int> dpoint2d; + typedef dpoint2d_<float> dpoint2df; + /// \} + + + /// \{ + /// Specializations of functions point and dpoint : (n,coord) -> type for n = 2. + template <typename C> struct point_ <2, C> { typedef point2d_<C> ret; }; + template <typename C> struct dpoint_ <2, C> { typedef dpoint2d_<C> ret; }; + /// \} + + /// Virtual types associated to oln::abstract::image. template <typename C> struct vtypes_< point2d_<C> > @@ -64,27 +82,36 @@ template <typename C> class point2d_ : public abstract::point_nd< point2d_<C> > // FIXME: stc_get_super_(point2d_<C>) { - typedef point2d_<C> self; - typedef abstract::point_nd<self> super; // FIXME: stc_get_super(self) - typedef oln_type_of(self, coord) coord; + typedef point2d_<C> self_t; + typedef abstract::point_nd<self_t> super_t; + typedef oln_type_of(self_t, coord) coord_t; - using super::v_; + using super_t::v_; public: - const coord row() const { return v_[0]; } - coord& row() { return v_[0]; } + /// Ctor. + point2d_() + { + } - const coord col() const { return v_[1]; } - coord& col() { return v_[1]; } - }; + /// Ctor. + point2d_(const xtd::vec<2,coord_t>& v) : + super_t(v) + { + } + coord_t row() const { return v_[0]; } + coord_t& row() { return v_[0]; } - /// Classical 2D point class. - typedef point2d_<int> point2d; + coord_t col() const { return v_[1]; } + coord_t& col() { return v_[1]; } + }; } // end of namespace oln +# include <oln/core/2d/dpoint2d.hh> + #endif // ! OLENA_CORE_2D_POINT2D_HH