843: Start cleaning so the trunk is BROKEN for several weeks.

https://svn.lrde.epita.fr/svn/oln/trunk/olena Index: ChangeLog from Thierry Geraud <thierry.geraud@lrde.epita.fr> Start cleaning so the trunk is BROKEN for several weeks. Add a temporary SCOOP equipment. * oln/stc/scoop.hh: New. * oln/stc/scoop.hxx: New. * oln/core/equipment.hh: New. Define some concepts. * oln/core/abstract/grid.hh: Rename as... * oln/core/concept/grid.hh: ...this and update. * oln/core/abstract/point.hh: Rename as... * oln/core/concept/point.hh: ...this and update. * oln/core/abstract/dpoint.hh: Rename as... * oln/core/concept/dpoint.hh: ...this and update. * oln/core/concept/operators.hh: New. Update implementation classes. * oln/core/2d/grid2d.hh: New. * oln/core/2d/dpoint2d.hh: Update. * oln/core/2d/point2d.hh: Update. * oln/core/internal/point_nd.hh: Rename as... * oln/core/internal/point_base.hh: ...this and update. * oln/core/internal/dpoint_base.hh: New. * oln/core/internal/dpoint2d.hh: New. * oln/core/internal/point2d.hh: New. Last. * oln/core/internal/tracked_ptr.hh (mlc/contract.hh): Include it. core/2d/dpoint2d.hh | 100 +--- core/2d/grid2d.hh | 69 +++ core/2d/point2d.hh | 113 +---- core/concept/dpoint.hh | 158 ++++--- core/concept/grid.hh | 53 -- core/concept/operators.hh | 181 ++++++++ core/concept/point.hh | 427 ++----------------- core/equipment.hh | 65 ++ core/internal/dpoint2d.hh | 127 +++++ core/internal/dpoint_base.hh | 230 ++++++++++ core/internal/point2d.hh | 127 +++++ core/internal/point_base.hh | 278 ++++-------- core/internal/tracked_ptr.hh | 2 stc/scoop.hh | 155 +++++++ stc/scoop.hxx | 951 +++++++++++++++++++++++++++++++++++++++++++ 15 files changed, 2215 insertions(+), 821 deletions(-) Index: oln/core/concept/grid.hh --- oln/core/concept/grid.hh (revision 0) +++ oln/core/concept/grid.hh (working copy) @@ -1,4 +1,5 @@ -// Copyright (C) 2005, 2006 EPITA Research and Development Laboratory +// Copyright (C) 2005, 2006, 2007 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 @@ -25,58 +26,28 @@ // reasons why the executable file might be covered by the GNU General // Public License. -#ifndef OLN_CORE_ABSTRACT_GRID_HH -# define OLN_CORE_ABSTRACT_GRID_HH +#ifndef OLN_CORE_CONCEPT_GRID_HH +# define OLN_CORE_CONCEPT_GRID_HH -# include <oln/core/type.hh> -# include <oln/core/typedefs.hh> +# include <oln/core/equipment.hh> -namespace oln { - - // Forward declaration. - namespace abstract +namespace oln { - template <typename E> class grid; - } - /// Super type declaration. - template <typename E> - struct set_super_type< abstract::grid<E> > - { - typedef mlc::none ret; - }; + /// Concept-class "Grid". - /// Virtual types associated to oln::abstract::grid. - template <typename E> - struct vtypes< abstract::grid<E> > + template <typename Exact> + struct Grid : public Any<Exact> { - typedef stc::abstract dimvalue_type; - }; - - namespace abstract { + stc_typename(dim); - template <typename E> - struct grid : public virtual stc::any__simple<E>, - public oln::type - { protected: - grid(); + Grid() {} }; -# ifndef OLN_INCLUDE_ONLY - - template <typename E> - grid<E>::grid() - { - } - -# endif - - } // end of namespace oln::abstract - } // end of namespace oln -#endif // ! OLN_CORE_ABSTRACT_GRID_HH +#endif // ! OLN_CORE_CONCEPT_GRID_HH Index: oln/core/concept/point.hh --- oln/core/concept/point.hh (revision 0) +++ oln/core/concept/point.hh (working copy) @@ -1,4 +1,4 @@ -// Copyright (C) 2001, 2002, 2003, 2004, 2006 EPITA Research and +// Copyright (C) 2001, 2002, 2003, 2004, 2006, 2007 EPITA Research and // Development Laboratory // // This file is part of the Olena Library. This library is free @@ -26,16 +26,11 @@ // reasons why the executable file might be covered by the GNU General // Public License. -#ifndef OLN_CORE_ABSTRACT_POINT_HH -# define OLN_CORE_ABSTRACT_POINT_HH +#ifndef OLN_CORE_CONCEPT_POINT_HH +# define OLN_CORE_CONCEPT_POINT_HH -# include <xtd/vec.hh> - -# include <oln/core/typedefs.hh> -# include <oln/core/traits_id.hh> -# include <oln/core/abstract/dpoint.hh> - -# include <xtd/vec.hh> +# include <mlc/value.hh> +# include <oln/core/equipment.hh> @@ -43,426 +38,110 @@ { - namespace ERROR - { - struct OPERANDS_ARE_NOT_COMPATIBLE; - - } // end of namespace oln::ERROR - - + /// Concept-class "Point". - // Forward declaration. - namespace abstract { template <typename E> class point; } - - - template <typename E> - struct set_super_type< abstract::point<E> > + template <typename Exact> + struct Point : public Any<Exact> { - typedef mlc::none ret; - }; - + stc_typename(grid); + stc_typename(dim); + stc_typename(coord); + stc_typename(dpoint); - /// Virtual types associated to abstract::point<E>. - template <typename E> - struct vtypes< abstract::point<E> > - { - // FIXME: Prefer to use final<deduce..> when possible. - typedef stc::abstract grid_type; - typedef stc::abstract dpoint_type; -# ifndef OLENA_USE_SCOOP_ALT - typedef oln_deduce_deferred_vtype(E, dpoint, coord) coord_type; -# endif // !OLENA_USE_SCOOP_ALT - typedef stc::abstract dim_type; - -# ifndef OLENA_USE_SCOOP_ALT - typedef oln_dim(E) dim_t; - typedef xtd::vec<mlc_value(dim_t), coord_type> vec_type; -# endif // !OLENA_USE_SCOOP_ALT - }; - -# ifdef OLENA_USE_SCOOP_ALT - template <typename E> - struct single_vtype< abstract::point<E>, typedef_::coord_type> - { - typedef oln_deduce_vtype(E, dpoint, coord) ret; - }; + enum { n = mlc_value(dim) }; - template <typename E> - struct single_vtype< abstract::point<E>, typedef_::vec_type> - { - private: - typedef oln_dim(E) dim_t; - typedef oln_coord(E) coord_t; - public: - typedef xtd::vec<mlc_value(dim_t), coord_t> ret; - }; -# endif // OLENA_USE_SCOOP_ALT - - - namespace abstract - { - - /// Abstract point class. - template <typename E> - class point : public stc::any__simple<E>, - public oln::type - { - typedef oln_dpoint(E) dpoint_t; - typedef oln_vec(E) vec_t; - - public: - - - /// \{ /// Operator =. + bool op_equal_(const Exact& rhs) const; - bool operator=(const E& rhs) const; - - template <typename P> - bool operator=(const abstract::point<P>& rhs) const; - - /// \} - - - /// \{ - /// Operator !=. - - bool operator!=(const E& rhs) const; - - template <typename P> - bool operator!=(const abstract::point<P>& rhs) const; - - /// \} - - - /// \{ /// Operator <. + bool op_less_(const Exact& rhs) const; - bool operator<(const E& rhs) const; - - template <typename P> - bool operator<(const abstract::point<P>& rhs) const; - - /// \} - - - /// \{ - /// Operator >. - - bool operator>(const E& rhs) const; - - template <typename P> - bool operator>(const abstract::point<P>& rhs) const; - - /// \} - - - /// \{ - /// Operator >=. - - bool operator>=(const E& rhs) const; - - template <typename P> - bool operator>=(const abstract::point<P>& rhs) const; - - /// \} - - - /// \{ - /// Operator <=. - - bool operator<=(const E& rhs) const; - - template <typename P> - bool operator<=(const abstract::point<P>& rhs) const; - - /// \} - - - /// \{ /// Operator +=. + Exact& op_plus_equal_(const dpoint& rhs); - E& operator+=(const dpoint_t& rhs); - - template <typename D> - E& operator+=(const abstract::dpoint<D>& rhs); - - /// \} - - - /// \{ - /// Operator +. - - E operator+(const dpoint_t& rhs) const; - - template <typename D> - xtd_op_plus_trait(E,D) operator+(const abstract::dpoint<D>& rhs) const; - - /// \} - - - /// \{ /// Operator -=. + Exact& op_minus_equal_(const dpoint& rhs); - E& operator-=(const dpoint_t& rhs); - - template <typename D> - E& operator-=(const abstract::dpoint<D>& rhs) const; - - /// \} - - - /// \{ /// Operator -. - - E operator-(const dpoint_t& rhs) const; - - template <typename D> - xtd_op_minus_trait(E, D) operator-(const abstract::dpoint<D>& rhs) const; - - /// \} - - - /// \{ - /// Operator -. - - dpoint_t operator-(const E& rhs) const; - - template <typename P> - xtd_op_minus_trait(E, P) operator-(const abstract::point<P>& rhs) const; - - /// \} - - - const vec_t& vec() const; - vec_t& vec(); - - - ~point() - { - // FIXME: See code below. - } + dpoint op_minus_(const Exact& rhs) const; protected: + Point(); - point(); - - }; // end of class oln::abstract::point<E> - + }; // end of oln::Point<Exact> -# ifndef OLN_INCLUDE_ONLY - template <typename E> - bool point<E>::operator=(const E& rhs) const - { - return this->exact().impl_equal(rhs); - } - - template <typename E> + /// Operator -. template <typename P> - bool point<E>::operator=(const abstract::point<P>& rhs) const - { - mlc::assert_equal_< oln_vtype(E, grid), - oln_vtype(P, grid), - oln::ERROR::OPERANDS_ARE_NOT_COMPATIBLE >::check(); - return this->exact().impl_equal(rhs.exact()); - } - - template <typename E> - bool point<E>::operator!=(const E& rhs) const - { - return not (*this = rhs); - } + typename P::dpoint operator-(const Point<P>& lhs, const Point<P>& rhs); - template <typename E> - template <typename P> - bool point<E>::operator!=(const abstract::point<P>& rhs) const - { - mlc::assert_equal_< oln_vtype(E, grid), - oln_vtype(P, grid), - oln::ERROR::OPERANDS_ARE_NOT_COMPATIBLE >::check(); - return not (*this = rhs); - } - template <typename E> - bool point<E>::operator<(const E& rhs) const - { - return this->exact().impl_less(rhs); - } - template <typename E> - template <typename P> - bool point<E>::operator<(const abstract::point<P>& rhs) const - { - mlc::assert_equal_< oln_vtype(E, grid), - oln_vtype(P, grid), - oln::ERROR::OPERANDS_ARE_NOT_COMPATIBLE >::check(); - return this->exact().impl_less(rhs.exact()); - } - - template <typename E> - bool point<E>::operator>(const E& rhs) const - { - return rhs < *this; - } + /// \{ + /// Invalid operators. - template <typename E> template <typename P> - bool point<E>::operator>(const abstract::point<P>& rhs) const - { - mlc::assert_equal_< oln_vtype(E, grid), - oln_vtype(P, grid), - oln::ERROR::OPERANDS_ARE_NOT_COMPATIBLE >::check(); - return rhs < *this; - } - - template <typename E> - bool point<E>::operator>=(const E& rhs) const - { - return not (*this < rhs); - } + void operator-(const Point<P>& rhs) /* error */ ; - template <typename E> - template <typename P> - bool point<E>::operator>=(const abstract::point<P>& rhs) const - { - mlc::assert_equal_< oln_vtype(E, grid), - oln_vtype(P, grid), - oln::ERROR::OPERANDS_ARE_NOT_COMPATIBLE >::check(); - return not (*this < rhs); - } + template <typename P1, typename P2> + void operator+(const Point<P1>& lhs, const Point<P2>& rhs) /* error */ ; - template <typename E> - bool point<E>::operator<=(const E& rhs) const - { - return not (rhs < *this); - } + /// \} - template <typename E> - template <typename P> - bool point<E>::operator<=(const abstract::point<P>& rhs) const - { - mlc::assert_equal_< oln_vtype(E, grid), - oln_vtype(P, grid), - oln::ERROR::OPERANDS_ARE_NOT_COMPATIBLE >::check(); - return not (rhs < *this); - } - template <typename E> - E& point<E>::operator+=(const typename point<E>::dpoint_t& rhs) - { - return this->exact().impl_plus_equal(rhs); - } - template <typename E> - template <typename D> - E& point<E>::operator+=(const abstract::dpoint<D>& rhs) - { - mlc::assert_equal_< oln_vtype(E, grid), - oln_vtype(D, grid), - oln::ERROR::OPERANDS_ARE_NOT_COMPATIBLE >::check(); - return this->exact().impl_plus_equal(rhs.exact()); - } +# ifndef OLN_INCLUDE_ONLY - template <typename E> - E point<E>::operator+(const typename point<E>::dpoint_t& rhs) const - { - return this->exact().impl_plus(rhs); - } - template <typename E> - template <typename D> - xtd_op_plus_trait(E,D) point<E>::operator+(const abstract::dpoint<D>& rhs) const + template <typename Exact> + bool Point<Exact>::op_equal_(const Exact& rhs) const { - mlc::assert_equal_< oln_vtype(E, grid), - oln_vtype(D, grid), - oln::ERROR::OPERANDS_ARE_NOT_COMPATIBLE >::check(); - return this->exact().impl_plus(rhs.exact()); + return exact(this)->impl_op_equal_(rhs); } - template <typename E> - E& point<E>::operator-=(const typename point<E>::dpoint_t& rhs) + template <typename Exact> + bool Point<Exact>::op_less_(const Exact& rhs) const { - return this->exact().impl_minus_equal(rhs); + return exact(this)->impl_op_less_(rhs); } - template <typename E> - template <typename D> - E& point<E>::operator-=(const abstract::dpoint<D>& rhs) const + template <typename Exact> + Exact& Point<Exact>::op_plus_equal_(const typename Point<Exact>::dpoint& rhs) { - mlc::assert_equal_< oln_vtype(E, grid), - oln_vtype(D, grid), - oln::ERROR::OPERANDS_ARE_NOT_COMPATIBLE >::check(); - return this->exact().impl_minus_equal(rhs.exact()); + return exact(this)->impl_op_plus_equal_(rhs); } - template <typename E> - E point<E>::operator-(const typename point<E>::dpoint_t& rhs) const + template <typename Exact> + Exact& Point<Exact>::op_minus_equal_(const typename Point<Exact>::dpoint& rhs) { - return this->exact().impl_minus(rhs); + return exact(this)->impl_op_minus_equal_(rhs); } - template <typename E> - template <typename D> - xtd_op_minus_trait(E, D) point<E>::operator-(const abstract::dpoint<D>& rhs) const + template <typename Exact> + typename Point<Exact>::dpoint Point<Exact>::op_minus_(const Exact& rhs) const { - mlc::assert_equal_< oln_vtype(E, grid), - oln_vtype(D, grid), - oln::ERROR::OPERANDS_ARE_NOT_COMPATIBLE >::check(); - return this->exact().impl_minus(rhs.exact()); + return exact(this)->impl_op_minus_(rhs); } - template <typename E> - typename point<E>::dpoint_t point<E>::operator-(const E& rhs) const + template <typename Exact> + Point<Exact>::Point() { - return this->exact().impl_minus(rhs); + // mlc::assert_defined_< oln_vtype(Exact, grid) >::check(); + // mlc::assert_defined_< oln_vtype(Exact, dPoint) >::check(); + // mlc::assert_defined_< oln_vtype(Exact, coord) >::check(); + // mlc::assert_defined_< oln_vtype(Exact, dim) >::check(); } - template <typename E> template <typename P> - xtd_op_minus_trait(E, P) point<E>::operator-(const abstract::point<P>& rhs) const - { - mlc::assert_equal_< oln_vtype(E, grid), - oln_vtype(P, grid), - oln::ERROR::OPERANDS_ARE_NOT_COMPATIBLE >::check(); - return this->exact().impl_minus(rhs.exact()); - } - - template <typename E> - const typename point<E>::vec_t& - point<E>::vec() const - { - return this->exact().impl_vec(); - } - - template <typename E> - typename point<E>::vec_t& - point<E>::vec() - { - return this->exact().impl_vec(); - } - - template <typename E> - point<E>::point() + typename P::dpoint operator-(const Point<P>& lhs, const Point<P>& rhs) { + return lhs.op_minus_(exact(rhs)); } -// template <typename E> -// point<E>::~point() -// { -// mlc::assert_defined_< oln_vtype(E, grid) >::check(); -// mlc::assert_defined_< oln_vtype(E, dpoint) >::check(); -// mlc::assert_defined_< oln_vtype(E, coord) >::check(); -// mlc::assert_defined_< oln_vtype(E, dim) >::check(); -// } - # endif - } // end of namespace oln::abstract - - } // end of namespace oln -#endif // ! OLN_CORE_ABSTRACT_POINT_HH +#endif // ! OLN_CORE_CONCEPT_POINT_HH Index: oln/core/concept/dpoint.hh --- oln/core/concept/dpoint.hh (revision 0) +++ oln/core/concept/dpoint.hh (working copy) @@ -1,4 +1,4 @@ -// Copyright (C) 2001, 2002, 2003, 2004, 2006 EPITA Research and +// Copyright (C) 2001, 2002, 2003, 2004, 2006, 2007 EPITA Research and // Development Laboratory // // This file is part of the Olena Library. This library is free @@ -26,10 +26,10 @@ // reasons why the executable file might be covered by the GNU General // Public License. -#ifndef OLN_CORE_ABSTRACT_DPOINT_HH -# define OLN_CORE_ABSTRACT_DPOINT_HH +#ifndef OLN_CORE_CONCEPT_DPOINT_HH +# define OLN_CORE_CONCEPT_DPOINT_HH -# include <oln/core/typedefs.hh> +# include <oln/core/concept/point.hh> @@ -46,103 +46,125 @@ }; - // Forward declaration. - namespace abstract { template <typename E> class dpoint; } - template <typename E> - struct set_super_type< abstract::dpoint<E> > + /// Abstract dpoint class. + template <typename Exact> + struct Dpoint : public Any<Exact> { - typedef mlc::none ret; - }; + stc_typename(grid); + stc_typename(coord); + stc_typename(dim); + stc_typename(point); + enum { n = mlc_value(dim) }; - /// Virtual types associated to abstract::dpoint<E>. - template <typename E> - struct vtypes< abstract::dpoint<E> > - { - // FIXME: Prefer to use final<deduce..> when possible. - typedef stc::abstract grid_type; - typedef stc::abstract point_type; - typedef stc::abstract coord_type; - typedef stc::abstract dim_type; - }; + /// Operator =. + bool op_equal_(const Exact& rhs) const; + /// Operator <. + bool op_less_(const Exact& rhs) const; + /// Operator +=. + Exact& op_plus_equal_(const Exact& rhs); - namespace abstract - { + /// Operator -=. + Exact& op_minus_equal_(const Exact& rhs); - /// Abstract dpoint class. - template <typename E> - class dpoint : public stc::any__simple<E>, - public oln::type - { - public: + /// Operator -. + Exact op_unary_minus_() const; - bool operator=(const abstract::dpoint<E>& rhs) const; - bool operator!=(const abstract::dpoint<E>& rhs) const; + protected: + Dpoint(); - bool operator< (const abstract::dpoint<E>& rhs) const; - bool operator> (const abstract::dpoint<E>& rhs) const; - bool operator>=(const abstract::dpoint<E>& rhs) const; - bool operator<=(const abstract::dpoint<E>& rhs) const; + }; // end of oln::Dpoint<Exact> - ~dpoint() - { - // FIXME: Code is below. - } - protected: + template <typename P, typename D> + P operator-(const Point<P>& lhs, const Dpoint<D>& rhs); - dpoint(); - }; + template <typename P, typename D> + P operator+(const Point<P>& lhs, const Dpoint<D>& rhs); + + + /// \{ + /// Invalid operators. + + template <typename D, typename P> + void operator-(const Dpoint<D>& lhs, const Point<P>& rhs) /* error */ ; + + template <typename D, typename P> + void operator+(const Dpoint<D>& lhs, const Point<P>& rhs) /* error */ ; + + /// \} # ifndef OLN_INCLUDE_ONLY - template <typename E> - bool dpoint<E>::operator=(const abstract::dpoint<E>& rhs) const + + template <typename Exact> + bool Dpoint<Exact>::op_equal_(const Exact& rhs) const { - return this->exact().impl_eq(rhs.exact()); + return exact(this)->impl_op_equal_(rhs); } - template <typename E> - bool dpoint<E>::operator!=(const abstract::dpoint<E>& rhs) const { return not (*this = rhs); } + template <typename Exact> + bool Dpoint<Exact>::op_less_(const Exact& rhs) const + { + return exact(this)->impl_op_less_(rhs); + } + + template <typename Exact> + Exact& Dpoint<Exact>::op_plus_equal_(const Exact& rhs) + { + return exact(this)->impl_op_plus_equal_(rhs); + } + + template <typename Exact> + Exact& Dpoint<Exact>::op_minus_equal_(const Exact& rhs) + { + return exact(this)->impl_op_minus_equal_(rhs); + } - template <typename E> - bool dpoint<E>::operator<(const abstract::dpoint<E>& rhs) const + template <typename Exact> + Exact Dpoint<Exact>::op_unary_minus_() const { - return this->exact().impl_less(rhs.exact()); + return exact(this)->impl_op_unary_minus_(); } - template <typename E> - bool dpoint<E>::operator> (const abstract::dpoint<E>& rhs) const { return rhs < *this; } + template <typename Exact> + Dpoint<Exact>::Dpoint() + { + // mlc::assert_defined_< oln_vtype(Exact, grid) >::check(); + // mlc::assert_defined_< oln_vtype(Exact, point) >::check(); + // mlc::assert_defined_< oln_vtype(Exact, coord) >::check(); + // mlc::assert_defined_< oln_vtype(Exact, dim) >::check(); + } - template <typename E> - bool dpoint<E>::operator>=(const abstract::dpoint<E>& rhs) const { return not (*this < rhs); } - template <typename E> - bool dpoint<E>::operator<=(const abstract::dpoint<E>& rhs) const { return not (rhs < *this); } + /// \{ + /// Operators. + + template <typename P, typename D> + P operator-(const Point<P>& lhs, const Dpoint<D>& rhs) + { + P tmp = exact(lhs); + return tmp -= rhs; + } - template <typename E> - dpoint<E>::dpoint() - {} + template <typename P, typename D> + P operator+(const Point<P>& lhs, const Dpoint<D>& rhs) + { + P tmp = exact(lhs); + return tmp += rhs; + } -// template <typename E> -// dpoint<E>::~dpoint() { -// mlc::assert_defined_< oln_vtype(E, grid) >::check(); -// mlc::assert_defined_< oln_vtype(E, point) >::check(); -// mlc::assert_defined_< oln_vtype(E, coord) >::check(); -// mlc::assert_defined_< oln_vtype(E, dim) >::check(); -// } + /// \} # endif - } // end of namespace oln::abstract - } // end of namespace oln -#endif // ! OLN_CORE_ABSTRACT_DPOINT_HH +#endif // ! OLN_CORE_CONCEPT_DPOINT_HH Index: oln/core/concept/operators.hh --- oln/core/concept/operators.hh (revision 0) +++ oln/core/concept/operators.hh (revision 0) @@ -0,0 +1,181 @@ +// Copyright (C) 2007 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 OLN_CORE_CONCEPT_OPERATORS_HH +# define OLN_CORE_CONCEPT_OPERATORS_HH + +# include <oln/core/equipment.hh> + + +namespace oln +{ + + /// \{ + /// Operator = (default version). + + template <typename L, typename R> + bool operator=(const Any<L>& lhs, const Any<R>& rhs) + { + return exact(lhs).op_equal_(exact(rhs)); + } + + /// \} + + + /// \{ + /// Operator != (default version). + + template <typename L, typename R> + bool operator!=(const Any<L>& lhs, const Any<R>& rhs) + { + return not (lhs = rhs); + } + + /// \} + + + /// \{ + /// Operator < (default version). + + template <typename L, typename R> + bool operator< (const Any<L>& lhs, const Any<R>& rhs) + { + return exact(lhs).op_less_(exact(rhs)); + } + + /// \} + + + /// \{ + /// Operator > (default version). + + template <typename L, typename R> + bool operator> (const Any<L>& lhs, const Any<R>& rhs) + { + return rhs < lhs; + } + + /// \} + + + /// \{ + /// Operator >= (default version). + + template <typename L, typename R> + bool operator>=(const Any<L>& lhs, const Any<R>& rhs) + { + return not (lhs < rhs); + } + + /// \} + + + /// \{ + /// Operator <= (default version). + + template <typename L, typename R> + bool operator<=(const Any<L>& lhs, const Any<R>& rhs) + { + return not (rhs < lhs); + } + + /// \} + + + /// \{ + /// Operator += (default version). + + template <typename L, typename R> + L& operator+=(Any<L>& lhs, const Any<R>& rhs) + { + return exact(lhs).op_plus_equal_(exact(rhs)); + } + + /// \} + + + /// \{ + /// Operators + (default versions). + + template <typename T> + T operator+ (const Any<T>& lhs, const Any<T>& rhs) + { + T tmp = exact(lhs); + return tmp += rhs; + } + +// template <typename L, typename R> +// xtd_op_plus_trait(L, R) operator+ (const Any<L>& lhs, const Any<R>& rhs) +// { +// return exact(lhs).op_plus_(exact(rhs)); +// } + + /// \} + + + /// \{ + /// Operator -= (default version). + + template <typename L, typename R> + L& operator-=(Any<L>& lhs, const Any<R>& rhs) + { + return exact(lhs).op_minus_equal_(exact(rhs)); + } + + /// \} + + + /// \{ + /// Operators - (default versions). + + template <typename T> + T operator- (const Any<T>& rhs) + { + return exact(rhs).op_unary_minus_(); + } + + template <typename T> + T operator- (const Any<T>& lhs, const Any<T>& rhs) + { + T tmp = exact(lhs); + return tmp -= rhs; + } + +// template <typename L, typename R> +// xtd_op_minus_trait(L, R) operator- (const Any<L>& lhs, const Any<R>& rhs) +// { +// return exact(lhs).op_minus_(exact(rhs)); +// } + + /// \} + + + +} // end of namespace oln + + +#endif // ! OLN_CORE_CONCEPT_OPERATORS_HH Index: oln/core/2d/dpoint2d.hh --- oln/core/2d/dpoint2d.hh (revision 842) +++ oln/core/2d/dpoint2d.hh (working copy) @@ -1,4 +1,4 @@ -// Copyright (C) 2001, 2002, 2003, 2004, 2006 EPITA Research and +// Copyright (C) 2001, 2002, 2003, 2004, 2006, 2007 EPITA Research and // Development Laboratory // // This file is part of the Olena Library. This library is free @@ -29,109 +29,59 @@ #ifndef OLN_CORE_2D_DPOINT2D_HH # define OLN_CORE_2D_DPOINT2D_HH -# include <mlc/int.hh> -# include <oln/core/2d/point2d.hh> -# include <oln/core/internal/dpoint_nd.hh> +# include <oln/core/2d/grid2d.hh> +# include <oln/core/internal/dpoint2d.hh> namespace oln { - typedef dpoint2d_<int> dpoint2d; + + struct point2d; + struct dpoint2d; /// Super type. - template<typename C> - struct set_super_type< dpoint2d_<C> > + template<> + struct super_trait_< dpoint2d > { - typedef internal::dpoint_nd< dpoint2d_<C> > ret; + typedef internal::dpoint2d_< dpoint2d > ret; }; - /// Fwd decls. - template <unsigned D> struct grid_; - typedef grid_<2> grid2d; - template <typename C> struct point2d_; - typedef point2d_<int> point2d; - - - /// Virtual types associated to oln::dpoint2d_<C>. - 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; - - typedef mlc::uint_<0> row_comp_type; - typedef mlc::uint_<1> col_comp_type; + /// Virtual types. + template <> + struct vtypes< dpoint2d > + { + typedef grid2d grid; + typedef int coord; + typedef point2d point; }; - /// General 2D dpoint class. - template <typename C> - class dpoint2d_ - : public internal::dpoint_nd< dpoint2d_<C> > + /// Usual 2D dpoint class. + class dpoint2d : public internal::dpoint2d_< dpoint2d > { - typedef dpoint2d_<C> self_t; - typedef internal::dpoint_nd<self_t> super_t; - - using super_t::v_; - public: - - /// Ctor. - dpoint2d_(); - - /// Ctor. - dpoint2d_(const xtd::vec<2,C>& v); - - /// Ctor. - dpoint2d_(C row, C col); - - C row() const; - C& row(); - - C col() const; - C& col(); + /// Ctors. + dpoint2d(); + dpoint2d(int row, int col); }; # ifndef OLN_INCLUDE_ONLY - template <typename C> - dpoint2d_<C>::dpoint2d_() - { - } - - /// Ctor. - template <typename C> - dpoint2d_<C>::dpoint2d_(const xtd::vec<2,C>& v) - : super_t(v) + dpoint2d::dpoint2d() { } - /// Ctor. - template <typename C> - dpoint2d_<C>::dpoint2d_(C row, C col) - : super_t(xtd::mk_vec(row, col)) + dpoint2d::dpoint2d(int row, int col) { + this->row() = row; + this->col() = col; } - template <typename C> - C dpoint2d_<C>::row() const { return v_[0]; } - - template <typename C> - C& dpoint2d_<C>::row() { return v_[0]; } - - template <typename C> - C dpoint2d_<C>::col() const { return v_[1]; } - - template <typename C> - C& dpoint2d_<C>::col() { return v_[1]; } - # endif Index: oln/core/2d/grid2d.hh --- oln/core/2d/grid2d.hh (revision 0) +++ oln/core/2d/grid2d.hh (revision 0) @@ -0,0 +1,69 @@ +// Copyright (C) 2007 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 OLN_CORE_2D_GRID2D_HH +# define OLN_CORE_2D_GRID2D_HH + +# include <mlc/int.hh> +# include <oln/core/concept/grid.hh> + + +namespace oln +{ + + struct grid2d; + + + /// Super type. + template<> + struct super_trait_< grid2d > + { + typedef Grid< grid2d > ret; + }; + + + /// Virtual types. + template <> + struct vtypes< grid2d > + { + typedef mlc::uint_<2> dim; + }; + + + /// Rectangular grid class. + class grid2d : public Grid< grid2d > + { + public: + /// Ctor. + grid2d() {} + }; + + +} // end of namespace oln + + +#endif // ! OLN_CORE_2D_GRID2D_HH Index: oln/core/2d/point2d.hh --- oln/core/2d/point2d.hh (revision 842) +++ oln/core/2d/point2d.hh (working copy) @@ -1,4 +1,4 @@ -// Copyright (C) 2001, 2002, 2003, 2004, 2006 EPITA Research and +// Copyright (C) 2001, 2002, 2003, 2004, 2006, 2007 EPITA Research and // Development Laboratory // // This file is part of the Olena Library. This library is free @@ -29,125 +29,62 @@ #ifndef OLN_CORE_2D_POINT2D_HH # define OLN_CORE_2D_POINT2D_HH -# include <mlc/int.hh> -# include <oln/core/internal/point_nd.hh> +# include <oln/core/2d/grid2d.hh> +# include <oln/core/internal/point2d.hh> namespace oln { - /// Fwd decls. - template <unsigned D> struct grid_; - template <typename C> struct dpoint2d_; - template <typename C> struct point2d_; - - - typedef grid_<2> grid2d; - typedef dpoint2d_<int> dpoint2d; - typedef point2d_<int> point2d; - - - /* FIXME: Is this the right place for these functions (on types)? - In particular, the function on dpoint2d should be near the - definition of dpoint2d, not point2d's. */ - /// Specializations of functions point and dpoint : - /// \f$(n, coord) \rightarrow type\f$ for \f$n = 2\f$. - /// \{ - template <typename C> struct point_ <2, C> { typedef point2d_<C> ret; }; - template <typename C> struct dpoint_ <2, C> { typedef dpoint2d_<C> ret; }; - /// \} + struct point2d; + struct dpoint2d; /// Super type. - template<typename C> - struct set_super_type< point2d_<C> > + template<> + struct super_trait_< point2d > { - typedef internal::point_nd< point2d_<C> > ret; + typedef internal::point2d_< point2d > ret; }; - /// Virtual types associated to oln::point2d_<C>. - template <typename C> - struct vtypes< point2d_<C> > - { - typedef grid2d grid_type; - typedef dpoint2d dpoint_type; - typedef C coord_type; - typedef mlc::uint_<2> dim_type; - - typedef mlc::uint_<0> row_comp_type; - typedef mlc::uint_<1> col_comp_type; + /// Virtual types. + template <> + struct vtypes< point2d > + { + typedef grid2d grid; + typedef int coord; + typedef dpoint2d dpoint; }; - /// General 2D point class. - template <typename C> - class point2d_ : public internal::point_nd< point2d_<C> > + /// Usual 2D point class. + class point2d : public internal::point2d_< point2d > { - typedef point2d_<C> self_t; - typedef internal::point_nd<self_t> super_t; - - using super_t::v_; - public: - - /// Ctor. - point2d_(); - - /// Ctor. - point2d_(C row, C col); - - /// Ctor. - point2d_(const xtd::vec<2,C>& v); - - /// Dtor. - ~point2d_() - { - } - - C row() const; - C& row(); - - C col() const; - C& col(); + /// Ctors. + point2d(); + point2d(int row, int col); }; # ifndef OLN_INCLUDE_ONLY - template <typename C> - point2d_<C>::point2d_() + point2d::point2d() { } - template <typename C> - point2d_<C>::point2d_(C row, C col) - : super_t (xtd::mk_vec(row, col)) + point2d::point2d(int row, int col) { + this->row() = row; + this->col() = col; } - template <typename C> - point2d_<C>::point2d_(const xtd::vec<2,C>& v) - : super_t(v) - { - } - - template <typename C> - C point2d_<C>::row() const { return v_[0]; } - - template <typename C> - C& point2d_<C>::row() { return v_[0]; } - - template <typename C> - C point2d_<C>::col() const { return v_[1]; } - - template <typename C> - C& point2d_<C>::col() { return v_[1]; } - # endif + } // end of namespace oln Index: oln/core/equipment.hh --- oln/core/equipment.hh (revision 0) +++ oln/core/equipment.hh (revision 0) @@ -0,0 +1,65 @@ +// Copyright (C) 2007 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 OLN_CORE_EQUIPMENT_HH +# define OLN_CORE_EQUIPMENT_HH + +# include <cassert> +# include <mlc/value.hh> +# include <mlc/contract.hh> +# include <oln/stc/scoop.hh> // FIXME: Remove "oln/" later. + + +namespace oln +{ + +# include <oln/stc/scoop.hxx> // FIXME: Remove "oln/" later. + + + stc_decl_associated_type(grid); + stc_decl_associated_type(coord); + stc_decl_associated_type(dim); + stc_decl_associated_type(point); + stc_decl_associated_type(dpoint); + stc_decl_associated_type(psite); + stc_decl_associated_type(index); + stc_decl_associated_type(value); + stc_decl_associated_type(rvalue); + stc_decl_associated_type(lvalue); + stc_decl_associated_type(iter); + stc_decl_associated_type(data); + stc_decl_associated_type(box); + stc_decl_associated_type(pset); + stc_decl_associated_type(n); + + +} // end of namespace oln + + + +#endif // ! OLN_CORE_EQUIPMENT_HH + Index: oln/core/internal/tracked_ptr.hh --- oln/core/internal/tracked_ptr.hh (revision 842) +++ oln/core/internal/tracked_ptr.hh (working copy) @@ -31,6 +31,8 @@ # include <set> # include <ostream> +# include <mlc/contract.hh> + namespace oln { Index: oln/core/internal/point_base.hh --- oln/core/internal/point_base.hh (revision 841) +++ oln/core/internal/point_base.hh (working copy) @@ -1,4 +1,4 @@ -// Copyright (C) 2001, 2002, 2003, 2004, 2006 EPITA Research and +// Copyright (C) 2001, 2002, 2003, 2004, 2006, 2007 EPITA Research and // Development Laboratory // // This file is part of the Olena Library. This library is free @@ -26,104 +26,74 @@ // reasons why the executable file might be covered by the GNU General // Public License. -#ifndef OLN_CORE_INTERNAL_POINT_ND_HH -# define OLN_CORE_INTERNAL_POINT_ND_HH +#ifndef OLN_CORE_INTERNAL_POINT_BASE_HH +# define OLN_CORE_INTERNAL_POINT_BASE_HH # include <xtd/vec.hh> -# include <xtd/optraits.hh> -// FIXME: There should be a header grouping the files required to make -// the extensible traits mechanism work. -# include <oln/core/traits_id.hh> -# include <oln/value/proxy.hh> -# include <oln/core/traits.hh> +# include <mlc/int.hh> +# include <oln/core/concept/point.hh> -# include <oln/core/abstract/point.hh> -# include <oln/core/internal/dpoint_nd.hh> namespace oln { - /// Function \f$point : (n, coord) \rightarrow point type\f$. + // Fwd decl. + namespace internal { template <typename Exact> class point_base_; } - template <unsigned n, typename C> - struct point_ + template <typename Exact> + struct super_trait_< internal::point_base_<Exact> > { - typedef mlc::undefined ret; + typedef Point<Exact> ret; }; + template <typename Exact> + struct vtypes< internal::point_base_<Exact> > + { + typedef stc::abstract grid; + typedef stc_deferred(grid) grid__; + typedef stc::final<stc_type(grid__, dim)> dim; - // Forward declaration. - namespace internal { template <typename E> class point_nd; } - - - - // Super type declaration. - template <typename E> - struct set_super_type< internal::point_nd<E> > - { - typedef abstract::point<E> ret; + typedef stc::abstract coord; + typedef stc::abstract dpoint; }; -// FIXME: Already defined in vtypes< abstract::point<E> > (Why?). -// template <typename E> -// struct vtypes< internal::point_nd<E> > -// { -// private: -// typedef oln_deferred_vtype(E, dim) dim_t; -// typedef oln_deferred_vtype(E, coord) coord_t; -// public: -// typedef xtd::vec<mlc_value(dim_t), coord_t> vec_type; -// }; - namespace internal { - template <typename E> - class point_nd : public abstract::point<E> + template <typename Exact> + class point_base_ : public Point<Exact> { - typedef point_nd<E> self_t; - typedef oln_dim(E) dim_t; - typedef oln_coord(E) coord_t; - typedef oln_dpoint(E) dpoint_t; - typedef xtd::vec< mlc_value(dim_t), coord_t> vec_t; + typedef Point<Exact> super; public: - enum { n = mlc_value(dim_t) }; - - coord_t operator[](unsigned i) const; - coord_t& operator[](unsigned i); - - bool impl_equal(const self_t& rhs) const; + stc_using(grid); + stc_using(coord); + stc_using(dim); + stc_using(dpoint); - bool impl_less(const self_t& rhs) const; + coord operator[](unsigned i) const; + coord& operator[](unsigned i); - E& impl_plus_equal(const dpoint_t& rhs); + bool impl_op_equal_(const Exact& rhs) const; - E impl_plus(const dpoint_t& rhs) const; + bool impl_op_less_(const Exact& rhs) const; - E& impl_minus_equal(const dpoint_t& rhs); + Exact& impl_op_plus_equal_(const dpoint& rhs); // Definition is in dpoint_base.hh - E impl_minus(const dpoint_t& rhs) const; + Exact& impl_op_minus_equal_(const dpoint& rhs); // Likewise - dpoint_t impl_minus(const self_t& rhs) const; + dpoint impl_op_minus_(const Exact& rhs) const; // Likewise - const vec_t& impl_vec() const; - vec_t& impl_vec(); + typedef xtd::vec<n, coord> vec_t; + const vec_t& vec() const; + vec_t& vec(); protected: - - /// Ctor. - point_nd(); - - /// Ctor. - point_nd(const vec_t& v); - - /// Dtor. - ~point_nd(); + point_base_(); vec_t v_; }; @@ -131,97 +101,53 @@ # ifndef OLN_INCLUDE_ONLY - template <typename E> - typename point_nd<E>::coord_t - point_nd<E>::operator[](unsigned i) const + template <typename Exact> + typename point_base_<Exact>::coord + point_base_<Exact>::operator[](unsigned i) const { assert(i < n); return v_[i]; } - template <typename E> - typename point_nd<E>::coord_t& - point_nd<E>::operator[](unsigned i) + template <typename Exact> + typename point_base_<Exact>::coord& + point_base_<Exact>::operator[](unsigned i) { assert(i < n); return v_[i]; } - template <typename E> - bool point_nd<E>::impl_equal(const self_t& rhs) const - { - return v_ = rhs.vec(); - } - - template <typename E> - bool point_nd<E>::impl_less(const self_t& rhs) const + template <typename Exact> + bool point_base_<Exact>::impl_op_equal_(const Exact& rhs) const { - return xtd::lexi_less(v_, rhs.vec()); + return v_ = rhs.v_; } - template <typename E> - E& point_nd<E>::impl_plus_equal(const dpoint_t& rhs) + template <typename Exact> + bool point_base_<Exact>::impl_op_less_(const Exact& rhs) const { - v_ += rhs.vec(); - return this->exact(); + return xtd::lexi_less(v_, rhs.v_); } - template <typename E> - E point_nd<E>::impl_plus(const dpoint_t& rhs) const + template <typename Exact> + const typename point_base_<Exact>::vec_t& + point_base_<Exact>::vec() const { - E tmp(v_ + rhs.vec()); - return tmp; - } - - template <typename E> - E& point_nd<E>::impl_minus_equal(const typename point_nd<E>::dpoint_t& rhs) - { - v_ += rhs.vec(); - return this->exact(); - } - - template <typename E> - E point_nd<E>::impl_minus(const typename point_nd<E>::dpoint_t& rhs) const - { - E tmp(v_ - rhs.vec()); - return tmp; - } - - template <typename E> - typename point_nd<E>::dpoint_t - point_nd<E>::impl_minus(const self_t& rhs) const - { - typename point_nd<E>::dpoint_t tmp(v_ - rhs.vec()); - return tmp; + return v_; } - template <typename E> - const typename point_nd<E>::vec_t& - point_nd<E>::impl_vec() const + template <typename Exact> + typename point_base_<Exact>::vec_t& + point_base_<Exact>::vec() { return v_; } - template <typename E> - typename point_nd<E>::vec_t& - point_nd<E>::impl_vec() + template <typename Exact> + point_base_<Exact>::point_base_() { - return v_; } - template <typename E> - point_nd<E>::point_nd() - {} - - template <typename E> - point_nd<E>::point_nd(const typename point_nd<E>::vec_t& v) : - v_(v) - {} - - template <typename E> - point_nd<E>::~point_nd() - {} - # endif @@ -229,14 +155,15 @@ } // end of namespace oln::internal + template <typename Exact> + std::ostream& operator<<(std::ostream& ostr, const internal::point_base_<Exact>& p); + - template <typename E> - std::ostream& operator<<(std::ostream& ostr, const internal::point_nd<E>& p); # ifndef OLN_INCLUDE_ONLY - template <typename E> - std::ostream& operator<<(std::ostream& ostr, const internal::point_nd<E>& p) + template <typename Exact> + std::ostream& operator<<(std::ostream& ostr, const internal::point_base_<Exact>& p) { ostr << p.vec(); return ostr; @@ -246,52 +173,53 @@ - /// internal::point_nd + internal::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, internal::point_nd), - mlc_is_a(D, internal::dpoint_nd) > > - { - typedef oln_vtype(P, coord) P_coord; - typedef oln_vtype(D, coord) D_coord; - typedef xtd_op_plus_trait(P_coord, D_coord) coord; - typedef oln_vtype(P, dim) dim; - typedef typename point_<mlc_value(dim), coord>::ret ret; - }; +// /// internal::point_base_ + internal::dpoint_base_ +// 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, internal::point_base_), +// mlc_is_a(D, internal::dpoint_base_) > > +// { +// typedef oln_vtype(P, coord) P_coord; +// typedef oln_vtype(D, coord) D_coord; +// typedef xtd_op_plus_trait(P_coord, D_coord) coord; +// typedef oln_vtype(P, dim) dim; +// typedef typename point_<mlc_value(dim), coord>::ret ret; +// }; - /// internal::point_nd - internal::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, internal::point_nd), - mlc_is_a(D, internal::dpoint_nd) > > - { - typedef oln_vtype(P, coord) P_coord; - typedef oln_vtype(D, coord) D_coord; - typedef xtd_op_minus_trait(P_coord, D_coord) coord; - typedef oln_vtype(P, dim) dim; - typedef typename point_<mlc_value(dim), coord>::ret ret; - }; +// /// internal::point_base_ - internal::dpoint_base_ +// 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, internal::point_base_), +// mlc_is_a(D, internal::dpoint_base_) > > +// { +// typedef oln_vtype(P, coord) P_coord; +// typedef oln_vtype(D, coord) D_coord; +// typedef xtd_op_minus_trait(P_coord, D_coord) coord; +// typedef oln_vtype(P, dim) dim; +// typedef typename point_<mlc_value(dim), coord>::ret ret; +// }; - /// internal::point_nd - internal::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, internal::point_nd), - mlc_is_a(P2, internal::point_nd) > > - { - typedef oln_vtype(P1, coord) P1_coord; - typedef oln_vtype(P2, coord) P2_coord; - typedef xtd_op_minus_trait(P1_coord, P2_coord) coord; - typedef oln_vtype(P1, dim) dim; - typedef typename dpoint_<mlc_value(dim), coord>::ret ret; - }; +// /// internal::point_base_ - internal::point_base_ +// 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, internal::point_base_), +// mlc_is_a(P2, internal::point_base_) > > +// { +// typedef oln_vtype(P1, coord) P1_coord; +// typedef oln_vtype(P2, coord) P2_coord; +// typedef xtd_op_minus_trait(P1_coord, P2_coord) coord; +// typedef oln_vtype(P1, dim) dim; +// typedef typename dpoint_<mlc_value(dim), coord>::ret ret; +// }; } // end of namespace oln -#endif // ! OLN_CORE_INTERNAL_POINT_ND_HH + +#endif // ! OLN_CORE_INTERNAL_POINT_BASE_HH Index: oln/core/internal/dpoint2d.hh --- oln/core/internal/dpoint2d.hh (revision 0) +++ oln/core/internal/dpoint2d.hh (revision 0) @@ -0,0 +1,127 @@ +// Copyright (C) 2001, 2002, 2003, 2004, 2006, 2007 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 OLN_CORE_INTERNAL_DPOINT2D_HH +# define OLN_CORE_INTERNAL_DPOINT2D_HH + +# include <oln/core/internal/dpoint_base.hh> + + +namespace oln +{ + + + /// Fwd decls. + template <unsigned D> struct grid_; + namespace internal { template <typename Exact> struct dpoint2d_; } + + + /// Super type. + template<typename Exact> + struct super_trait_< internal::dpoint2d_<Exact> > + { + typedef internal::dpoint_base_<Exact> ret; + }; + + + /// Virtual types. + template <typename Exact> + struct vtypes< internal::dpoint2d_<Exact> > + { + }; + + + namespace internal + { + + + template <typename Exact> + class dpoint2d_ : public dpoint_base_<Exact> + { + typedef dpoint_base_<Exact> super; + stc_using(coord); + + public: + + coord row() const; + coord& row(); + + coord col() const; + coord& col(); + + protected: + dpoint2d_(); + }; + + + +# ifndef OLN_INCLUDE_ONLY + + template <typename Exact> + dpoint2d_<Exact>::dpoint2d_() + { + } + + template <typename Exact> + typename dpoint2d_<Exact>::coord + dpoint2d_<Exact>::row() const + { + return this->v_[0]; + } + + template <typename Exact> + typename dpoint2d_<Exact>::coord & + dpoint2d_<Exact>::row() + { + return this->v_[0]; + } + + template <typename Exact> + typename dpoint2d_<Exact>::coord + dpoint2d_<Exact>::col() const + { + return this->v_[1]; + } + + template <typename Exact> + typename dpoint2d_<Exact>::coord & + dpoint2d_<Exact>::col() + { + return this->v_[1]; + } + +# endif + + + } // end of namespace oln::internal + + +} // end of namespace oln + + +#endif // ! OLN_CORE_INTERNAL_DPOINT2D_HH Index: oln/core/internal/dpoint_base.hh --- oln/core/internal/dpoint_base.hh (revision 0) +++ oln/core/internal/dpoint_base.hh (revision 0) @@ -0,0 +1,230 @@ +// Copyright (C) 2001, 2002, 2003, 2004, 2006, 2007 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 OLN_CORE_INTERNAL_DPOINT_BASE_HH +# define OLN_CORE_INTERNAL_DPOINT_BASE_HH + +# include <xtd/vec.hh> +# include <mlc/int.hh> +# include <oln/core/concept/dpoint.hh> + + + +namespace oln +{ + + // Fwd decl. + namespace internal { template <typename Exact> class dpoint_base_; } + + template <typename Exact> + struct super_trait_< internal::dpoint_base_<Exact> > + { + typedef Dpoint<Exact> ret; + }; + + template <typename Exact> + struct vtypes< internal::dpoint_base_<Exact> > + { + typedef stc::abstract grid; + + typedef stc_deferred(grid) grid__; + typedef stc::final<stc_type(grid__, dim)> dim; + + typedef stc::abstract coord; + typedef stc::abstract point; + }; + + + namespace internal + { + + template <typename Exact> + class dpoint_base_ : public Dpoint<Exact> + { + typedef Dpoint<Exact> super; + + public: + + stc_using(grid); + stc_using(coord); + stc_using(dim); + stc_using(point); + + coord operator[](unsigned i) const; + coord& operator[](unsigned i); + + bool impl_op_equal_(const Exact& rhs) const; + + bool impl_op_less_(const Exact& rhs) const; + + Exact& impl_op_plus_equal_(const Exact& rhs); + + Exact& impl_op_minus_equal_(const Exact& rhs); + + Exact impl_op_unary_minus_() const; + + typedef xtd::vec<n, coord> vec_t; + const vec_t& vec() const; + vec_t& vec(); + + protected: + dpoint_base_(); + + vec_t v_; + }; + + +# ifndef OLN_INCLUDE_ONLY + + template <typename Exact> + typename dpoint_base_<Exact>::coord + dpoint_base_<Exact>::operator[](unsigned i) const + { + assert(i < n); + return v_[i]; + } + + template <typename Exact> + typename dpoint_base_<Exact>::coord& + dpoint_base_<Exact>::operator[](unsigned i) + { + assert(i < n); + return v_[i]; + } + + template <typename Exact> + bool dpoint_base_<Exact>::impl_op_equal_(const Exact& rhs) const + { + return v_ = rhs.v_; + } + + template <typename Exact> + bool dpoint_base_<Exact>::impl_op_less_(const Exact& rhs) const + { + return xtd::lexi_less(v_, rhs.v_); + } + + template <typename Exact> + Exact& dpoint_base_<Exact>::impl_op_plus_equal_(const Exact& rhs) + { + v_ += rhs.v_; + return *exact(this); + } + + template <typename Exact> + Exact& dpoint_base_<Exact>::impl_op_minus_equal_(const Exact& rhs) + { + v_ -= rhs.v_; + return *exact(this); + } + + template <typename Exact> + Exact dpoint_base_<Exact>::impl_op_unary_minus_() const + { + Exact tmp; + tmp.v_ = - v_; + return tmp; + } + + template <typename Exact> + const typename dpoint_base_<Exact>::vec_t& + dpoint_base_<Exact>::vec() const + { + return v_; + } + + template <typename Exact> + typename dpoint_base_<Exact>::vec_t& + dpoint_base_<Exact>::vec() + { + return v_; + } + + template <typename Exact> + dpoint_base_<Exact>::dpoint_base_() + { + } + + + /// Extra code for internal::point_base_<Exact>. + + template <typename Exact> + Exact& + point_base_<Exact>::impl_op_plus_equal_(const typename point_base_<Exact>::dpoint& rhs) + { + this->v_ += rhs.vec(); + return *exact(this); + } + + template <typename Exact> + Exact& + point_base_<Exact>::impl_op_minus_equal_(const typename point_base_<Exact>::dpoint& rhs) + { + this->v_ -= rhs.vec(); + return *exact(this); + } + + template <typename Exact> + typename point_base_<Exact>::dpoint + point_base_<Exact>::impl_op_minus_(const Exact& rhs) const + { + typename point_base_<Exact>::dpoint tmp; + tmp.vec() = this->v_ - rhs.vec(); + return tmp; + } + + +# endif // ! OLN_INCLUDE_ONLY + + + + } // end of namespace oln::internal + + + template <typename Exact> + std::ostream& operator<<(std::ostream& ostr, const internal::dpoint_base_<Exact>& p); + + + +# ifndef OLN_INCLUDE_ONLY + + template <typename Exact> + std::ostream& operator<<(std::ostream& ostr, const internal::dpoint_base_<Exact>& p) + { + ostr << p.vec(); + return ostr; + } + +# endif + + +} // end of namespace oln + + + +#endif // ! OLN_CORE_INTERNAL_DPOINT_BASE_HH Index: oln/core/internal/point2d.hh --- oln/core/internal/point2d.hh (revision 0) +++ oln/core/internal/point2d.hh (revision 0) @@ -0,0 +1,127 @@ +// Copyright (C) 2001, 2002, 2003, 2004, 2006, 2007 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 OLN_CORE_INTERNAL_POINT2D_HH +# define OLN_CORE_INTERNAL_POINT2D_HH + +# include <oln/core/internal/point_base.hh> + + +namespace oln +{ + + + /// Fwd decls. + template <unsigned D> struct grid_; + namespace internal { template <typename Exact> struct point2d_; } + + + /// Super type. + template<typename Exact> + struct super_trait_< internal::point2d_<Exact> > + { + typedef internal::point_base_<Exact> ret; + }; + + + /// Virtual types. + template <typename Exact> + struct vtypes< internal::point2d_<Exact> > + { + }; + + + namespace internal + { + + + template <typename Exact> + class point2d_ : public point_base_<Exact> + { + typedef point_base_<Exact> super; + stc_using(coord); + + public: + + coord row() const; + coord& row(); + + coord col() const; + coord& col(); + + protected: + point2d_(); + }; + + + +# ifndef OLN_INCLUDE_ONLY + + template <typename Exact> + point2d_<Exact>::point2d_() + { + } + + template <typename Exact> + typename point2d_<Exact>::coord + point2d_<Exact>::row() const + { + return this->v_[0]; + } + + template <typename Exact> + typename point2d_<Exact>::coord & + point2d_<Exact>::row() + { + return this->v_[0]; + } + + template <typename Exact> + typename point2d_<Exact>::coord + point2d_<Exact>::col() const + { + return this->v_[1]; + } + + template <typename Exact> + typename point2d_<Exact>::coord & + point2d_<Exact>::col() + { + return this->v_[1]; + } + +# endif + + + } // end of namespace oln::internal + + +} // end of namespace oln + + +#endif // ! OLN_CORE_INTERNAL_POINT2D_HH Index: oln/stc/scoop.hh --- oln/stc/scoop.hh (revision 0) +++ oln/stc/scoop.hh (revision 0) @@ -0,0 +1,155 @@ +// Copyright (C) 2005, 2006, 2007 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 OLN_STC_SCOOP_HH +# define OLN_STC_SCOOP_HH + +# include <mlc/flags.hh> +# include <mlc/typedef.hh> +# include <mlc/ret.hh> +# include <mlc/assert.hh> +# include <mlc/abort.hh> +# include <mlc/bool.hh> +# include <mlc/pair.hh> +# include <mlc/cmp.hh> +# include <mlc/if.hh> +# include <mlc/is_a.hh> +# include <mlc/case.hh> + + + + +namespace stc +{ + + struct not_delegated; + + struct abstract; + + template <typename T> + struct final; + + template < template <class> class > + struct is; + + typedef mlc::true_ true_; + typedef mlc::false_ false_; + + + + + /// Equality test between a couple of types. + /// \{ + template <typename T> + struct is_found : public mlc::bexpr_<true> + {}; + + template <> + struct is_found< mlc::not_found > : public mlc::bexpr_<false> + {}; + + template <typename T> + struct is_not_found : public mlc::bexpr_<false> + {}; + + template <> + struct is_not_found< mlc::not_found > : public mlc::bexpr_<true> + {}; + /// \} + + + +} // end of namespace stc + + +#define stc_decl_associated_type mlc_decl_typedef + + +#define stc_super(T) typename super_trait_< T >::ret + +#define stc_stm(From, Target) typename get_stm< From , Target >::ret + + + +// Access to associated type +# define stc_type_(From, Type) vtype<From, typedef_::Type>::ret +# define stc_type(From, Type) typename stc_type_(From, Type) + + +// below the more tolerant version is used, namely stc_deferred, +// yet it sometimes can be replaced by "stc_find_type(E, Name)" +# define stc_find_type_(From, Type) find_vtype<From, typedef_::Type>::ret +# define stc_find_type(From, Type) typename stc_find_type_(From, Type) + +// Boolean expression counterpart of stc_find_type +# define stc_type_is_found(Type) stc::is_found< stc_deferred(Type) > +# define stc_type_is_not_found(Type) stc::is_not_found< stc_deferred(Type) > + + + + + + + +// For concepts. +# define stc_typename(Type) typedef stc_type(Exact, Type) Type +# define stc_using(Type) typedef typename super::Type Type +# define stc_using_from(Abstraction, Type) typedef typename Abstraction<Exact>::Type Type +# define stc_deduce_typename(Src, Type) typedef stc_type(Src, Type) Type + + +// For impl classes. +# define stc_deferred(Type) typename deferred_vtype<Exact, typedef_::Type >::ret +# define stc_lookup(Type) typedef typename vtype< stc_type(current, exact_type), typedef_::Type>::ret Type + +// For set_impl classes. +# define stc_deferred_typename(Type) typedef stc_deferred(Type) Type + + +# define stc_deferred_type(From, Type) typename deferred_vtype< From, typedef_::Type >::ret + + + +// the macro below was called stc_prop which was ambiguous +// (that lets us think that it is true_ or false_) but the +// result is a mlc::bexpr_! +// so it has been renamed as stc_is +# define stc_is(Type) mlc::eq_< stc_find_type(E, Type), stc::true_ > + +// likewise: + +# define stc_is_not(Type) \ + mlc::or_< mlc::eq_< stc_find_type(E, Type), \ + mlc::not_found >, \ + mlc::eq_< stc_find_type(E, Type), \ + stc::false_ > > + +# define stc_prop(From, Type) typename mlc::eq_< stc_find_type(From, Type), stc::true_ >::eval + + + +#endif // ! OLN_STC_SCOOP_HH Index: oln/stc/scoop.hxx --- oln/stc/scoop.hxx (revision 0) +++ oln/stc/scoop.hxx (revision 0) @@ -0,0 +1,951 @@ + +/* \file oln/stc/scoop.hxx + \brief To be included within a namespace to import SCOOP 2 equipment. */ + + +mlc_decl_typedef(exact_); + +mlc_decl_typedef(category); +mlc_decl_typedef(behavior); +mlc_decl_typedef(delegatee); + + + +namespace ERROR +{ + + template < typename first_definition, + typename re_definition, + typename target > + struct final_vtype_redefined_; + + + template < typename first_definition, + typename declaration, + typename target > + struct vtype_declared_but_already_set_; + + + template < typename from, + typename target > + struct vtype_not_defined; + + + template < typename curr, + typename target, + typename stm > + struct wrong_final_stm_; + + + template < typename target, + typename declaration, + typename from > + struct vtype_declared_but_not_defined; + + + template <typename T> + struct _declaration_is_in_; + + template <typename T> + struct _definition_is_looked_up_from_; + + + template <typename T> + struct _for_vtype_; + + + struct no_delegatee_declared_; + + +} /* end of namespace ERROR */ + + + + +/* vtypes */ + +template <typename from_type> +struct vtypes +{ +}; + +template <typename from_type, typename type> +struct single_vtype +{ + typedef mlc::not_found ret; +}; + + + + +template <typename from_type> +struct super_trait_; + + +template <template <class> class abstraction, typename Exact> +struct super_trait_< abstraction<Exact> > +{ + typedef mlc::none ret; +}; + + + + + +/* Any */ + +template <typename Exact> +struct Any; + + +template <typename Exact> +struct super_trait_< Any<Exact> > +{ + typedef mlc::none ret; +}; + +template <typename Exact> +struct vtypes< Any<Exact> > +{ + typedef stc::final<Exact> exact_; +}; + +template <typename Exact> +struct Any +{ + typedef Exact exact_; +protected: + Any() {} +}; + + +template <typename Exact> +Exact& exact(Any<Exact>& ref) +{ + return *(Exact*)(void*)(&ref); +} + +template <typename Exact> +const Exact& exact(const Any<Exact>& cref) +{ + return *(const Exact*)(const void*)(&cref); +} + + +template <typename Exact> +Exact* exact(Any<Exact>* ptr) +{ + return (Exact*)(void*)(ptr); +} + +template <typename Exact> +const Exact* exact(const Any<Exact>* cptr) +{ + return (const Exact*)(const void*)(cptr); +} + +template <typename Exact> +const Exact* my_exact(const Any<Exact>* cptr) +{ + return (const Exact*)(const void*)(cptr); +} + + + + + + +namespace internal +{ + + + /* + * Forward declarations. + */ + + + template <typename from, typename target> + struct get_stm; + + template <typename res1, typename res2> + struct helper_get_stm; + + template <typename from, typename target> + struct first_stm; + + template <typename curr, typename target, typename stm> + struct helper_first_stm; + + + template <typename from, typename target, typename curr = from> + struct superior_find; + + template <typename from, typename target, typename curr, typename stm> + struct helper_superior_find; + + template <typename from, typename target> + struct delegator_find; + + template <typename from, typename target, typename delegatee> + struct helper_delegator_find; + + template <typename from, typename target> + struct find; + + template <typename from, typename target, typename where, typename res> + struct helper_find; + + + + template <typename from, typename target> + struct check; + + template <typename curr, typename target, typename stm> + struct helper_check; + + + + /* get_stm(from, target) + * + * Returns the statement for class 'from' corresponding to 'target'. + * This statement is either defined in 'vtypes' or in 'single_vtype'. + * + * This routine is local; it does not recourse on superior classes. + * + */ + + template <typename res1> + struct helper_get_stm <res1, mlc::not_found> + { + typedef res1 ret; + }; + + template <typename res2> + struct helper_get_stm <mlc::not_found, res2> + { + typedef res2 ret; + }; + + template <> + struct helper_get_stm <mlc::not_found, mlc::not_found> + { + typedef mlc::not_found ret; + }; + + template <typename res1, typename res2> + struct helper_get_stm /* FIXME: Insert mlc::abort_<> statement here? */ + { + /* error */ + }; + + template <typename from, typename target> + struct get_stm + { + typedef vtypes<from> decl1; + typedef typename target::template from_<decl1>::ret res1; + + typedef single_vtype<from, target> decl2; + typedef typename decl2::ret ret2; + + typedef typename helper_get_stm<res1, ret2>::ret ret; + }; + + + + + /* -------------------- */ + /* Checking algorithm. */ + /* -------------------- */ + + /* + * check_no_final_inherited + * + * FIXME: ... + */ + + template < typename orig, typename curr, typename target, + typename stm = typename get_stm<curr, target>::ret > + struct check_no_final_inherited + + : mlc::assert_< mlc_is_not_a(stm, stc::final), + ERROR::final_vtype_redefined_< orig, + mlc::pair_<curr, stm>, + target > + >, + /* rec */ check_no_final_inherited<orig, stc_super(curr), target> + { + }; + + template <typename orig, typename target, typename stm> + struct check_no_final_inherited <orig, /* if curr = */ mlc::none, target, stm> + { + }; + + + /* + * check_no_stm_inherited + * + * FIXME: ... + */ + + template < typename orig, typename curr, typename target, + typename stm = typename get_stm<curr, target>::ret > + struct check_no_stm_inherited + + : mlc::assert_< stc::is_not_found<stm>, + ERROR::vtype_declared_but_already_set_< orig, + mlc::pair_<curr, stm>, + target > + >, + /* rec */ check_no_stm_inherited<orig, stc_super(curr), target> + { + }; + + template <typename orig, typename target, typename stm> + struct check_no_stm_inherited <orig, /* if curr = */ mlc::none, target, stm> + { + }; + + + /* + * check_delegatee_inherited + */ + + template <typename curr, typename target> + struct check_delegatee_inherited + : mlc::assert_< stc::is_found< typename first_stm<curr, + typedef_::delegatee>::ret::second_elt >, + ERROR::no_delegatee_declared_ > + { + }; + + + /* + * check_final_stm + */ + + template <typename curr, typename target, typename stm> + struct check_final_stm + {}; + + template <typename curr, typename target> + struct check_final_stm < curr, target, stc::abstract > + : mlc::abort_< ERROR::wrong_final_stm_<curr, target, stc::final<stc::abstract> > > + {}; + + template <typename curr, typename target, typename T> + struct check_final_stm < curr, target, stc::final<T> > + : mlc::abort_< ERROR::wrong_final_stm_<curr, target, stc::final<stc::final<T> > > > + {}; + + template <typename curr, typename target> + struct check_final_stm < curr, target, stc::not_delegated > + : mlc::abort_< ERROR::wrong_final_stm_<curr, target, stc::final<stc::not_delegated> > > + {}; + + template <typename curr, typename target> + struct check_final_stm < curr, target, mlc::not_found > + : mlc::abort_< ERROR::wrong_final_stm_<curr, target, stc::final<mlc::not_found> > > + {}; + + + + + /* + * check(from, target) + * + * pseudo-code: + * + * check(from, target) + * { + * if (from = mlc::none) // stop because no more class + * return done; + * else + * return helper_check(from, target, get_stm(from, target)); + * } + */ + + struct dummy {}; + + template <typename target> + struct check < /* if from = */ mlc::none, target > + { + typedef dummy ret; + }; + + template <typename from, typename target> + struct check /* otherwise */ + { + typedef typename helper_check< from, target, + stc_stm(from, target) >::ret ret; + }; + + + + + /* + * pseudo-code: + * + * helper_check(curr, target, stm) + * { + * super = super(curr); + * + * if (stm = stc::abstract) { + * check_no_stm_inherited(curr, super, target); + * return check(super, target); + * } + * if (stm = stc::final<T>) { + * check_final_stm(T); + * check_no_final_inherited((curr, T), super, target); + * return check(super, target); + * } + * if (stm = stc::not_delegated) { + * check_delegatee_inherited(curr); + * check_no_final_inherited((curr, stc::not_delegated), super, target); + * return check(super, target); + * } + * if (stm = mlc::not_found) { + * return check(super, target); + * } + * // otherwise, non-final stm: + * if (stm = T) { + * check_no_final_inherited((curr, T), super, target); + * return check(super, target); + * } + * } + * + */ + + template <typename curr, typename target> + struct helper_check < curr, target, + /* if stm = */ stc::abstract > + : check_no_stm_inherited< mlc::pair_<curr, stc::abstract >, + stc_super(curr), + target > + { + typedef typename check<stc_super(curr), target>::ret ret; + }; + + template <typename curr, typename target, typename T> + struct helper_check < curr, target, + /* if stm = */ stc::final<T> > + : check_no_final_inherited< mlc::pair_<curr, stc::final<T> >, + stc_super(curr), + target > + { + /* FIXME: + check_final_stm(T); + */ + typedef typename check<stc_super(curr), target>::ret ret; + }; + + template <typename curr, typename target> + struct helper_check < curr, target, + /* if stm = */ stc::not_delegated > + : check_no_final_inherited< mlc::pair_<curr, stc::not_delegated>, + stc_super(curr), + target > + { + /* FIXME: + check_delegatee_inherited(curr); + */ + typedef typename check<stc_super(curr), target>::ret ret; + }; + + template <typename curr, typename target> + struct helper_check < curr, target, + /* if stm = */ mlc::not_found > + { + typedef typename check<stc_super(curr), target>::ret ret; + }; + + template <typename curr, typename target, typename stm> + struct helper_check /* otherwise, non-final stm */ + : check_no_final_inherited< mlc::pair_<curr, stm>, + stc_super(curr), + target > + { + typedef typename check<stc_super(curr), target>::ret ret; + }; + + + + /* ------------------- */ + /* Look-up algorithm. */ + /* ------------------- */ + + /* + * first_stm(from, target) + * + * returns a pair (Where, Value) with Value being: + * - stc::abstract + * - stc::not_delegated + * - mlc::not_found + * - a type T + * and Where being the class where the stm is found. + * + * + * helper_first_stm(curr, target, stm) + * { + * if (stm = mlc::not_found) + * return first_stm(super(curr), target); + * else if (stm = stc::final<T>) + * return pair(curr, T); + * else + * return pair(curr, stm); + * } + * + * first_stm(from, target) + * { + * if (from = mlc::none) + * return pair(mlc::none, mlc::not_found); + * else + * return helper_first_stm(from, target, + * get_stm(from, target)); + * } + * + */ + + template <typename curr, typename target> + struct helper_first_stm < curr, target, + /* if stm = */ mlc::not_found > + { + typedef typename first_stm<stc_super(curr), target>::ret ret; + }; + + template <typename curr, typename target, typename T> + struct helper_first_stm < curr, target, + /* if stm = */ stc::final<T> > + { + typedef mlc::pair_<curr, T> ret; + }; + + template <typename curr, typename target, typename stm> + struct helper_first_stm /* otherwise */ + { + typedef mlc::pair_<curr, stm> ret; + }; + + template <typename target> + struct first_stm < /* if from = */ mlc::none, target > + { + typedef mlc::pair_<mlc::none, mlc::not_found> ret; + }; + + template <typename from, typename target> + struct first_stm /* otherwise */ + { + typedef typename helper_first_stm<from, target, + stc_stm(from, target)>::ret ret; + }; + + + + /* + * superior_find(from, target) + * + * returns: + * either mlc::not_found + * or a type T + * behavior: + * - the stm stc::not_delegated is ignored + * - error when stc::abstract is reached + * + * helper_superior_find(from, target, curr, stm) + * { + * if (stm = stc::abstract) + * error("<target> declared in <curr> but not defined at <from>"); + * else if (stm = mlc::not_found or + * stm = stc::not_delegated) + * return superior_find(from, target, super(curr)); + * else if (stm = stc::final<T>) + * return T; + * else + * return stm; + * } + * + * superior_find(from, target, curr = from) + * { + * if (curr = mlc::none) + * return mlc::not_found; + * else + * return helper_superior_find(from, target, curr, + * get_stm(curr, target)); + * } + */ + + template <typename from, typename target, typename curr> + struct helper_superior_find < from, target, curr, + /* if stm = */ stc::abstract > + { + /* FIXME: error("<target> declared in <curr> but not defined at <from>"); */ + }; + + template <typename from, typename target, typename curr> + struct helper_superior_find < from, target, curr, + /* if stm = */ mlc::not_found > + { + typedef typename superior_find< from, target, + stc_super(curr) >::ret ret; + }; + + template <typename from, typename target, typename curr> + struct helper_superior_find < from, target, curr, + /* if stm = */ stc::not_delegated > + { + typedef typename superior_find< from, target, + stc_super(curr) >::ret ret; + }; + + template <typename from, typename target, typename curr, typename T> + struct helper_superior_find < from, target, curr, + /* if stm = */ stc::final<T> > + { + typedef T ret; + }; + + template <typename from, typename target, typename curr, typename stm> + struct helper_superior_find /* otherwise */ + { + typedef stm ret; + }; + + template <typename from, typename target> + struct superior_find < from, target, /* if curr = */ mlc::none > + { + typedef mlc::not_found ret; + }; + + template <typename from, typename target, typename curr> + struct superior_find /* otherwise */ + { + typedef typename helper_superior_find<from, target, curr, + stc_stm(curr, target)>::ret ret; + }; + + + + /* + * delegator_find(from, target) + * + * + * delegator_find(from, target) + * { + * precondition(target != delegatee); + * delegatee = superior_find(from, delegatee); + * if (delegatee = mlc::not_found) + * return mlc::not_found; + * else + * return find(delegatee, target); + * } + */ + + template <typename from, typename target> + struct helper_delegator_find < from, target, + /* if delegatee = */ mlc::not_found > + { + typedef mlc::not_found ret; + }; + + template <typename from, typename target, typename delegatee> + struct helper_delegator_find /* otherwise */ + { + typedef typename find<delegatee, target>::ret ret; + }; + + template <typename from, typename target> + struct delegator_find + { + typedef typename superior_find<from, typedef_::delegatee>::ret delegatee; + typedef typename helper_delegator_find<from, target, delegatee>::ret ret; + }; + + + + /* + * helper_find(from, target, where, res) + * + * + * + */ + + template <typename from, typename target, typename where> + struct helper_find < from, target, where, + /* if res = */ mlc::not_found > + { + typedef typename delegator_find<from, target>::ret ret; + }; + + template <typename from, typename target, typename where> + struct helper_find < from, target, where, + /* if res = */ stc::abstract > + { + typedef typename delegator_find<from, target>::ret res_d; + struct check_ + : mlc::assert_< stc::is_found<res_d>, + ERROR::vtype_declared_but_not_defined + < ERROR::_for_vtype_<target>, + ERROR::_declaration_is_in_<where>, + ERROR::_definition_is_looked_up_from_<from> > > + /* FIXME: error("<target> declared in <where> but not defined at <from>"); */ + { + typedef res_d ret; + }; + typedef typename check_::ret ret; + }; + + template <typename from, typename target, typename where> + struct helper_find < from, target, where, + /* if res = */ stc::not_delegated > + { + typedef typename superior_find<from, target>::ret ret; + }; + + template <typename from, typename target, typename where, typename res> + struct helper_find /* otherwise */ + { + typedef res ret; + }; + + + + /* + * find(from, target) + * + * FIXME: ... + * + * find(from, target) + * { + * if (target = delegatee) + * return superior_find(from, delegatee); + * else + * return helper_find(from, target); + * } + */ + + template <typename from> + struct find <from, /* if target = */ typedef_::delegatee > + { + typedef typename superior_find<from, typedef_::delegatee>::ret ret; + }; + + template <typename from, typename target> + struct find /* otherwise */ + { + typedef typename first_stm<from, target>::ret stm; + typedef mlc_elt(stm, 1) where; + typedef mlc_elt(stm, 2) res; + typedef typename helper_find<from, target, + where, res>::ret ret; + }; + + +} /* end of internal */ + + +/* + * find_vtype(from, target) + * + * FIXME:... + * + */ + +template <typename from, typename target> +struct deferred_vtype +{ + typedef typename internal::find<from, target>::ret ret; +}; + +template <typename from, typename target> +struct find_vtype +{ + typedef typename internal::find<from, target>::ret ret; + typedef typename internal::check<from, target>::ret chk; +}; + +template <typename from, typename target> +struct vtype +{ + typedef typename find_vtype<from, target>::ret res; + struct check_ : mlc::assert_< stc::is_found<res>, + ERROR::vtype_not_defined<from, target> > + { + typedef res ret; + }; + typedef typename check_::ret ret; +}; + + + +mlc_case_equipment_for_namespace(internal); + + + + +namespace internal +{ + + + template < template <class> class abstraction, + unsigned num = 1 > + struct selector + { + protected: selector() {} + }; + + + /* fwd decl */ + template < template <class> class abstraction, typename E, unsigned num > + struct plug_node; + + template < template <class> class abstraction, + typename E, + unsigned num, + typename another_selector = mlc::false_ > + struct next_plug_node + { + /* here: no other selector */ + protected: next_plug_node() {} + }; + + template < template <class> class abstraction, + typename E > + struct next_plug_node < abstraction, E, 1, mlc::false_ > + : public abstraction<E> + { + protected: next_plug_node() {} + }; + + + template < template <class> class abstraction, + typename E, + unsigned num > + struct next_plug_node < abstraction, + E, + num, + mlc::true_> + + : /* plug to client selectors */ + public virtual switch_< selector<abstraction, num>, E >::ret, + + /* here: another selector (number is 'num + 1') */ + public plug_node<abstraction, E, num + 1> + { + protected: next_plug_node() {} + }; + + + template < template <class> class abstraction, + typename E, + unsigned num > + struct plug_node + : public next_plug_node< abstraction, + E, + num, + typename mlc::is_defined_< case_< selector<abstraction, num>, + E, 1 > >::eval > + { + protected: plug_node() {} + }; + + + template < template <class> class abstraction, + unsigned num, + typename E > + struct default_case_ < selector<abstraction, num>, + E > + { + typedef abstraction<E> ret; + }; + + + template < template <class> class abstraction, + typename E > + struct plug : public plug_node<abstraction, E, 1> + { + protected: plug() {} + }; + + template <typename abstraction, typename E> + struct top; + + template <template<class> class abstraction, typename E> + struct top < stc::is<abstraction>, E > : public plug< abstraction, E > + { + protected: top() {} + }; + + template <typename E> + struct top < mlc::none, E > : public Any<E> + { + protected: top() {} + }; + + template <typename E> + struct top < mlc::not_found, E >; /* FIXME: Error msg here */ + + +} /* end of namespace internal */ + + +/* top class */ + +template <typename E> struct top; + +template <typename E> +struct vtypes< top<E> > +{ + typedef stc::final<E> exact; + /* default is "no category" */ +}; + +template <typename E> +struct top : public internal::top< stc_find_type(E, category), E > +{ +protected: + top() {} +}; + + + +namespace automatic +{ + + /* + * set_impl + */ + + template < template <class> class abstraction, typename behavior, typename E > + struct set_impl + /* to be defined by the client */ ; + + + + /* + * impl + */ + + template < template <class> class abstraction, typename behavior, typename E > + struct impl : public set_impl< abstraction, behavior, E > + { /* fetch */ }; + + template < template <class> class abstraction, typename E > + struct impl< abstraction, /* behavior is */ mlc::not_found, E > + { /* nothing */ }; + + template < template <class> class abstraction, typename E > + struct impl< abstraction, mlc::none /* behavior */, E > + { /* nothing */ }; + + + + /* + * get_impl + */ + + template < template <class> class abstraction, typename E > + struct get_impl : impl< abstraction, stc_find_type(E, behavior), E > + { /* depends upon behavior */ }; + + +} /* end of namespace automatic */
participants (1)
-
Thierry Geraud