529: Fix the current implementation of image_entry, as well as some tests.

https://svn.lrde.epita.fr/svn/oln/trunk/olena I've fixed some ChangeLog entries in the previous commit, and did not post the diffs; that's why it didn't show up on the list/newsgroup. Index: ChangeLog from Roland Levillain <roland@lrde.epita.fr> Fix the current implementation of image_entry, as well as some tests. * oln/core/abstract/internal/image_impl.hh (oln::category::image): Move this declaration... * oln/core/abstract/image.hh: ...here. * oln/core/case.hh: New file. * oln/core/abstract/image_abstractions.hh, * olena/oln/core/abstract/entry.hh, * oln/core/traits.hh: Use it. * oln/Makefile.am (nobase_oln_HEADERS): Add core/case.hh. * oln/core/abstract/image_dimension.hh (oln::ERROR::UNKNOWN_GRID_TYPE): New. (oln::default_case_<grid_dim_tag, grid_type): Use it. (ext_vtype_in_category): Turn into... (ext_vtype): ...this. * oln/core/abstract/image_typeness.hh (ext_vtype_in_category): Turn into... (ext_vtype): ...this. * oln/core/typedefs.hh (oln_type_of, oln_type_of_): Move these macros... * oln/core/abstract/macros.hh: ...here, and replace the previous ones. Rename file as... * oln/core/macros.hh: ...this. Adjust header guards. * oln/core/abstract/internal/image_impl.hh: Adjust users. * oln/Makefile.am (nobase_oln_HEADERS): Remove core/abstract/macros.hh. Add core/macros.hh * oln/core/abstract/grid.hh (oln_grd_type_of, oln_grd_type_of_): Remove macros. (vtypes_in_category< category::grid, abstract::grid<G> >): Turn into... (vtypes< abstract::grid<G> >): ...this. (packed_vtypes_in_category<category::grid, G>): s/oln_grd_type_of/oln_type_of/g. * oln/core/1d/grid1d.hh, oln/core/2d/grid2d.hh, * oln/core/3d/grid3d.hh (vtypes_in_category): Turn into... (vtypes): ...this. * tests/grid.cc: s/oln_grd_type_of_/oln_type_of_/g * tests/image_entry.cc (my::dummy): New declaration. (vtypes_in_category<category::image, my::image>): Turn into... (vtypes<my::image>): ...this. Add missing virtual types. (my::image): Fix base class. (main): Remove any references to packed_vtypes_in_category<oln::category::image, my::image>, since it no longer exists. * tests/Makefile.am (AM_CPPFLAGS): Add -I$(top_srcdir)/extended. oln/Makefile.am | 9 +++--- oln/core/1d/grid1d.hh | 2 - oln/core/2d/grid2d.hh | 2 - oln/core/3d/grid3d.hh | 2 - oln/core/abstract/entry.hh | 2 - oln/core/abstract/grid.hh | 19 ++++---------- oln/core/abstract/image.hh | 8 +++++- oln/core/abstract/image_abstractions.hh | 5 --- oln/core/abstract/image_dimension.hh | 23 +++++++++++++++-- oln/core/abstract/image_typeness.hh | 3 -- oln/core/abstract/internal/image_impl.hh | 8 ------ oln/core/case.hh | 40 +++++++++++++++++++++++++++++++ oln/core/macros.hh | 28 +++++++++++++-------- oln/core/traits.hh | 6 ---- oln/core/typedefs.hh | 16 +----------- tests/Makefile.am | 4 +-- tests/grid.cc | 6 ++-- tests/image_entry.cc | 26 +++++++++++++------- 18 files changed, 127 insertions(+), 82 deletions(-) Index: tests/image_entry.cc --- tests/image_entry.cc (revision 528) +++ tests/image_entry.cc (working copy) @@ -34,11 +34,13 @@ #include <oln/core/1d/grid1d.hh> #include <oln/core/abstract/image_entry.hh> - namespace my { // Forward declaration. - class image; + struct image; + + // Dummy type. + struct dummy; } namespace oln @@ -48,7 +50,7 @@ /// Virtual types associated to my::image. template<> - struct vtypes_in_category<category::image, my::image> + struct vtypes<my::image> { // The switch for image_dimension (above image_entry) plugs the // inheritance relation to the right abstract::image_dimension @@ -59,13 +61,23 @@ // Likewise, for the switch of image_typeness using the type of // the value of the image. typedef char value_type; + + // FIXME: Dummy values. + typedef my::dummy topo_type; + typedef my::dummy psite_type; + typedef my::dummy rvalue_type; + typedef my::dummy point_type; + typedef my::dummy piter_type; + typedef my::dummy fwd_piter_type; + typedef my::dummy bkd_piter_type; + typedef my::dummy concrete_type; }; } namespace my { // A very simple 1-D image. - class image : public oln::set_super_type<my::image>::ret + class image : public oln::get_super_types<my::image>::ret { public: typedef image self_type; @@ -78,6 +90,7 @@ }; } + int main() { @@ -102,9 +115,4 @@ // Ensure we can instantiate it. my::image i; - - // Print my::image's vtypes. - // FIXME: To be removed in the final version. - oln::packed_vtypes_in_category< oln::category::image, - my::image >::echo (std::cout); } Index: tests/Makefile.am --- tests/Makefile.am (revision 528) +++ tests/Makefile.am (working copy) @@ -1,8 +1,8 @@ ## Process this file through Automake to create Makefile.in -*- Makefile -*- AM_CPPFLAGS = \ - -I$(top_srcdir)/olena -I$(top_srcdir)/static \ - -I$(top_srcdir)/metalic + -I$(top_srcdir)/olena -I$(top_srcdir)/extended \ + -I$(top_srcdir)/static -I$(top_srcdir)/metalic # FIXME: Add # # AM_CXXFLAGS = $(CXXFLAGS_STRICT) $(CXXFLAGS_OPTIMIZE) -ggdb Index: tests/grid.cc --- tests/grid.cc (revision 528) +++ tests/grid.cc (working copy) @@ -38,7 +38,7 @@ // The extra pairs of parenthesis around mlc_value are needed to // prevent the assert macro from interpreting the arguments of // mlc_value as its own. - assert((mlc_value(oln_grd_type_of_(oln::grid1d, dimvalue))) == 1); - assert((mlc_value(oln_grd_type_of_(oln::grid2d, dimvalue))) == 2); - assert((mlc_value(oln_grd_type_of_(oln::grid3d, dimvalue))) == 3); + assert((mlc_value(oln_type_of_(oln::grid1d, dimvalue))) == 1); + assert((mlc_value(oln_type_of_(oln::grid2d, dimvalue))) == 2); + assert((mlc_value(oln_type_of_(oln::grid3d, dimvalue))) == 3); } Index: oln/core/typedefs.hh --- oln/core/typedefs.hh (revision 528) +++ oln/core/typedefs.hh (working copy) @@ -44,20 +44,8 @@ # include <stc/vtypes.hh> # include <oln/core/type.hh> - - -/*! \macro oln_type_of(OlnType, Alias) -** -** Macro to retrieve an associated type \Alias from an oln type -** \OlnType whose category is not specified. -*/ - -# define oln_type_of(OlnType, Alias) \ -stc_type_of(oln, void, OlnType, Alias) - -# define oln_type_of_(OlnType, Alias) \ -stc_type_of_(oln, void, OlnType, Alias) - +// FIXME: Move to oln/core. +# include <oln/core/macros.hh> namespace oln Index: oln/core/macros.hh --- oln/core/macros.hh (revision 521) +++ oln/core/macros.hh (working copy) @@ -25,17 +25,23 @@ // 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 +#ifndef OLENA_CORE_MACROS_HH +# define OLENA_CORE_MACROS_HH -/// \def Shortcuts for virtual types associated to images (version to -// be used inside a template). -# define oln_type_of(ImageType, Alias) \ -stc_type_of(oln, oln::category::image, ImageType, 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 inside +/// a template). +# define oln_type_of(OlnType, Alias) \ +stc_type_of(oln, void, OlnType, Alias) -/// \def Shortcuts for virtual types associated to images (version to -// be used outside a template). -# define oln_type_of_(ImageType, Alias) \ -stc_type_of_(oln, oln::category::image, ImageType, 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). +# define oln_type_of_(OlnType, Alias) \ +stc_type_of_(oln, void, OlnType, Alias) -#endif // ! OLENA_CORE_ABSTRACT_MACROS_HH +#endif // ! OLENA_CORE_MACROS_HH Index: oln/core/abstract/image.hh --- oln/core/abstract/image.hh (revision 528) +++ oln/core/abstract/image.hh (working copy) @@ -33,10 +33,16 @@ // # include <oln/core/abstract/internal/image_impl.hh> - namespace oln { + /// Category image. + namespace category + { + struct image; + } + + /*! \namespace oln::abstract ** \brief oln::abstract namespace. */ Index: oln/core/abstract/grid.hh --- oln/core/abstract/grid.hh (revision 528) +++ oln/core/abstract/grid.hh (working copy) @@ -35,13 +35,6 @@ # include <oln/core/typedefs.hh> -# define oln_grd_type_of(GridType, Alias) \ -stc_type_of(oln, oln::category::grid, GridType, Alias) - -# define oln_grd_type_of_(GridType, Alias) \ -stc_type_of_(oln, oln::category::grid, GridType, Alias) - - namespace oln { @@ -59,7 +52,7 @@ /// Virtual types associated to oln::abstract::image. template <typename G> - struct vtypes_in_category< category::grid, abstract::grid<G> > + struct vtypes< abstract::grid<G> > { typedef mlc::undefined point_type; typedef mlc::none dpoint_type; @@ -72,11 +65,11 @@ template <typename G> struct packed_vtypes_in_category<category::grid, G> { - typedef oln_grd_type_of(G, point) point_type; - typedef oln_grd_type_of(G, dpoint) dpoint_type; - typedef oln_grd_type_of(G, coord) coord_type; - typedef oln_grd_type_of(G, size) size_type; - typedef oln_grd_type_of(G, dimvalue) dimvalue_type; + typedef oln_type_of(G, point) point_type; + typedef oln_type_of(G, dpoint) dpoint_type; + typedef oln_type_of(G, coord) coord_type; + typedef oln_type_of(G, size) size_type; + typedef oln_type_of(G, dimvalue) dimvalue_type; static void echo(std::ostream& ostr) { Index: oln/core/abstract/image_dimension.hh --- oln/core/abstract/image_dimension.hh (revision 528) +++ oln/core/abstract/image_dimension.hh (working copy) @@ -107,6 +107,24 @@ } // end of namespace oln +/*-----------------. +| Error messages. | +`-----------------*/ + +namespace oln +{ + /// Error messages raised by static assertions. + namespace ERROR + { + + template <typename Grid> + struct UNKNOWN_GRID_TYPE; + + } // end of namespace oln::ERROR + +} // end of namespace oln + + /*-------------------. | Dimension switch. | `-------------------*/ @@ -176,7 +194,7 @@ template <typename grid_type> struct default_case_<grid_dim_tag, grid_type> { - typedef mlc::abort_<grid_dim_tag> ret; + typedef mlc::abort_< grid_dim_tag, ERROR::UNKNOWN_GRID_TYPE<grid_type> > ret; }; /// \} @@ -192,8 +210,7 @@ { /// Image dimension type as an extended vtype of abstract::image. template <typename I> - struct ext_vtype_in_category< category::image, - abstract::image<I>, + struct ext_vtype< abstract::image<I>, // FIXME: Get rid of this typedef_:: qualifier. typedef_::image_dimension_type > { Index: oln/core/abstract/image_abstractions.hh --- oln/core/abstract/image_abstractions.hh (revision 528) +++ oln/core/abstract/image_abstractions.hh (working copy) @@ -28,10 +28,7 @@ #ifndef OLENA_CORE_ABSTRACT_IMAGE_ABSTRACTIONS_HH # define OLENA_CORE_ABSTRACT_IMAGE_ABSTRACTIONS_HH -# include <mlc/case.hh> - -// Add switch/case equipment in the oln namespace. -mlc_case_equipment_for_namespace(oln); +# include <oln/core/case.hh> namespace oln Index: oln/core/abstract/entry.hh --- oln/core/abstract/entry.hh (revision 528) +++ oln/core/abstract/entry.hh (working copy) @@ -29,7 +29,7 @@ # define OLENA_CORE_ABSTRACT_ENTRY_HH # include <oln/core/typedefs.hh> - +# include <oln/core/case.hh> namespace oln { Index: oln/core/abstract/image_typeness.hh --- oln/core/abstract/image_typeness.hh (revision 528) +++ oln/core/abstract/image_typeness.hh (working copy) @@ -308,8 +308,7 @@ { /// Image ``typeness'' as an extended vtype of abstract::image. template <typename I> - struct ext_vtype_in_category< category::image, - abstract::image<I>, + struct ext_vtype< abstract::image<I>, // FIXME: Get rid of this typedef_:: qualifier. typedef_::image_typeness_type > { Index: oln/core/abstract/internal/image_impl.hh --- oln/core/abstract/internal/image_impl.hh (revision 528) +++ oln/core/abstract/internal/image_impl.hh (working copy) @@ -31,19 +31,13 @@ # include <mlc/flags.hh> # include <oln/core/typedefs.hh> # include <oln/core/abstract/any.hh> -# include <oln/core/abstract/macros.hh> +# include <oln/core/macros.hh> // FIXME: To be rewtitten using Metalic's switch/case? namespace oln { - /// Category image. - namespace category - { - struct image; - } - namespace abstract { Index: oln/core/1d/grid1d.hh --- oln/core/1d/grid1d.hh (revision 528) +++ oln/core/1d/grid1d.hh (working copy) @@ -47,7 +47,7 @@ /// Virtual types associated to oln::grid1d. template <> - struct vtypes_in_category<category::grid, grid1d> + struct vtypes<grid1d> { typedef point1d point_type; typedef dpoint1d dpoint_type; Index: oln/core/traits.hh --- oln/core/traits.hh (revision 528) +++ oln/core/traits.hh (working copy) @@ -30,16 +30,12 @@ # include <mlc/assert.hh> -# include <mlc/case.hh> # include <mlc/abort.hh> # include <xtd/optraits.hh> # include <stc/exact.hh> # include <oln/core/type.hh> - - -mlc_case_equipment_for_namespace(oln); - +# include <oln/core/case.hh> namespace oln Index: oln/core/2d/grid2d.hh --- oln/core/2d/grid2d.hh (revision 528) +++ oln/core/2d/grid2d.hh (working copy) @@ -47,7 +47,7 @@ /// Virtual types associated to oln::grid2d. template <> - struct vtypes_in_category<category::grid, grid2d> + struct vtypes<grid2d> { typedef point2d point_type; typedef dpoint2d dpoint_type; Index: oln/core/3d/grid3d.hh --- oln/core/3d/grid3d.hh (revision 528) +++ oln/core/3d/grid3d.hh (working copy) @@ -47,7 +47,7 @@ /// Virtual types associated to oln::grid3d. template <> - struct vtypes_in_category<category::grid, grid3d> + struct vtypes<grid3d> { typedef point3d point_type; typedef dpoint3d dpoint_type; Index: oln/core/case.hh --- oln/core/case.hh (revision 0) +++ oln/core/case.hh (revision 0) @@ -0,0 +1,40 @@ +// 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. + +/** \file oln/core/case.hh + \brief Switch/case equipment for the oln namespace. + + Use this file to avoid unnecessary (duplicated) expansions of case_. */ + +#ifndef OLENA_CORE_CASE_HH +# define OLENA_CORE_CASE_HH + +# include <mlc/case.hh> + +mlc_case_equipment_for_namespace(oln); + +#endif // ! OLENA_CORE_CASE_HH Index: oln/Makefile.am --- oln/Makefile.am (revision 528) +++ oln/Makefile.am (working copy) @@ -2,8 +2,6 @@ olndir = $(includedir)/oln nobase_oln_HEADERS = \ - core/typedefs.hh \ - \ core/1d/grid1d.hh \ \ core/2d/grid2d.hh \ @@ -18,6 +16,9 @@ core/abstract/image_dimension.hh \ core/abstract/image_typeness.hh \ core/abstract/image_typeness_integre.hh \ - core/abstract/macros.hh \ \ - core/abstract/internal/image_impl.hh + core/abstract/internal/image_impl.hh \ + \ + core/case.hh \ + core/macros.hh \ + core/typedefs.hh
participants (1)
-
Roland Levillain