462: Lay the foundation stone of abstract::image.

https://svn.lrde.epita.fr/svn/oln/trunk/olena There is a lot of commented code in these newly imported files; this is on purpose, since disabled features are to be re-enabled as one goes along; this way, we'll let current code pass the tests. I only checked in a single abstraction hierarchy (image dimension) into the project; feel free to take part to the population of olena::abstract! You can have a look at Christophe's work on Olena's Trac Wiki : http://olena.lrde.org/trac.cgi/wiki/ImageTaxonomy The best way to re-import existing code (presumably from the prototypes/proto-1.0 source tree) is to use `svn copy', e.g.: svn copy https://svn.lrde.epita.fr/svn/oln/prototypes/proto-1.0/myfile \ path-to-my-working-copy/my-file This way, the history of the file is preserved. P.S.: A lot of copyright headers of Olena use the old postal address of the FSF. Of course, we'll run an update script later, but I think we should take the good habit of using their new address in every newly added file. Index: ChangeLog from Roland Levillain <roland@lrde.epita.fr> Lay the foundation stone of abstract::image. * oln/core/abstract/any.hh, oln/core/typedefs.hh, * oln/core/abstract/image.hh, * oln/core/abstract/internal/image_impl.hh * oln/core/abstract/image_entry.hh * oln/core/abstract/image_dimension.hh: New files (imported from Olena proto-1.0, and modified). * oln/core/abstract/macros.hh: New file. * tests/image_entry.cc: New test. * Makefile.am, oln/Makefile.am, tests/Makefile.am: New files. Makefile.am | 3 oln/Makefile.am | 13 oln/core/abstract/any.hh | 19 - oln/core/abstract/image.hh | 571 +++++++++++++++++-------------- oln/core/abstract/image_dimension.hh | 22 - oln/core/abstract/image_entry.hh | 66 +-- oln/core/abstract/internal/image_impl.hh | 95 ++++- oln/core/abstract/macros.hh | 46 ++ oln/core/typedefs.hh | 178 +++++---- tests/Makefile.am | 17 tests/image_entry.cc | 73 +++ 11 files changed, 716 insertions(+), 387 deletions(-) Index: tests/image_entry.cc --- tests/image_entry.cc (revision 0) +++ tests/image_entry.cc (revision 0) @@ -0,0 +1,73 @@ +// Copyright (C) 2006 EPITA Research and Development Laboratory +// +// This file is part of the Olena Library. This library is free +// software; you can redistribute it and/or modify it under the terms +// of the GNU General Public License version 2 as published by the +// Free Software Foundation. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +// 02110-1301 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. + +/// Test oln::abstract::image_entry. + +#include <oln/core/abstract/image_entry.hh> +#include <oln/core/abstract/image_dimension.hh> + +namespace my +{ + // Fwd decl. + class image; +} + +namespace oln +{ + // Warning, this sugar might be removed in the future. + stc_set_super(my::image, abstract::image_entry<my::image>); + + /// Virtual types associated to my::A. + template<> + struct vtypes<category::image, my::image> + { + // FIXME: Don't use the abstraction as a property, but the + // corresponding grid instead. The switch for image_dimension + // (above image_entry) should plug the inheritance relationship to + // the right image_dimension class using the sole grid information + // (the grid can be seen here as a ``tag''). + typedef stc::is_a<abstract::image1d> image_dimension_type; + }; +} + +namespace my +{ + // A very simple 1D image. + class image : public oln::set_super_type<image>::ret + { + typedef image self_type; + typedef oln_type_of_(self_type, image_dimension) image_dimension_type; + }; +} + +int +main() +{ + // Instantiate it, and check its dimension. + my::image i; + mlc::assert_< mlc_is_a_(my::image::image, oln::abstract::image1d) >::check(); +} Index: tests/Makefile.am --- tests/Makefile.am (revision 0) +++ tests/Makefile.am (revision 0) @@ -0,0 +1,17 @@ +## Process this file through Automake to create Makefile.in -*- Makefile -*- + +AM_CPPFLAGS = \ + -I$(top_srcdir)/olena -I$(top_srcdir)/static \ + -I$(top_srcdir)/metalic +# FIXME: Add +# +# AM_CXXFLAGS = $(CXXFLAGS_STRICT) $(CXXFLAGS_OPTIMIZE) -ggdb +# +# when oln.m4 is available in the distribution. + +check_PROGRAMS = \ + image_entry + +image_entry_SOURCES = image_entry.cc + +TESTS = $(check_PROGRAMS) Index: oln/core/typedefs.hh --- oln/core/typedefs.hh (revision 0) +++ oln/core/typedefs.hh (working copy) @@ -1,4 +1,4 @@ -// Copyright (C) 2005 EPITA Research and Development Laboratory +// Copyright (C) 2005, 2006 EPITA Research and Development Laboratory // // This file is part of the Olena Library. This library is free // software; you can redistribute it and/or modify it under the terms @@ -11,9 +11,9 @@ // 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, 59 Temple Place - Suite 330, Boston, -// MA 02111-1307, USA. +// along with this program; if not, write to the Free Software +// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +// 02110-1301 USA // // As a special exception, you may use this file as part of a free // software library without restriction. Specifically, if other files @@ -31,11 +31,10 @@ # include <iostream> # include <mlc/contract.hh> -# include <mlc/types.hh> +# include <mlc/flags.hh> # include <mlc/cmp.hh> # include <mlc/typedef.hh> -# include <mlc/properties.hh> -# include <mlc/to_string.hh> +# include <stc/properties.hh> # define oln_super_of_(Type) \ @@ -56,79 +55,114 @@ namespace oln { + // Namespace equipment. + stc_equip_namespace_with_properties(); - mlc_equip_namespace_with_properties(); + // Misc. - - // misc - - mlc_decl_typedef(exact_type); - - // general - - mlc_decl_typedef(grid_type); - - // iterators - - mlc_decl_typedef(iter_type); - mlc_decl_typedef(fwd_iter_type); - mlc_decl_typedef(bkd_iter_type); - - mlc_decl_typedef(piter_type); - mlc_decl_typedef(fwd_piter_type); - mlc_decl_typedef(bkd_piter_type); - - mlc_decl_typedef(qiter_type); - mlc_decl_typedef(fwd_qiter_type); - mlc_decl_typedef(bkd_qiter_type); - - mlc_decl_typedef(niter_type); - mlc_decl_typedef(fwd_niter_type); - mlc_decl_typedef(bkd_niter_type); - - // category::image - - mlc_decl_typedef(data_type); - mlc_decl_typedef(value_type); - mlc_decl_typedef(neighb_type); - mlc_decl_typedef(value_storage_type); - mlc_decl_typedef(storage_type); - mlc_decl_typedef(point_type); - mlc_decl_typedef(dpoint_type); - mlc_decl_typedef(image_type); - mlc_decl_typedef(concrete_type); +// -------------------------------------------------------------------- +// FIXME: To be enabled later. +// -------------------------------------------------------------------- +// mlc_decl_typedef(exact_type); +// -------------------------------------------------------------------- + + // General. + +// -------------------------------------------------------------------- +// FIXME: To be enabled later. +// -------------------------------------------------------------------- +// mlc_decl_typedef(grid_type); +// -------------------------------------------------------------------- + + // Iterators. + +// -------------------------------------------------------------------- +// FIXME: To be enabled later. +// -------------------------------------------------------------------- +// mlc_decl_typedef(iter_type); +// mlc_decl_typedef(fwd_iter_type); +// mlc_decl_typedef(bkd_iter_type); + +// mlc_decl_typedef(piter_type); +// mlc_decl_typedef(fwd_piter_type); +// mlc_decl_typedef(bkd_piter_type); + +// mlc_decl_typedef(qiter_type); +// mlc_decl_typedef(fwd_qiter_type); +// mlc_decl_typedef(bkd_qiter_type); + +// mlc_decl_typedef(niter_type); +// mlc_decl_typedef(fwd_niter_type); +// mlc_decl_typedef(bkd_niter_type); +// -------------------------------------------------------------------- + + // category::image. + +// -------------------------------------------------------------------- +// FIXME: To be enabled later. +// -------------------------------------------------------------------- +// mlc_decl_typedef(data_type); +// mlc_decl_typedef(value_type); +// mlc_decl_typedef(neighb_type); +// mlc_decl_typedef(value_storage_type); +// mlc_decl_typedef(storage_type); +// mlc_decl_typedef(point_type); +// mlc_decl_typedef(dpoint_type); +// mlc_decl_typedef(image_type); +// mlc_decl_typedef(concrete_type); +// -------------------------------------------------------------------- mlc_decl_typedef(delegated_type); - mlc_decl_typedef(size_type); - mlc_decl_typedef(window_type); - - mlc_decl_typedef(image_neighbness_type); - mlc_decl_typedef(image_constness_type); +// -------------------------------------------------------------------- +// FIXME: To be enabled later. +// -------------------------------------------------------------------- +// mlc_decl_typedef(size_type); +// mlc_decl_typedef(window_type); + +// mlc_decl_typedef(image_neighbness_type); +// mlc_decl_typedef(image_constness_type); +// -------------------------------------------------------------------- mlc_decl_typedef(image_dimension_type); - mlc_decl_typedef(image_typeness_type); - mlc_decl_typedef(image_valuedness_type); - mlc_decl_typedef(image_rawness_type); - - // extension in image_operators - mlc_decl_typedef(output_type); - mlc_decl_typedef(input_type); - mlc_decl_typedef(input1_type); - mlc_decl_typedef(input2_type); - - - - // category::grid - - mlc_decl_typedef(dimvalue_type); - mlc_decl_typedef(coord_type); +// -------------------------------------------------------------------- +// FIXME: To be enabled later. +// -------------------------------------------------------------------- +// mlc_decl_typedef(image_typeness_type); +// mlc_decl_typedef(image_valuedness_type); +// mlc_decl_typedef(image_rawness_type); +// -------------------------------------------------------------------- + + // Extension in image_operators. +// -------------------------------------------------------------------- +// FIXME: To be enabled later. +// -------------------------------------------------------------------- +// mlc_decl_typedef(output_type); +// mlc_decl_typedef(input_type); +// mlc_decl_typedef(input1_type); +// mlc_decl_typedef(input2_type); +// -------------------------------------------------------------------- - // category::fun1 and 2 - mlc_decl_typedef(res_type); - mlc_decl_typedef(arg_type); - mlc_decl_typedef(left_type); - mlc_decl_typedef(right_type); + // category::grid. + +// -------------------------------------------------------------------- +// FIXME: To be enabled later. +// -------------------------------------------------------------------- +// mlc_decl_typedef(dimvalue_type); +// mlc_decl_typedef(coord_type); +// -------------------------------------------------------------------- + + + // category::fun1 and category::fun2. + +// -------------------------------------------------------------------- +// FIXME: To be enabled later. +// -------------------------------------------------------------------- +// mlc_decl_typedef(res_type); +// mlc_decl_typedef(arg_type); +// mlc_decl_typedef(left_type); +// mlc_decl_typedef(right_type); +// -------------------------------------------------------------------- } // end of namespace oln Index: oln/core/abstract/image.hh --- oln/core/abstract/image.hh (revision 0) +++ oln/core/abstract/image.hh (working copy) @@ -1,4 +1,5 @@ -// Copyright (C) 2001, 2003, 2004, 2005 EPITA Research and Development Laboratory +// Copyright (C) 2001, 2003, 2004, 2005, 2006 EPITA Research and +// Development Laboratory // // This file is part of the Olena Library. This library is free // software; you can redistribute it and/or modify it under the terms @@ -11,9 +12,9 @@ // 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, 59 Temple Place - Suite 330, Boston, -// MA 02111-1307, USA. +// along with this program; if not, write to the Free Software +// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +// 02110-1301 USA // // As a special exception, you may use this file as part of a free // software library without restriction. Specifically, if other files @@ -28,15 +29,9 @@ #ifndef OLENA_CORE_ABSTRACT_IMAGE_HH # define OLENA_CORE_ABSTRACT_IMAGE_HH -# include <oln/core/typedefs.hh> - -# define oln_type_of_(ImageType, Alias) \ -mlc_type_of_(oln, oln::category::image, ImageType, Alias) - -# define oln_type_of(ImageType, Alias) \ -mlc_type_of(oln, oln::category::image, ImageType, Alias) - - +# include <mlc/cmp.hh> +# include <mlc/to_string.hh> +# include <oln/core/abstract/internal/image_impl.hh> namespace oln { @@ -48,145 +43,174 @@ // fwd decls namespace abstract { - template <typename P> class point; template <typename I> class image; - template <typename I> class image_without_nbh; - template <typename I> class readonly_image; - template <typename I> class raw_image; +// -------------------------------------------------------------------- +// FIXME: To be enabled later. +// -------------------------------------------------------------------- +// template <typename I> class image_without_nbh; +// template <typename I> class readonly_image; +// template <typename I> class raw_image; +// template <typename P> class point; +// -------------------------------------------------------------------- } - namespace category - { - struct image; - } - - - /// Default properties of any image type. + // Declare virtual types. + mlc_decl_typedef(grid_type); - template <> - struct set_default_props < category::image > + /// Virtual types associated to oln::abstract::image. + template <typename I> + struct vtypes< category::image, abstract::image<I> > { - typedef mlc::undefined_type grid_type; - - typedef mlc::undefined_type concrete_type; - typedef mlc::undefined_type value_type; - typedef mlc::undefined_type point_type; - typedef mlc::undefined_type size_type; - - typedef mlc::undefined_type piter_type; - typedef mlc::undefined_type fwd_piter_type; - typedef mlc::undefined_type bkd_piter_type; - - typedef mlc::no_type value_storage_type; - typedef mlc::no_type storage_type; - typedef mlc::no_type delegated_type; - typedef mlc::no_type neighb_type; - - - typedef is_a<abstract::image_without_nbh> image_neighbness_type; - typedef is_a<abstract::readonly_image> image_constness_type; - typedef mlc::undefined_type image_rawness_type; - typedef mlc::undefined_type image_dimension_type; - - //... + typedef I exact_type; +// -------------------------------------------------------------------- +// FIXME: To be enabled later. +// -------------------------------------------------------------------- +// typedef mlc::undefined grid_type; +// typedef mlc::undefined concrete_type; +// typedef mlc::undefined value_type; +// typedef mlc::undefined point_type; +// typedef mlc::undefined size_type; + +// typedef mlc::undefined piter_type; +// typedef mlc::undefined fwd_piter_type; +// typedef mlc::undefined bkd_piter_type; + +// typedef mlc::none value_storage_type; +// typedef mlc::none storage_type; +// -------------------------------------------------------------------- + typedef mlc::none delegated_type; +// -------------------------------------------------------------------- +// FIXME: To be enabled later. +// -------------------------------------------------------------------- +// typedef mlc::none neighb_type; + +// typedef is_a<abstract::image_without_nbh> image_neighbness_type; +// typedef is_a<abstract::readonly_image> image_constness_type; +// typedef mlc::undefined image_rawness_type; +// -------------------------------------------------------------------- + typedef mlc::undefined image_dimension_type; }; + // FIXME: This should be placed into stc/properties.hh. + template <typename Category, typename T> + struct packed_vtypes + { + // Empty. + }; /// Retrieval of any image type properties (FIXME: say 'packing'). - template <typename I> - struct get_props < category::image, I > + struct packed_vtypes < category::image, I > { - typedef oln_type_of(I, grid) grid_type; - - typedef oln_type_of(I, concrete) concrete_type; - typedef oln_type_of(I, value) value_type; - typedef oln_type_of(I, point) point_type; - typedef oln_type_of(I, size) size_type; - - typedef oln_type_of(I, piter) piter_type; - typedef oln_type_of(I, fwd_piter) fwd_piter_type; - typedef oln_type_of(I, bkd_piter) bkd_piter_type; - - typedef oln_type_of(I, value_storage) value_storage_type; - typedef oln_type_of(I, storage) storage_type; +// -------------------------------------------------------------------- +// FIXME: To be enabled later. +// -------------------------------------------------------------------- +// typedef oln_type_of(I, grid) grid_type; + +// typedef oln_type_of(I, concrete) concrete_type; +// typedef oln_type_of(I, value) value_type; +// typedef oln_type_of(I, point) point_type; +// typedef oln_type_of(I, size) size_type; + +// typedef oln_type_of(I, piter) piter_type; +// typedef oln_type_of(I, fwd_piter) fwd_piter_type; +// typedef oln_type_of(I, bkd_piter) bkd_piter_type; + +// typedef oln_type_of(I, value_storage) value_storage_type; +// typedef oln_type_of(I, storage) storage_type; +// -------------------------------------------------------------------- typedef oln_type_of(I, delegated) delegated_type; - typedef oln_type_of(I, neighb) neighb_type; +// -------------------------------------------------------------------- +// FIXME: To be enabled later. +// -------------------------------------------------------------------- +// typedef oln_type_of(I, neighb) neighb_type; - typedef oln_type_of(I, image_neighbness) image_neighbness_type; - typedef oln_type_of(I, image_constness) image_constness_type; - typedef oln_type_of(I, image_rawness) image_rawness_type; +// typedef oln_type_of(I, image_neighbness) image_neighbness_type; +// typedef oln_type_of(I, image_constness) image_constness_type; +// typedef oln_type_of(I, image_rawness) image_rawness_type; +// -------------------------------------------------------------------- typedef oln_type_of(I, image_dimension) image_dimension_type; //... static void echo(std::ostream& ostr) { - ostr << "props_of( oln::category::image, " << mlc_to_string(I) << " ) =" << std::endl + ostr + << "props_of( oln::category::image, " << mlc_to_string(I) << " ) =" + << std::endl << "{" << std::endl - - << "\t grid_type = " << mlc_to_string(grid_type) << std::endl - - << "\t concrete_type = " << mlc_to_string(concrete_type) << std::endl - << "\t value_type = " << mlc_to_string(value_type) << std::endl - << "\t point_type = " << mlc_to_string(point_type) << std::endl - << "\t size_type = " << mlc_to_string(size_type) << std::endl - - << "\t piter_type = " << mlc_to_string(piter_type) << std::endl - << "\t fwd_piter_type = " << mlc_to_string(fwd_piter_type) << std::endl - << "\t bkd_piter_type = " << mlc_to_string(bkd_piter_type) << std::endl - - << "\t value_storage_type = " << mlc_to_string(value_storage_type) << std::endl - << "\t storage_type = " << mlc_to_string(storage_type) << std::endl +// -------------------------------------------------------------------- +// FIXME: To be enabled later. +// -------------------------------------------------------------------- +// << "\t grid_type = " << mlc_to_string(grid_type) << std::endl + +// << "\t concrete_type = " << mlc_to_string(concrete_type) << std::endl +// << "\t value_type = " << mlc_to_string(value_type) << std::endl +// << "\t point_type = " << mlc_to_string(point_type) << std::endl +// << "\t size_type = " << mlc_to_string(size_type) << std::endl + +// << "\t piter_type = " << mlc_to_string(piter_type) << std::endl +// << "\t fwd_piter_type = " << mlc_to_string(fwd_piter_type) << std::endl +// << "\t bkd_piter_type = " << mlc_to_string(bkd_piter_type) << std::endl + +// << "\t value_storage_type = " << mlc_to_string(value_storage_type) << std::endl +// << "\t storage_type = " << mlc_to_string(storage_type) << std::endl +// --------------------------------------------------------------------- << "\t delegated_type = " << mlc_to_string(delegated_type) << std::endl - << "\t neighb_type = " << mlc_to_string(neighb_type) << std::endl - - << "\t image_neighbness_type = " << mlc_to_string(image_neighbness_type) << std::endl - << "\t image_constness_type = " << mlc_to_string(image_constness_type) << std::endl - << "\t image_rawness_type = " << mlc_to_string(image_rawness_type) << std::endl +// -------------------------------------------------------------------- +// FIXME: To be enabled later. +// -------------------------------------------------------------------- +// << "\t neighb_type = " << mlc_to_string(neighb_type) << std::endl + +// << "\t image_neighbness_type = " << mlc_to_string(image_neighbness_type) << std::endl +// << "\t image_constness_type = " << mlc_to_string(image_constness_type) << std::endl +// << "\t image_rawness_type = " << mlc_to_string(image_rawness_type) << std::endl +// -------------------------------------------------------------------- << "\t image_dimension_type = " << mlc_to_string(image_dimension_type) << std::endl - << "}" << std::endl; } static void ensure() { - mlc::is_ok< grid_type >::ensure(); - mlc::is_ok< concrete_type >::ensure(); - mlc::is_ok< value_type >::ensure(); - mlc::is_ok< point_type >::ensure(); - mlc::is_ok< size_type >::ensure(); - mlc::is_ok< piter_type >::ensure(); - mlc::is_ok< fwd_piter_type >::ensure(); - mlc::is_ok< bkd_piter_type >::ensure(); - - mlc::is_ok< value_storage_type >::ensure(); - mlc::is_ok< storage_type >::ensure(); - mlc::is_ok< delegated_type >::ensure(); - mlc::is_ok< neighb_type >::ensure(); - - mlc::is_ok< image_neighbness_type >::ensure(); - mlc::is_ok< image_constness_type >::ensure(); - mlc::is_ok< image_rawness_type >::ensure(); - mlc::is_ok< image_dimension_type >::ensure(); +// -------------------------------------------------------------------- +// FIXME: To be enabled later. +// -------------------------------------------------------------------- +// mlc::is_ok_< grid_type >::ensure(); +// mlc::is_ok_< concrete_type >::ensure(); +// mlc::is_ok_< value_type >::ensure(); +// mlc::is_ok_< point_type >::ensure(); +// mlc::is_ok_< size_type >::ensure(); +// mlc::is_ok_< piter_type >::ensure(); +// mlc::is_ok_< fwd_piter_type >::ensure(); +// mlc::is_ok_< bkd_piter_type >::ensure(); + +// mlc::is_ok_< value_storage_type >::ensure(); +// mlc::is_ok_< storage_type >::ensure();x +// -------------------------------------------------------------------- + mlc::is_ok_< delegated_type >::ensure(); +// -------------------------------------------------------------------- +// FIXME: To be enabled later. +// -------------------------------------------------------------------- +// mlc::is_ok_< neighb_type >::ensure(); + +// mlc::is_ok_< image_neighbness_type >::ensure(); +// mlc::is_ok_< image_constness_type >::ensure(); +// mlc::is_ok_< image_rawness_type >::ensure(); +// -------------------------------------------------------------------- + mlc::is_ok_< image_dimension_type >::ensure(); } }; - - template <typename I> - struct set_props < category::image, abstract::image<I> > - { - typedef I exact_type; - }; - - } // end of namespace oln -# include <oln/core/abstract/internal/image_impl.hh> -# include <oln/core/gen/internal/value_box.hh> +// -------------------------------------------------------------------- +// FIXME: To be enabled later. +// -------------------------------------------------------------------- +// # include <oln/core/gen/internal/value_box.hh> +// -------------------------------------------------------------------- namespace oln @@ -211,11 +235,14 @@ template <typename E> struct image : public internal::get_image_impl < image<E>, E > { - - /// typedefs - typedef oln_type_of(E, size) size_type; - typedef oln_type_of(E, value) value_type; - typedef oln_type_of(E, point) point_type; +// -------------------------------------------------------------------- +// FIXME: To be enabled later. +// -------------------------------------------------------------------- +// /// typedefs +// typedef oln_type_of(E, size) size_type; +// typedef oln_type_of(E, value) value_type; +// typedef oln_type_of(E, point) point_type; +// -------------------------------------------------------------------- /*------------------* @@ -231,10 +258,14 @@ ** size2d. */ - const size_type& size() const - { - return this->exact().impl_size(); - } +// -------------------------------------------------------------------- +// FIXME: To be enabled later. +// -------------------------------------------------------------------- +// const size_type& size() const +// { +// return this->exact().impl_size(); +// } +// -------------------------------------------------------------------- /*! \brief Return the number of points of the current image. @@ -247,10 +278,14 @@ ** not yet defined; ex: image2d<int> ima; cout << ima.npoints(); */ - unsigned long npoints() const - { - return this->exact().impl_npoints(); - } +// -------------------------------------------------------------------- +// FIXME: To be enabled later. +// -------------------------------------------------------------------- +// unsigned long npoints() const +// { +// return this->exact().impl_npoints(); +// } +// -------------------------------------------------------------------- /*! \brief Test if the point \a p belongs to the current image. @@ -263,7 +298,11 @@ ** \see hold_large */ - bool hold(const point_type& p) const; // impl is in box.hh +// -------------------------------------------------------------------- +// FIXME: To be enabled later. +// -------------------------------------------------------------------- +// bool hold(const point_type& p) const; // impl is in box.hh +// -------------------------------------------------------------------- /*! \brief Test if \a p is a proper point to access a value of @@ -280,11 +319,15 @@ ** \see hold */ - bool hold_large(const point_type& p) const - { - precondition(this->npoints() != 0); - return this->exact().impl_hold_large(p); - } +// -------------------------------------------------------------------- +// FIXME: To be enabled later. +// -------------------------------------------------------------------- +// bool hold_large(const point_type& p) const +// { +// precondition(this->npoints() != 0); +// return this->exact().impl_hold_large(p); +// } +// -------------------------------------------------------------------- /*! \brief Default implementation for hold_large. If not @@ -297,12 +340,16 @@ ** \see hold_large */ - bool impl_hold_large(const point_type& p) const - { - // it relies on 'impl_hold' to avoid counting one call to - // 'hold' when the effective call is 'hold_large' - return this->exact().impl_hold(p); - } +// -------------------------------------------------------------------- +// FIXME: To be enabled later. +// -------------------------------------------------------------------- +// bool impl_hold_large(const point_type& p) const +// { +// // it relies on 'impl_hold' to avoid counting one call to +// // 'hold' when the effective call is 'hold_large' +// return this->exact().impl_hold(p); +// } +// -------------------------------------------------------------------- @@ -310,11 +357,15 @@ ! concrete methods ! *------------------*/ - template <typename P> - void operator()(const oln::abstract::point<P>&) const - { - // FIXME: provide an explicit err msg, e.g., "(p) should not be used on an ima" - } +// -------------------------------------------------------------------- +// FIXME: To be enabled later. +// -------------------------------------------------------------------- +// template <typename P> +// void operator()(const oln::abstract::point<P>&) const +// { +// // FIXME: provide an explicit err msg, e.g., "(p) should not be used on an ima" +// } +// -------------------------------------------------------------------- /*! \brief Give access to the value stored at \a p in the ** current image. Precisely it returns a box that encloses this @@ -325,13 +376,17 @@ ** \see value_box */ - value_box<const E> operator[](const point_type& p) const - { - precondition(this->npoints() != 0); - precondition(this->hold_large(p)); - value_box<const E> tmp(this->exact(), p); - return tmp; - } +// -------------------------------------------------------------------- +// FIXME: To be enabled later. +// -------------------------------------------------------------------- +// value_box<const E> operator[](const point_type& p) const +// { +// precondition(this->npoints() != 0); +// precondition(this->hold_large(p)); +// value_box<const E> tmp(this->exact(), p); +// return tmp; +// } +// -------------------------------------------------------------------- /*! \brief Gives access to the value stored at \a p in the @@ -343,13 +398,17 @@ ** \see value_box */ - value_box<E> operator[](const point_type& p) - { - precondition(this->npoints() != 0); - precondition(this->hold_large(p)); - value_box<E> tmp(this->exact(), p); - return tmp; - } +// -------------------------------------------------------------------- +// FIXME: To be enabled later. +// -------------------------------------------------------------------- +// value_box<E> operator[](const point_type& p) +// { +// precondition(this->npoints() != 0); +// precondition(this->hold_large(p)); +// value_box<E> tmp(this->exact(), p); +// return tmp; +// } +// -------------------------------------------------------------------- /*! \brief Destructor. @@ -357,7 +416,6 @@ virtual ~image() { - get_props<category::image, E>::ensure(); // FIXME: static check fails because "pointer to member conversion via virtual base"... // mlc_check_method_impl(E, const size_type&, size, , const); // mlc_check_method_impl(E, unsigned long, npoints, , const); @@ -390,14 +448,22 @@ ** \see value_box, abstract::image<I>::operator[](point) */ - const value_type get(const point_type& p) const; // impl is in box.hh +// -------------------------------------------------------------------- +// FIXME: To be enabled later. +// -------------------------------------------------------------------- +// const value_type get(const point_type& p) const; // impl is in box.hh +// -------------------------------------------------------------------- + +// -------------------------------------------------------------------- +// FIXME: To be enabled later. +// -------------------------------------------------------------------- // FIXME: patch! - - void resize_border(size_t new_border, bool copy_border = false) const - { - this->exact().impl_resize_border(new_border, copy_border); - } +// void resize_border(size_t new_border, bool copy_border = false) const +// { +// this->exact().impl_resize_border(new_border, copy_border); +// } +// -------------------------------------------------------------------- protected: @@ -412,100 +478,107 @@ /*! \brief Op= (protected, empty). */ void operator=(const image&) {} - }; - /*! \namespace oln::abstract::internal - ** \brief oln::abstract::internal namespace. - */ - namespace internal { - - template <typename E> - struct set_image_impl < image<E>, E > : public virtual image_impl<E> - { - - /// typedefs - - typedef typename image_impl<E>::D D; - - typedef oln_type_of(D, size) size_type; - typedef oln_type_of(D, point) point_type; - typedef oln_type_of(D, value) value_type; +// -------------------------------------------------------------------- +// FIXME: To be enabled later. +// -------------------------------------------------------------------- +// /*! \namespace oln::abstract::internal +// ** \brief oln::abstract::internal namespace. +// */ +// namespace internal { + +// template <typename E> +// struct set_image_impl < image<E>, E > : public virtual image_impl<E> +// { + +// /// typedefs + +// typedef typename image_impl<E>::D D; + +// typedef oln_type_of(D, size) size_type; +// typedef oln_type_of(D, point) point_type; +// typedef oln_type_of(D, value) value_type; + +// // delegations are "template methods" (Cf. the GOF's book) + +// const size_type& impl_size() const +// { +// const size_type& s = this->delegate().size(); +// this->exact().impl_size_extra(s); +// return s; +// } + +// unsigned long impl_npoints() const +// { +// unsigned long n = this->delegate().npoints(); +// this->exact().impl_npoints_extra(n); +// return n; +// } + +// bool impl_hold(const point_type& p) const +// { +// this->exact().impl_hold_extra(p); +// return this->delegate().hold(p); +// } + +// bool impl_hold_large(const point_type& p) const +// { +// this->exact().impl_hold_large_extra(p); +// return this->delegate().hold_large(p); +// } + +// value_box<const D> operator[](const point_type& p) const +// { +// precondition(this->hold_large(p)); +// return this->delegate().operator[](p); +// } + +// value_box<D> operator[](const point_type& p) +// { +// precondition(this->hold_large(p)); +// return this->delegate().operator[](p); +// } + +// const value_type impl_get(const point_type& p) const +// { +// this->exact().impl_get_extra(p); +// return this->delegate().get(p); +// } + +// // FIXME: patch + +// void impl_resize_border(size_t new_border, bool copy_border) const +// { +// this->delegate().impl_resize_border(new_border, copy_border); +// } + +// // extra code; default is "do nothing" + +// void impl_size_extra(const size_type& s) const {} +// void impl_npoints_extra(unsigned long n) const {} - // delegations are "template methods" (Cf. the GOF's book) - - const size_type& impl_size() const - { - const size_type& s = this->delegate().size(); - this->exact().impl_size_extra(s); - return s; - } +// void impl_hold_extra(const point_type& p) const {} +// void impl_hold_large_extra(const point_type& p) const {} - unsigned long impl_npoints() const - { - unsigned long n = this->delegate().npoints(); - this->exact().impl_npoints_extra(n); - return n; - } - - bool impl_hold(const point_type& p) const - { - this->exact().impl_hold_extra(p); - return this->delegate().hold(p); - } - - bool impl_hold_large(const point_type& p) const - { - this->exact().impl_hold_large_extra(p); - return this->delegate().hold_large(p); - } - - value_box<const D> operator[](const point_type& p) const - { - precondition(this->hold_large(p)); - return this->delegate().operator[](p); - } - - value_box<D> operator[](const point_type& p) - { - precondition(this->hold_large(p)); - return this->delegate().operator[](p); - } - - const value_type impl_get(const point_type& p) const - { - this->exact().impl_get_extra(p); - return this->delegate().get(p); - } - - // FIXME: patch - - void impl_resize_border(size_t new_border, bool copy_border) const - { - this->delegate().impl_resize_border(new_border, copy_border); - } - - // extra code; default is "do nothing" - - void impl_size_extra(const size_type& s) const {} - void impl_npoints_extra(unsigned long n) const {} - - void impl_hold_extra(const point_type& p) const {} - void impl_hold_large_extra(const point_type& p) const {} - - void impl_get_extra(const point_type&) const {} - }; +// void impl_get_extra(const point_type&) const {} +// }; - } // end of namespace oln::abstract::internal +// } // end of namespace oln::abstract::internal +// -------------------------------------------------------------------- } // end of namespace oln::abstract } // end of namespace oln -# include <oln/core/abstract/piter.hh> +// -------------------------------------------------------------------- +// FIXME: To be enabled later. +// -------------------------------------------------------------------- +// # include <oln/core/abstract/piter.hh> +// -------------------------------------------------------------------- // this allows for browsing points in file // where oln/core/abstract/image.hh is included Index: oln/core/abstract/image_entry.hh --- oln/core/abstract/image_entry.hh (revision 0) +++ oln/core/abstract/image_entry.hh (working copy) @@ -1,4 +1,4 @@ -// Copyright (C) 2005 EPITA Research and Development Laboratory +// Copyright (C) 2005, 2006 EPITA Research and Development Laboratory // // This file is part of the Olena Library. This library is free // software; you can redistribute it and/or modify it under the terms @@ -11,9 +11,9 @@ // 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, 59 Temple Place - Suite 330, Boston, -// MA 02111-1307, USA. +// along with this program; if not, write to the Free Software +// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +// 02110-1301 USA // // As a special exception, you may use this file as part of a free // software library without restriction. Specifically, if other files @@ -28,47 +28,49 @@ #ifndef OLENA_CORE_ABSTRACT_IMAGE_ENTRY_HH # define OLENA_CORE_ABSTRACT_IMAGE_ENTRY_HH -# include <oln/core/abstract/image_constness.hh> -# include <oln/core/abstract/image_dimension.hh> -# include <oln/core/abstract/image_neighbness.hh> -# include <oln/core/abstract/image_typeness.hh> -# include <oln/core/abstract/image_valuedness.hh> -# include <oln/core/abstract/image_rawness.hh> +# include <oln/core/abstract/image.hh> +# include <stc/entry.hh> - - - -namespace oln { - - // fwd decl - namespace abstract { +namespace oln +{ + namespace abstract + { + // Forward declaration. template <typename E> struct image_entry; } - // entry => no super type but a category - + /// \brief Uplink. + /// + /// oln::abstract::image<E> is not the direct super type of + /// oln::abstract::image_entry<E>, however, it is declared as such + /// using set_super_type, to make the virtual type retrieval system + /// work. template <typename E> - struct set_category < abstract::image_entry<E> > { typedef category::image ret; }; - + struct set_super_type< abstract::image_entry<E> > + { + typedef abstract::image<E> ret; + }; - namespace abstract { + namespace abstract + { template <typename E> - struct image_entry : - // intrusive: - public oln_type_of_(E, image_constness) ::template instantiated_with<E>::ret, - public oln_type_of_(E, image_dimension) ::template instantiated_with<E>::ret, - public oln_type_of_(E, image_neighbness) ::template instantiated_with<E>::ret, - public oln_type_of_(E, image_rawness) ::template instantiated_with<E>::ret, - // ... - public typeness::inheritance_switch<E>, - public valuedness::inheritance_switch<E> + struct image_entry : public stc::entry<E> { protected: image_entry() {} }; - } + /// \brief Tags for abstractions. + /// Use them instead of hard-coded numbers. + enum abstraction_tags + { + dimension_tag = 1, + constness_tag + // ... + }; + + } // end of namespace oln::abstract } // end of namespace oln Index: oln/core/abstract/macros.hh --- oln/core/abstract/macros.hh (revision 0) +++ oln/core/abstract/macros.hh (revision 0) @@ -0,0 +1,46 @@ +// Copyright (C) 2006 EPITA Research and Development Laboratory +// +// This file is part of the Olena Library. This library is free +// software; you can redistribute it and/or modify it under the terms +// of the GNU General Public License version 2 as published by the +// Free Software Foundation. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +// 02110-1301 USA +// +// As a special exception, you may use this file as part of a free +// software library without restriction. Specifically, if other files +// instantiate templates or use macros or inline functions from this +// file, or you compile this file and link it with other files to +// produce an executable, this file does not by itself cause the +// resulting executable to be covered by the GNU General Public +// License. This exception does not however invalidate any other +// reasons why the executable file might be covered by the GNU General +// Public License. + +#ifndef OLENA_CORE_ABSTRACT_MACROS_HH +# define OLENA_CORE_ABSTRACT_MACROS_HH + +// FIXME: Perhaps only ``external'' versions are really useful (since +// they are more precise), and we could get rid of other versions. +// Likewise, we could drop the stc_typeof without namespace +// information. + +/// \def Shortcuts for virtual types associated to images (version to +// be used inside a template). +# define oln_type_of(ImageType, Alias) \ +stc_typeof_in_namespace(oln, oln::category::image, ImageType, Alias) + +/// \def Shortcuts for virtual types associated to images (version to +// be used outside a template). +# define oln_type_of_(ImageType, Alias) \ +stc_typeof_in_namespace_(oln, oln::category::image, ImageType, Alias) + +#endif // ! OLENA_CORE_ABSTRACT_MACROS_HH Index: oln/core/abstract/image_dimension.hh --- oln/core/abstract/image_dimension.hh (revision 0) +++ oln/core/abstract/image_dimension.hh (working copy) @@ -1,4 +1,4 @@ -// Copyright (C) 2005 EPITA Research and Development Laboratory +// Copyright (C) 2005, 2006 EPITA Research and Development Laboratory // // This file is part of the Olena Library. This library is free // software; you can redistribute it and/or modify it under the terms @@ -11,9 +11,9 @@ // 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, 59 Temple Place - Suite 330, Boston, -// MA 02111-1307, USA. +// along with this program; if not, write to the Free Software +// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +// 02110-1301 USA // // As a special exception, you may use this file as part of a free // software library without restriction. Specifically, if other files @@ -88,4 +88,18 @@ } // end of namespace oln +// Register the dimension switch for oln::abstract::image_entry. +namespace stc +{ + template <typename E> + struct set_entry_node<E, oln::abstract::dimension_tag> : + // FIXME: Don't use the abstraction as a property, but the + // corresponding grid instead. + public oln_type_of_(E, image_dimension) + ::template instantiated_with<E>::ret + { + }; +} + + #endif // ! OLENA_CORE_ABSTRACT_IMAGE_DIMENSION_HH Index: oln/core/abstract/any.hh --- oln/core/abstract/any.hh (revision 0) +++ oln/core/abstract/any.hh (working copy) @@ -1,4 +1,5 @@ -// Copyright (C) 2001, 2002, 2003, 2004, 2005 EPITA Research and Development Laboratory +// Copyright (C) 2001, 2002, 2003, 2004, 2005, 2006 EPITA Research and +// Development Laboratory // // This file is part of the Olena Library. This library is free // software; you can redistribute it and/or modify it under the terms @@ -11,9 +12,9 @@ // 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, 59 Temple Place - Suite 330, Boston, -// MA 02111-1307, USA. +// along with this program; if not, write to the Free Software +// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +// 02110-1301 USA // // As a special exception, you may use this file as part of a free // software library without restriction. Specifically, if other files @@ -39,9 +40,7 @@ template <typename E> - struct any - : - public mlc::any<E, mlc::dispatch_policy::simple> + struct any : public mlc::any<E, mlc::dispatch_policy::simple> { protected: typedef mlc::any<E, mlc::dispatch_policy::simple> super; @@ -51,8 +50,7 @@ template <typename E> - struct any_best_speed - : + struct any_best_speed : public mlc::any<E, mlc::dispatch_policy::best_speed> { protected: @@ -66,7 +64,8 @@ } // end of namespace oln -# define oln_is_any(Type) mlc::or_< mlc_is_a(Type, oln::abstract::any), \ +# define oln_is_any(Type) \ + mlc::or_< mlc_is_a(Type, oln::abstract::any), \ mlc_is_a(Type, oln::abstract::any_best_speed) > Index: oln/core/abstract/internal/image_impl.hh --- oln/core/abstract/internal/image_impl.hh (revision 0) +++ oln/core/abstract/internal/image_impl.hh (working copy) @@ -1,4 +1,4 @@ -// Copyright (C) 2005 EPITA Research and Development Laboratory +// Copyright (C) 2005, 2006 EPITA Research and Development Laboratory // // This file is part of the Olena Library. This library is free // software; you can redistribute it and/or modify it under the terms @@ -11,9 +11,9 @@ // 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, 59 Temple Place - Suite 330, Boston, -// MA 02111-1307, USA. +// along with this program; if not, write to the Free Software +// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +// 02110-1301 USA // // As a special exception, you may use this file as part of a free // software library without restriction. Specifically, if other files @@ -28,47 +28,102 @@ #ifndef OLENA_CORE_ABSTRACT_INTERNAL_IMAGE_IMPL_HH # define OLENA_CORE_ABSTRACT_INTERNAL_IMAGE_IMPL_HH -# include <mlc/types.hh> +# include <mlc/flags.hh> +# include <oln/core/typedefs.hh> # include <oln/core/abstract/any.hh> +# include <oln/core/abstract/macros.hh> +// FIXME: To be rewtitten using Metalic's switch/case? -namespace oln { +namespace oln +{ + + /// Image category. + namespace category + { + struct image; + } + + namespace abstract + { + + namespace internal + { - namespace abstract { + /* A summary of the implementation retrieval mechanism. - namespace internal { - // FIXME: doc! + any_best_speed<E> any_best_speed<E> + ^ ^ + | | + |(*) | + | | + set_image_impl<A, E> | + ^ | + | | + get_image_impl_helper<A, D, E> get_image_impl_helper<A, mlc::no_type, E> + | | + `--------------. ,-----------------' + | | + o o + o + | + get_image_impl<E> + ^ + | + image<E> + ^ + | + ... + ^ + | + E + (client) + + + The D parameter is the delegated type. If there is no + delegated type (i.e. D = mlc::none), get_image_impl inherits + from oln::any_best_speed (trough get_image_impl_helper); + otherwise, get_image_impl is plugged to set_image_impl, a + class than can specialized by the user. + + (*) This relation is not mandatory (set_image_impl is to be + defined by the user), but it every specialization of + set_image_impl *should* inherit from oln::any_best_speed. */ template <typename A, typename D, typename E> struct get_image_impl_helper; - // entry point: + // Entry point. template <typename A, typename E> - struct get_image_impl : public get_image_impl_helper <A, oln_type_of(E, delegated), E> + struct get_image_impl : + public get_image_impl_helper <A, oln_type_of(E, delegated), E> { }; template <typename A, typename E> - struct get_image_impl_helper <A, mlc::no_type, E> - : + struct get_image_impl_helper <A, mlc::none, E> : public virtual oln::abstract::any_best_speed<E> { - // no impl + // No implementation. }; + // To be specialized. template <typename A, typename E> - struct set_image_impl; // to be specialized... + struct set_image_impl; template <typename A, typename D, typename E> struct get_image_impl_helper : public set_image_impl <A, E> { - // impl comes from internal::set_image_impl <A, E> + // Implementation comes from internal::set_image_impl<A, E>. }; + /// \brief Abstraction factorization for the delegation mechanism. + /// + /// set_image_impl specializations should inherit from this + /// class (as a public virtual derivation). template <typename E> - struct image_impl - : + struct image_impl : public virtual oln::abstract::any_best_speed<E> { typedef oln_type_of(E, delegated) D; @@ -76,9 +131,9 @@ const D& delegate() const { return this->exact().impl_delegate(); } }; - } // end of namespace internal + } // end of namespace oln::abstract::internal - } // end of namespace abstract + } // end of namespace oln::abstract } // end of namespace oln Index: oln/Makefile.am --- oln/Makefile.am (revision 0) +++ oln/Makefile.am (revision 0) @@ -0,0 +1,13 @@ +## Process this file through Automake to create Makefile.in -*- Makefile -*- + +olndir = $(includedir)/oln +nobase_oln_HEADERS = \ + core/typedefs.hh \ + \ + core/abstract/any.hh \ + core/abstract/image.hh \ + core/abstract/image_entry.hh \ + core/abstract/image_dimension.hh \ + core/abstract/macros.hh \ + \ + core/abstract/internal/image_impl.hh Index: Makefile.am --- Makefile.am (revision 0) +++ Makefile.am (revision 0) @@ -0,0 +1,3 @@ +## Process this file through Automake to create Makefile.in -*- Makefile -*- + +SUBDIRS = oln tests
participants (1)
-
Roland Levillain