
https://svn.lrde.epita.fr/svn/oln/trunk/olena I'm relieved this issue was solvable: it could have been a bad sign for the creation and use of non-toy morphers -- even if G++ 4.1 and 4.2 seem to handle this pretty good. Index: ChangeLog from Roland Levillain <roland@lrde.epita.fr> Restore the compatibility of morphers with G++ 4.0. * oln/core/macros.hh (oln_direct_type_of, oln_direct_type_of_): New macros. * oln/morpher/internal/image_extension.hh (oln): Use `oln_direct_type_of(Exact, ...)' instead of `oln_type_of(self_t, ...)'. * tests/morphers.cc (main): Add more static assertions. * tests/identity_morpher.cc: More documentation. * tests/add_neighborhood_morpher.cc: New test. * tests/Makefile.am (check_PROGRAMS): Add add_neighborhood_morpher. (add_neighborhood_morpher_SOURCES): New. oln/core/macros.hh | 30 +++++++++--- oln/morpher/internal/image_extension.hh | 7 +- tests/Makefile.am | 12 +++- tests/add_neighborhood_morpher.cc | 79 ++++++++++++++++++++++++++++++++ tests/identity_morpher.cc | 22 ++++++-- tests/morphers.cc | 19 ++++++- 6 files changed, 147 insertions, 22 deletions Index: tests/add_neighborhood_morpher.cc --- tests/add_neighborhood_morpher.cc (revision 0) +++ tests/add_neighborhood_morpher.cc (revision 0) @@ -0,0 +1,79 @@ +// Copyright (C) 2006 EPITA Research and Development Laboratory +// +// This file is part of the Olena Library. This library is free +// software; you can redistribute it and/or modify it under the terms +// of the GNU General Public License version 2 as published by the +// Free Software Foundation. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this library; see the file COPYING. If not, write to +// the Free Software Foundation, 51 Franklin Street, Fifth Floor, +// Boston, MA 02111-1307, USA. +// +// As a special exception, you may use this file as part of a free +// software library without restriction. Specifically, if other files +// instantiate templates or use macros or inline functions from this +// file, or you compile this file and link it with other files to +// produce an executable, this file does not by itself cause the +// resulting executable to be covered by the GNU General Public +// License. This exception does not however invalidate any other +// reasons why the executable file might be covered by the GNU General +// Public License. + +/// Test the identity morpher. + +#include <mlc/assert.hh> +#include <mlc/is_a.hh> + +// FIXME: We should not include oln/basics2d.hh, but only +// oln/core/2d/image2d.hh. +#include <oln/basics2d.hh> +#include <oln/morpher/add_neighborhood.hh> + +int +main() +{ + /*----------------. + | image2d<char>. | + `----------------*/ + + typedef oln::image2d<char> image_t; + + // Sanity check: interfaces realized by oln::image2d. + mlc::assert_< mlc_is_a_(image_t, oln::abstract::image2d) >::check(); + mlc::assert_< mlc_is_a_(image_t, + oln::abstract::grey_level_image) >::check(); + mlc::assert_< mlc_is_a_(image_t, + oln::abstract::not_binary_image) >::check(); + + image_t ima(42, 51); + + + /*------------------------------------. + | add_neighborhood< image2d<char> >. | + `------------------------------------*/ + + typedef oln::morpher::add_neighborhood<image_t> image_with_nbh_t; + + // Check that the instantiated add_neighborhood morpher realizes the + // same interfaces as the underlying morphed image. + mlc::assert_< mlc_is_a_(image_with_nbh_t, oln::abstract::image2d) >::check(); + mlc::assert_< mlc_is_a_(image_with_nbh_t, + oln::abstract::grey_level_image) >::check(); + mlc::assert_< mlc_is_a_(image_with_nbh_t, + oln::abstract::not_binary_image) >::check(); + // Check the type of neighborhood. + mlc::assert_< mlc_eq(oln_type_of_(image_with_nbh_t, neighborhood), + oln::neighb2d) >::check(); + + // Instantiate a neighborhood for this image type. + oln_type_of_(image_with_nbh_t, neighborhood) nbh; + // Instantiate an object, and check its methods. + image_with_nbh_t ima_with_nbh(ima, nbh); + oln::neighb2d nbh2 = ima_with_nbh.neighborhood(); +} Index: tests/morphers.cc --- tests/morphers.cc (revision 557) +++ tests/morphers.cc (working copy) @@ -25,12 +25,13 @@ // reasons why the executable file might be covered by the GNU General // Public License. -/// Test some morphers. +/// Test some morphers and morpher composition. #include <mlc/assert.hh> #include <mlc/is_a.hh> -// FIXME: We should not include oln/basics2d.hh, but oln/core/2d/image2d.hh. +// FIXME: We should not include oln/basics2d.hh, but +// oln/core/2d/image2d.hh (and oln/core/2d/neigh2d.hh ?). #include <oln/basics2d.hh> #include <oln/morpher/identity.hh> #include <oln/morpher/add_neighborhood.hh> @@ -44,12 +45,14 @@ `----------------*/ typedef oln::image2d<char> image_t; + // Sanity check: abstractions realized by oln::image2d. mlc::assert_< mlc_is_a_(image_t, oln::abstract::image2d) >::check(); mlc::assert_< mlc_is_a_(image_t, oln::abstract::grey_level_image) >::check(); mlc::assert_< mlc_is_a_(image_t, oln::abstract::not_binary_image) >::check(); + image_t ima(42, 51); @@ -58,16 +61,21 @@ `------------------------------------*/ typedef oln::morpher::add_neighborhood<image_t> image_with_nbh_t; + // Check that the instantiated neighborhood addition morpher // realizes the same abstraction as the underlying morphed image. mlc::assert_< mlc_is_a_(image_with_nbh_t, oln::abstract::image2d) >::check(); mlc::assert_< mlc_is_a_(image_with_nbh_t, oln::abstract::image_having_neighborhood) >::check(); + mlc::assert_< mlc_is_a_(image_with_nbh_t, + oln::abstract::not_binary_image) >::check(); // Check the type of neighborhood. mlc::assert_< mlc_eq(oln_type_of_(image_with_nbh_t, neighborhood), oln::neighb2d) >::check(); - oln::neighb2d nbh; + // Instantiate a neighborhood for this image type. + oln_type_of_(image_with_nbh_t, neighborhood) nbh; + // Instantiate an object, and check its methods. image_with_nbh_t ima_with_nbh(ima, nbh); oln::neighb2d nbh2 = ima_with_nbh.neighborhood(); @@ -77,15 +85,20 @@ `------------------------------------------------*/ typedef oln::morpher::identity<image_with_nbh_t> image_with_nbh_id_t; + // Check that the instantiated identity morpher realizes the same // abstraction as the underlying morphed image. mlc::assert_< mlc_is_a_(image_with_nbh_id_t, oln::abstract::image2d) >::check(); mlc::assert_< mlc_is_a_(image_with_nbh_id_t, oln::abstract::image_having_neighborhood) >::check(); + mlc::assert_< mlc_is_a_(image_with_nbh_id_t, + oln::abstract::not_binary_image) >::check(); // Check the type of neighborhood. mlc::assert_< mlc_eq(oln_type_of_(image_with_nbh_id_t, neighborhood), oln::neighb2d) >::check(); + + // Instantiate an object, and check its methods. image_with_nbh_id_t ima_with_nbh_id(ima_with_nbh); oln::neighb2d nbh3 = ima_with_nbh_id.neighborhood(); } Index: tests/Makefile.am --- tests/Makefile.am (revision 557) +++ tests/Makefile.am (working copy) @@ -11,15 +11,19 @@ check_PROGRAMS = \ grid \ - identity_morpher \ image_entry \ - morphers \ - npoints + npoints \ + \ + identity_morpher \ + add_neighborhood_morpher \ + morphers grid_SOURCES = grid.cc -identity_morpher_SOURCES = identity_morpher.cc image_entry_SOURCES = image_entry.cc npoints_SOURCES = npoints.cc +# Morphers. +identity_morpher_SOURCES = identity_morpher.cc +add_neighborhood_morpher_SOURCES = add_neighborhood_morpher.cc morphers_SOURCES = morphers.cc TESTS = $(check_PROGRAMS) Index: tests/identity_morpher.cc --- tests/identity_morpher.cc (revision 557) +++ tests/identity_morpher.cc (working copy) @@ -30,31 +30,43 @@ #include <mlc/assert.hh> #include <mlc/is_a.hh> -// FIXME: We should not include oln/basics2d.hh, but oln/core/2d/image2d.hh. +// FIXME: We should not include oln/basics2d.hh, but only +// oln/core/2d/image2d.hh. #include <oln/basics2d.hh> #include <oln/morpher/identity.hh> int main() { - + /*----------------. + | image2d<char>. | + `----------------*/ typedef oln::image2d<char> image_t; - // Sanity check: abstractions realized by oln::image2d. + + // Sanity check: interfaces realized by oln::image2d. mlc::assert_< mlc_is_a_(image_t, oln::abstract::image2d) >::check(); mlc::assert_< mlc_is_a_(image_t, oln::abstract::grey_level_image) >::check(); mlc::assert_< mlc_is_a_(image_t, oln::abstract::not_binary_image) >::check(); + image_t ima(42, 51); + + /*----------------------------. + | identity< image2d<char> >. | + `----------------------------*/ + typedef oln::morpher::identity<image_t> image_id_t; - image_id_t ima_id(ima); + // Check that the instantiated identity morpher realizes the same - // abstraction as the underlying morphed image. + // interfaces as the underlying morphed image. mlc::assert_< mlc_is_a_(image_id_t, oln::abstract::image2d) >::check(); mlc::assert_< mlc_is_a_(image_id_t, oln::abstract::grey_level_image) >::check(); mlc::assert_< mlc_is_a_(image_id_t, oln::abstract::not_binary_image) >::check(); + + image_id_t ima_id(ima); } Index: oln/core/macros.hh --- oln/core/macros.hh (revision 557) +++ oln/core/macros.hh (working copy) @@ -30,18 +30,36 @@ /// \def oln_type_of(OlnType, Alias) /// -/// Macro to retrieve an associated type \a Alias from an oln type -/// \a OlnType whose category is not specified (version to be used inside -/// a template). +/// Macro to retrieve an associated type \a Alias from the exact type of +/// an oln type \a OlnType whose category is not specified (version to be +/// used inside a template). # define oln_type_of(OlnType, Alias) \ stc_type_of(oln, void, OlnType, Alias) /// \def oln_type_of(OlnType, Alias) /// -/// Macro to retrieve an associated type \a Alias from an oln type -/// \a OlnType whose category is not specified (version to be used -/// outside a template). +/// Macro to retrieve an associated type \a Alias from the exact type of +/// an oln type \a OlnType whose category is not specified (version to be +/// used outside a template). # define oln_type_of_(OlnType, Alias) \ stc_type_of_(oln, void, OlnType, Alias) + + +/// \def oln_direct_type_of(OlnType, Alias) +/// +/// Macro to retrieve an associated type \a Alias from an oln type \a +/// OlnType directly, and whose category is not specified (version to +/// be used inside a template). +# define oln_direct_type_of(OlnType, Alias) \ + stc_direct_type_of(oln, void, OlnType, Alias) + +/// \def oln_direct_type_of_(OlnType, Alias) +/// +/// Macro to retrieve an associated type \a Alias from an oln type \a +/// OlnType directly, and whose category is not specified (version to +/// be used inside a template). +# define oln_direct_type_of_(OlnType, Alias) \ + stc_direct_type_of_(oln, void, OlnType, Alias) + #endif // ! OLENA_CORE_MACROS_HH Index: oln/morpher/internal/image_extension.hh --- oln/morpher/internal/image_extension.hh (revision 557) +++ oln/morpher/internal/image_extension.hh (working copy) @@ -58,7 +58,6 @@ typedef Image ret; }; - namespace morpher { namespace internal @@ -74,9 +73,9 @@ /// Type of morphed image. typedef Image image_t; - typedef oln_type_of(self_t, topo) topo_t; - typedef oln_type_of(self_t, value) value_t; - typedef oln_type_of(self_t, point) point_t; + typedef oln_direct_type_of(Exact, topo) topo_t; + typedef oln_direct_type_of(Exact, value) value_t; + typedef oln_direct_type_of(Exact, point) point_t; public: // FIXME: Handle the constness.