https://svn.lrde.epita.fr/svn/oln/trunk/olena
Index: ChangeLog
from Roland Levillain <roland(a)lrde.epita.fr>
Plug image_entry's inheritance to the right image dimension
abstraction according to the grid type of the exact image type.
* oln/core/abstract/image_entry.hh: Add switch/case equipment in
the oln namespace.
* oln/core/abstract/image_dimension.hh
(grid_dim_tag)
(case_<grid_dim_tag, grid_type, 1>)
(case_<grid_dim_tag, grid_type, 2>)
(case_<grid_dim_tag, grid_type, 3>)
(default_case_<grid_dim_tag, grid_type>): New Metalic switch/case
on grid type, returning the corresponding image dimension type.
(set_entry_node<I, oln::abstract::dimension_tag>): Use this Metalic
switch/case to choose the dimension abstraction in the inheritance
tree.
* oln/core/abstract/image.hh (vtypes): Don't define
image_dimension_type as an internal vtype, instead...
* oln/core/abstract/image_dimension.hh
(oln::ext_vtype<category::image, abstract::image<I>,
typedef_::image_dimension_type>): ...define it externally, using
the switch used inheritance-plugging mechanism based on the grid
type.
* tests/image_entry.cc (oln): Adjust.
Check my::image's virtual types.
Print my::image's vtypes on the standard output.
oln/core/abstract/image.hh | 7 +--
oln/core/abstract/image_dimension.hh | 80 +++++++++++++++++++++++++++++++----
oln/core/abstract/image_entry.hh | 7 ++-
tests/image_entry.cc | 27 ++++++++---
4 files changed, 101 insertions(+), 20 deletions(-)
Index: tests/image_entry.cc
--- tests/image_entry.cc (revision 470)
+++ tests/image_entry.cc (working copy)
@@ -46,12 +46,10 @@
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;
+ // The switch for image_dimension (above image_entry) plugs the
+ // inheritance relation to the right abstract::image_dimension
+ // class using the sole grid information (the grid can be seen
+ // here as a ``tag'').
typedef oln::grid1d grid_type;
};
}
@@ -62,6 +60,9 @@
class image : public oln::set_super_type<my::image>::ret
{
typedef image self_type;
+ // An internal vtype.
+ typedef oln_type_of_(self_type, grid) grid_type;
+ // An external vtype.
typedef oln_type_of_(self_type, image_dimension) image_dimension_type;
};
}
@@ -69,7 +70,17 @@
int
main()
{
- // Instantiate it, and check its dimension.
+ // Check its internally defined vtype.
+ mlc::assert_< mlc_eq(my::image::grid_type, oln::grid1d) >::check();
+ // Check its externally defined vtype.
+ mlc::assert_< mlc_eq( my::image::image_dimension_type,
+ stc::is_a<oln::abstract::image1d> ) >::check();
+ // Check its image dimension abstraction.
+ mlc::assert_< mlc_is_a_(my::image, oln::abstract::image1d) >::check();
+ // Ensure we can instantiate it.
my::image i;
- mlc::assert_< mlc_is_a_(my::image::image, oln::abstract::image1d) >::check();
+
+ // Print my::image's vtypes.
+ // FIXME: To be removed in the final version.
+ oln::packed_vtypes<oln::category::image, my::image>::echo (std::cout);
}
Index: oln/core/abstract/image.hh
--- oln/core/abstract/image.hh (revision 470)
+++ oln/core/abstract/image.hh (working copy)
@@ -87,13 +87,13 @@
// typedef is_a<abstract::readonly_image> image_constness_type;
// typedef mlc::undefined image_rawness_type;
// --------------------------------------------------------------------
- typedef mlc::undefined image_dimension_type;
};
/// Packing of the virtual types of any image class.
template <typename I>
struct packed_vtypes<category::image, I>
{
+ // Internally defined virtual types.
typedef oln_type_of(I, grid) grid_type;
// --------------------------------------------------------------------
@@ -122,10 +122,11 @@
// 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;
- //...
+ // Defined externally virtual types.
+ typedef oln_type_of(I, image_dimension) image_dimension_type;
+ /// Pretty-printing.
static void echo(std::ostream& ostr)
{
ostr
Index: oln/core/abstract/image_entry.hh
--- oln/core/abstract/image_entry.hh (revision 470)
+++ oln/core/abstract/image_entry.hh (working copy)
@@ -28,8 +28,9 @@
#ifndef OLENA_CORE_ABSTRACT_IMAGE_ENTRY_HH
# define OLENA_CORE_ABSTRACT_IMAGE_ENTRY_HH
-# include <oln/core/abstract/image.hh>
+# include <mlc/case.hh>
# include <stc/entry.hh>
+# include <oln/core/abstract/image.hh>
namespace oln
{
@@ -75,4 +76,8 @@
} // end of namespace oln
+// Add switch/case equipment in the oln namespace.
+mlc_case_equipment_for_namespace(oln);
+
+
#endif // ! OLENA_CORE_ABSTRACT_IMAGE_ENTRY_HH
Index: oln/core/abstract/image_dimension.hh
--- oln/core/abstract/image_dimension.hh (revision 470)
+++ oln/core/abstract/image_dimension.hh (working copy)
@@ -82,24 +82,88 @@
image3d() {}
};
-
} // end of namespace oln::abstract
+
+ /*-------------------.
+ | Dimension switch. |
+ `-------------------*/
+
+ /// Forward declarations.
+ /// \{
+ class grid1d;
+ class grid2d;
+ class grid3d;
+ /// \}
+
+ /// Case tag for the dimension.
+ struct grid_dim_tag;
+
+ /// Switch on on the grid dimension.
+ /// \{
+ template <typename grid_type>
+ struct case_<grid_dim_tag, grid_type, 1> :
+ // Test.
+ public mlc::where_< mlc_eq(grid_type, oln::grid1d) >
+ {
+ // Super class if test succeeds.
+ typedef stc::is_a<abstract::image1d> ret;
+ };
+
+ template <typename grid_type>
+ struct case_<grid_dim_tag, grid_type, 2> :
+ // Test.
+ public mlc::where_< mlc_eq(grid_type, oln::grid2d) >
+ {
+ // Super class if test succeeds.
+ typedef stc::is_a<abstract::image2d> ret;
+ };
+
+ template <typename grid_type>
+ struct case_<grid_dim_tag, grid_type, 3> :
+ // Test.
+ public mlc::where_< mlc_eq(grid_type, oln::grid3d) >
+ {
+ // Super class if test succeeds.
+ typedef stc::is_a<abstract::image3d> ret;
+ };
+
+ /// Abort when grid_type is not handled by the previous cases.
+ template <typename grid_type>
+ struct default_case_<grid_dim_tag, grid_type>
+ {
+ typedef mlc::abort_<grid_dim_tag> ret;
+ };
+ /// \}
+
} // 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
+ template <typename I>
+ struct set_entry_node<I, oln::abstract::dimension_tag> :
+ public oln::switch_< oln::grid_dim_tag, oln_type_of(I, grid) >::ret
+ ::template instantiated_with<I>::ret
{
};
-}
+} // end of namespace stc
+namespace oln
+{
+ /// An external type associated to my::B.
+ template <typename I>
+ struct ext_vtype< category::image,
+ abstract::image<I>,
+ // FIXME: Get rid of this typedef_:: qualifier.
+ typedef_::image_dimension_type >
+ {
+ // Use the same switch as the one use in the inheritance-plugging
+ // mechanism above.
+ typedef typename oln::switch_< oln::grid_dim_tag,
+ oln_type_of(I, grid) >::ret ret;
+ };
+}
#endif // ! OLENA_CORE_ABSTRACT_IMAGE_DIMENSION_HH