
https://svn.lrde.epita.fr/svn/oln/trunk/milena Index: ChangeLog from Nicolas Ballas <ballas@lrde.epita.fr> Start a site/psite refactorization example. * sandbox/ballas/refactorization: New. * sandbox/ballas/refactorization/test: New. * sandbox/ballas/refactorization/test/test.cc: New. * sandbox/ballas/refactorization/metal: New. * sandbox/ballas/refactorization/metal/equal.hh: New. * sandbox/ballas/refactorization/metal/bool.hh: New. * sandbox/ballas/refactorization/metal/bexpr.hh: New. * sandbox/ballas/refactorization/exact.hh: New. * sandbox/ballas/refactorization/concept.hh: New. * sandbox/ballas/refactorization/internal: New. * sandbox/ballas/refactorization/internal/exact.hh: New. * sandbox/ballas/refactorization/internal/pset_base.hh: New. * sandbox/ballas/refactorization/internal/image_base.hh: New. * sandbox/ballas/refactorization/internal/piter_base.hh: New. * sandbox/ballas/refactorization/internal/site_base.hh: New. * sandbox/ballas/refactorization/internal/psite_base.hh: New. concept.hh | 182 +++++++++++++++++++++++++++++++++++++++++++++++++ exact.hh | 95 +++++++++++++++++++++++++ internal/exact.hh | 124 +++++++++++++++++++++++++++++++++ internal/image_base.hh | 39 ++++++++++ internal/piter_base.hh | 74 +++++++++++++++++++ internal/pset_base.hh | 22 +++++ internal/psite_base.hh | 40 ++++++++++ internal/site_base.hh | 21 +++++ metal/bexpr.hh | 80 +++++++++++++++++++++ metal/bool.hh | 99 ++++++++++++++++++++++++++ metal/equal.hh | 63 ++++++++++++++++ test/test.cc | 7 + 12 files changed, 846 insertions(+) Index: sandbox/ballas/refactorization/test/test.cc --- sandbox/ballas/refactorization/test/test.cc (revision 0) +++ sandbox/ballas/refactorization/test/test.cc (revision 0) @@ -0,0 +1,7 @@ +#include <internal/image_base.hh> + + +int main() +{ + return 0; +} Index: sandbox/ballas/refactorization/metal/equal.hh --- sandbox/ballas/refactorization/metal/equal.hh (revision 0) +++ sandbox/ballas/refactorization/metal/equal.hh (revision 0) @@ -0,0 +1,63 @@ +// 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 MLN_METAL_EQUAL_HH +# define MLN_METAL_EQUAL_HH + +/*! + * \file mln/metal/equal.hh + * + * \brief FIXME. + */ + +# include <metal/bool.hh> + + +# define mlc_equal(T1, T2) mln::metal::equal< T1, T2 > + + +namespace mln +{ + + namespace metal + { + + template <typename T1, typename T2> + struct equal : false_ + {}; + + template <typename T> + struct equal< T, T > : true_ + {}; + + + } // end of namespace mln::metal + +} // end of namespace mln + + +#endif // ! MLN_METAL_EQUAL_HH Index: sandbox/ballas/refactorization/metal/bool.hh --- sandbox/ballas/refactorization/metal/bool.hh (revision 0) +++ sandbox/ballas/refactorization/metal/bool.hh (revision 0) @@ -0,0 +1,99 @@ +// 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 MLN_METAL_BOOL_HH +# define MLN_METAL_BOOL_HH + +/*! \file mln/metal/bool.hh + * + * \brief Definition of a Boolean value type. + */ + +# include <string> + + +namespace mln +{ + + namespace metal + { + + // Fwd decl. + template <bool b> struct bool_; + + + /// "true" type. + template <> + struct bool_< true > + { + typedef bool_<true> check_t; + static const bool value = true; + typedef bool_<true> eval; + static void check(); + std::string name() const { return "true"; } + }; + + typedef bool_<true> true_; + + + /// "false" type. + template <> + struct bool_< false > + { + typedef bool_<false> check_not_t; + static const bool value = false; + typedef bool_<false> eval; + static void check_not(); + std::string name() const { return "false"; } + }; + + typedef bool_<false> false_; + + +# ifndef MLN_INCLUDE_ONLY + + inline + void true_::check() + { + } + + inline + void false_::check_not() + { + } + +# endif // ! MLN_INCLUDE_ONLY + + } // end of namespace mln::metal + +} // end of namespace mln + + +# include <metal/bexpr.hh> + + +#endif // ! MLN_METAL_BOOL_HH Index: sandbox/ballas/refactorization/metal/bexpr.hh --- sandbox/ballas/refactorization/metal/bexpr.hh (revision 0) +++ sandbox/ballas/refactorization/metal/bexpr.hh (revision 0) @@ -0,0 +1,80 @@ +// 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 MLN_METAL_BEXPR_HH +# define MLN_METAL_BEXPR_HH + +/*! \file mln/metal/bexpr.hh + * + * \brief Definition of types for static Boolean expressions. + */ + +# include <metal/bool.hh> + + +# define mlc_not( B ) mln::metal::not_< B > +# define mlc_and( B1, B2 ) mln::metal::and_< B1, B2 > +# define mlc_or( B1, B2 ) mln::metal::or_ < B1, B2 > +# define mlc_xor( B1, B2 ) mln::metal::xor_< B1, B2 > + + +namespace mln +{ + + namespace metal + { + + /// Negate type. + template <typename B> + struct not_ : bool_<( ! B::value )> + {}; + + + /// And type. + template <typename L, typename R> + struct and_ : bool_<( L::value && R::value )> + {}; + + + /// Or type. + template <typename L, typename R> + struct or_ : bool_<( L::value || R::value )> + {}; + + + /// Xor type. + template <typename L, typename R> + struct xor_ : bool_<( L::value ^ R::value )> + {}; + + + } // end of namespace mln::metal + +} // end of namespace mln + + +#endif // ! MLN_METAL_BOOL_HH Index: sandbox/ballas/refactorization/exact.hh --- sandbox/ballas/refactorization/exact.hh (revision 0) +++ sandbox/ballas/refactorization/exact.hh (revision 0) @@ -0,0 +1,95 @@ +// 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 MLN_CORE_EXACT_HH +# define MLN_CORE_EXACT_HH + +/*! \file mln/core/exact.hh + * \brief Definition of the mln::exact downcast routines. + */ + +#include <internal/exact.hh> + + +/// FIXME: Doc! +#define mln_exact(T) typename internal::exact_<T>::ret + + + +namespace mln +{ + + /*! \brief Exact cast routine for mln objects. + * + * This set of routines can be used to downcast an object towards + * its exact type. The only argument, respectively \p ptr or \p + * ref, should be an mln::Object. + * + * \c The parameter E is the exact type of the object. + * + * \return The return follows the nature of the argument (either a + * pointer or a reference, const or not). + */ + /// \{ + + template <typename T> + typename internal::exact_<T>::ret* + exact(T* ptr); + + template <typename T> + typename internal::exact_<T>::ret& + exact(T& ref); + + /// \} + + +# ifndef MLN_INCLUDE_ONLY + + // exact + + template <typename T> + inline + typename internal::exact_<T>::ret* + exact(T* ptr) + { + return internal::exact_<T>::run(ptr); + } + + template <typename T> + inline + typename internal::exact_<T>::ret& + exact(T& ref) + { + return *exact(&ref); + } + +# endif // ! MLN_INCLUDE_ONLY + +} // end of namespace mln + + +#endif // ! MLN_CORE_EXACT_HH Index: sandbox/ballas/refactorization/concept.hh --- sandbox/ballas/refactorization/concept.hh (revision 0) +++ sandbox/ballas/refactorization/concept.hh (revision 0) @@ -0,0 +1,182 @@ +#ifndef CORE_CONCEPT_HH_ +# define CORE_CONCEPT_HH_ + +# include <cassert> + +/// This file describes all the concepts + +namespace mln +{ + + /// Object + template <typename E> + struct Object + { + typedef E exact_t; + protected: + Object(); + }; + + /// Site concept + template <typename E> + struct Site : public Object<E> + { + /* + typedef site + typedef dsite; + + const psite& ref_(); + */ + protected: + Site(); + }; + + + /// Psite Concept + /// Do we need a concept for representing psite? + template <typename E> + struct Psite : public Object<E> + { + /* + // Site must be different from psite, + // if site = psite, then the psite has no sense. + typedef site; + typedef psite; + + // Site conversion + const site& to_site() const; + operator point() const; + + + const psite& ref_(); + */ + + protected: + Psite(); + }; + + /// Piter concept + /// Psite iterator + /// use template specializaion for psite == site or psite != psite + /// to deal with the cast problem + template <typename E> + struct Piter : public Object<E> + { + /* + bool is_valid() const; + void start(); + void next_(); + + typedef psite; + const psite& to_psite() const; + operator psite() const; + + typedef site; + const site& to_site() const; + operator site() const; + */ + + void next(); + protected: + Piter(); + }; + + /// Pset + /// Psite set + template <typename E> + struct Pset : public Object<E> + { + /* + typedef psite; + typedef fwd_piter; + typedef bkd_piter; + + bool has(const psite& p) const; + */ + protected: + Pset(); + }; + + + ///FIXME values concepts:.... + + /// Image concept: + template <typename E> + struct Image : public Object<E> + { + /* + typedef values; + typedef rvalues; + typedef lvalues; + //typedef vset; + //const vset& destination() const; + // const vset& values() const; + bool is_ready(); + + typedef site; + typedef psite; + rvalue operator() (const psite&) const; + lvalue operator() (const psite); + bool owns_(const psite&) const; + bool has(const psite&) const; + + typedef fwd_piter; + typedef bkd_piter; + */ + + protected: + Image(); + }; + + +# ifndef MLN_INCLUDE_ONLY + + /// Object + template <typename E> + inline + Object<E>::Object() + { + } + + /// Site + template <typename E> + inline + Site<E>::Site() + { + /// FIXME + } + + /// Psite + template <typename E> + inline + Psite<E>::Psite() + { + } + + /// Piter + template <typename E> + inline + Piter<E>::Piter() + { + } + + template <typename E> + void + Piter<E>::next() + { + exact(this)->next_(); + } + + template <typename E> + Image<E>::Image() + { + /// FIXME + } + +# endif // ! MLN_INCLUDE_ONLY + +} + + + +#endif // ! CORE_CONCEPT_HH_ Index: sandbox/ballas/refactorization/internal/exact.hh --- sandbox/ballas/refactorization/internal/exact.hh (revision 0) +++ sandbox/ballas/refactorization/internal/exact.hh (revision 0) @@ -0,0 +1,124 @@ +// 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 MLN_CORE_INTERNAL_EXACT_HH +# define MLN_CORE_INTERNAL_EXACT_HH + +/*! \file mln/core/internal/exact.hh + * \brief Meta-code for the mln::exact downcast routines. + */ + +# include <concept.hh> + +namespace mln +{ + + namespace internal + { + + typedef char yes_; + struct no_ { char dummy[2]; }; + + template <typename T> + struct make_ + { + static T* ptr(); + }; + + template <unsigned id, typename T> + struct exact_ret_; + + template <typename T> + struct exact_ret_< 1, T > + { + typedef typename T::exact_t ret; + }; + + template <typename T> + struct exact_ret_< 2, T > + { + typedef T ret; + }; + + template <typename E> + yes_ exact_selector_(Object<E>*); + + no_ exact_selector_(void*); + + template <typename E, typename T> + E* exact_run_(Object<E>* t, T*); + + template <typename T> + T* exact_run_(void*, T* t); + + template <typename T> + struct exact_ + { + enum { id = sizeof(exact_selector_(make_<T>::ptr())) }; + typedef typename exact_ret_<id, T>::ret ret; + static ret* run(T* t) + { + return exact_run_(t, t); + } + }; + + template <typename T> + struct exact_<const T> + { + enum { id = sizeof(exact_selector_(make_<T>::ptr())) }; + typedef const typename exact_ret_<id, T>::ret ret; + static ret* run(const T* t) + { + return exact_run_((T*)t, (T*)t); + } + }; + + +# ifndef MLN_INCLUDE_ONLY + + template <typename E, typename T> + inline + E* exact_run_(Object<E>* t, T*) + { + return (E*)(void*)t; + } + + template <typename T> + inline + T* exact_run_(void*, T* t) + { + return t; + } + +# endif // ! MLN_INCLUDE_ONLY + + } // end of namespace mln::internal + +} // end of namespace mln + + +#endif // ! MLN_CORE_INTERNAL_EXACT_HH Index: sandbox/ballas/refactorization/internal/pset_base.hh --- sandbox/ballas/refactorization/internal/pset_base.hh (revision 0) +++ sandbox/ballas/refactorization/internal/pset_base.hh (revision 0) @@ -0,0 +1,22 @@ +#ifndef INTERNAL_PSET_BASE_HH_ +# define INTERNAL_PSET_BASE_HH_ + + +namespace mln +{ + namespace internal + { + /// pset base class + /// P is the psite type + /// FIXME: psite = site => Do we declare a site + /// typedef in site_base class? + template <typename P, typename E> + struct pset_base_ + { + typedef typename P::site site; + typedef P psite; + }; + } +} + +#endif // ! INTENAL_PSET_BASE_HH_ Index: sandbox/ballas/refactorization/internal/image_base.hh --- sandbox/ballas/refactorization/internal/image_base.hh (revision 0) +++ sandbox/ballas/refactorization/internal/image_base.hh (revision 0) @@ -0,0 +1,39 @@ +#ifndef INTERNAL_IMAGE_BASE_HH_ +# define INTERNAL_IMAGE_BASE_HH_ + +#include <concept.hh> + +namespace mln +{ + namespace internal + { + /// Image base + /// S is the point set type + template <typename S, typename E> + struct image_base_ : public Image<E> + { + typedef S pset; + typedef typename S::psite psite; + typedef typename S::site site; + + typedef typename S::fwd_piter fwd_piter; + typedef typename S::bkd_piter bkd_piter; + + protected: + image_base_(); + }; + + ///FIXME: is_ready + +# ifndef MLN_INCLUDE_ONLY + + template <typename S, typename E> + image_base_<S, E>::image_base_() + { + } + +# endif // ! MLN_INCLUDE_ONLY + } +} + +#endif // ! INTERNAL_IMAGE_BASE_HH_ Index: sandbox/ballas/refactorization/internal/piter_base.hh --- sandbox/ballas/refactorization/internal/piter_base.hh (revision 0) +++ sandbox/ballas/refactorization/internal/piter_base.hh (revision 0) @@ -0,0 +1,74 @@ +#ifndef INTERNAL_PITER_BASE_HH_ +# define INTERNAL_PITER_BASE_HH_ + +# include <concept.hh> +# include <exact.hh> +# include <metal/bool.hh> +# include <metal/equal.hh> + +namespace mln +{ + + namespace internal + { + + /// fwd declaration + template <typename E, typename B> + struct piter_base_site_cast; + + /// Psite = Site + template <typename E> + struct piter_base_site_cast<E, metal::true_> : public Piter<E> + { + }; + + /// Psite != site + template <typename E> + struct piter_base_site_cast<E, metal::false_> : public Piter<E> + { + operator typename E::site() const; + }; + + /// Piter base + template <typename E> + struct piter_base_ : + public piter_base_site_cast<E, + typename mlc_equal(typename E::site, + typename E::psite)::eval> + { + operator typename E::psite() const; + + protected: + piter_base_(); + + }; + +# ifndef MLN_INCLUDE_ONLY + + template <typename E> + piter_base_site_cast<E, metal::false_>::operator typename E::site () const + { + return exact(this)->to_site(); + } + + + template <typename E> + piter_base_<E>::operator typename E::psite () const + { + return exact(this)->to_site(); + } + + + template <typename E> + piter_base_<E>::piter_base_() + { + } + +# endif // ! MLN_INCLUDE_ONLY + + } + +} + + +#endif // !INTERNAL_PITER_BASE_HH_ Index: sandbox/ballas/refactorization/internal/site_base.hh --- sandbox/ballas/refactorization/internal/site_base.hh (revision 0) +++ sandbox/ballas/refactorization/internal/site_base.hh (revision 0) @@ -0,0 +1,21 @@ +#ifndef INTERNAL_SITE_BASE_HH_ +# define INTERNAL_SITE_BASE_HH_ + +# include <concept> + +namespace mln +{ + namespace internal + { + + /// Site base class + template <typename S, typename E> + struct site_base_ : public site_base_<E> + { + typedef S site; + }; + } +} + + +#endif // ! INTERNAL_SITE_BASE_HH_ Index: sandbox/ballas/refactorization/internal/psite_base.hh --- sandbox/ballas/refactorization/internal/psite_base.hh (revision 0) +++ sandbox/ballas/refactorization/internal/psite_base.hh (revision 0) @@ -0,0 +1,40 @@ +#ifndef INTERNAL_PSITE_BASE_HH_ +# define INTERNAL_PSITE_BASE_HH_ + +# include <concept.hh> +# include <exact.hh> + +namespace mln +{ + namespace internal + { + + template <typename E> + struct psite_base : public Psite<E> + /// FIXME Get implementation + { + operator typename E::psite () const; + + protected: + psite_base(); + }; + +# ifndef MLN_INCLUDE_ONLY + + template <typename E> + psite_base<E>::operator typename E::psite () const + { + return exact(this)->to_site(); + } + + template <typename E> + psite_base<E>::psite_base() + { + } + +# endif // !MLN_INCLUDE_ONLY + + } +} + +#endif // ! INTERNAL_PSITE_BASE_HH_