https://svn.lrde.epita.fr/svn/oln/trunk/olena
I don't know where to put oln/core/abstract/image_typeness_integre.hh;
it adds cases to the typeness hierarchy in, Olena but it depends on
Integre. Maybe we could have a third-party place for this kind of
``glue'' between two subprojects of Olena.
Another (straightforward) solution is to enclose this file within
#if HAVE_NTG / #endif directives.
Index: ChangeLog
from Roland Levillain <roland(a)lrde.epita.fr>
Add image ``typeness'' abstraction hierarchy.
* tests/image_entry.cc (my): Check image_typeness_type vtype and
inheritance.
* oln/core/typedefs.hh (value_type, image_typeness_type): Enable
typedef.
* oln/core/abstract/image.hh (vtypes::value_type): Enable typedef.
(packed_vtypes::value_type): New typedef.
(packed_vtypes::echo): Print value_type and image_typeness_type.
(packed_vtypes::ensure): Check value_type and image_typeness_type.
(image::value_type): Enable typedef.
* oln/core/abstract/image_entry.hh: Include images abstractions
headers.
Don't include mlc/case.hh nor oln/core/abstract/image.hh.
(mlc_case_equipment_for_namespace(oln))
(abstraction_tags): Move...
* oln/core/abstract/image_abstractions.hh: ...here (new file).
* oln/core/abstract/image_dimension.hh: Include it.
Include stc/entry.hh.
Aesthetic changes.
* oln/core/abstract/image_typeness.hh: New file (imported from
Olena proto-1.0, and modified).
* oln/core/abstract/image_typeness_integre.hh: New file
* oln/Makefile.am (nobase_oln_HEADERS): Add
core/abstract/image_abstractions.hh,
core/abstract/image_typeness.hh and
core/abstract/image_typeness_integre.hh.
oln/Makefile.am | 3
oln/core/abstract/image.hh | 39 ++
oln/core/abstract/image_abstractions.hh | 61 ++++
oln/core/abstract/image_dimension.hh | 50 +--
oln/core/abstract/image_entry.hh | 21 -
oln/core/abstract/image_typeness.hh | 410 ++++++++++++++--------------
oln/core/abstract/image_typeness_integre.hh | 161 ++++++++++
oln/core/typedefs.hh | 8
tests/image_entry.cc | 33 +-
9 files changed, 521 insertions(+), 265 deletions(-)
Index: tests/image_entry.cc
--- tests/image_entry.cc (revision 479)
+++ tests/image_entry.cc (working copy)
@@ -27,9 +27,13 @@
/// Test oln::abstract::image_entry.
+// FIXME: Check also with a (possibly fake) ntg::int_u<1, B> type, to
+// stress image_typeness.hh. This should be done in another test, of
+// course.
+
#include <oln/core/1d/grid1d.hh>
#include <oln/core/abstract/image_entry.hh>
-#include <oln/core/abstract/image_dimension.hh>
+
namespace my
{
@@ -51,6 +55,10 @@
// class using the sole grid information (the grid can be seen
// here as a ``tag'').
typedef oln::grid1d grid_type;
+
+ // Likewise, for the switch of image_typeness using the type of
+ // the value of the image.
+ typedef char value_type;
};
}
@@ -60,24 +68,37 @@
class image : public oln::set_super_type<my::image>::ret
{
typedef image self_type;
- // An internal vtype.
+ // Internal vtypes.
typedef oln_type_of_(self_type, grid) grid_type;
- // An external vtype.
+ typedef oln_type_of_(self_type, value) value_type;
+ // External vtypes.
typedef oln_type_of_(self_type, image_dimension) image_dimension_type;
+ typedef oln_type_of_(self_type, image_typeness) image_typeness_type;
};
}
int
main()
{
- // Check its internally defined vtype.
+ // Check its internally defined vtypes.
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,
+ mlc::assert_< mlc_eq(my::image::value_type, char) >::check();
+ // Check its externally defined vtypes.
+ mlc::assert_<
+ mlc_eq( my::image::image_dimension_type,
stc::abstraction_as_type<oln::abstract::image1d> )
>::check();
+ mlc::assert_<
+ mlc_eq( my::image::image_typeness_type,
+ stc::abstraction_as_type<oln::abstract::grey_level_image> )
+ >::check();
+
// Check its image dimension abstraction.
mlc::assert_< mlc_is_a_(my::image, oln::abstract::image1d) >::check();
+ // Check its image ``typeness'' abstraction.
+ mlc::assert_< mlc_is_a_(my::image,
+ oln::abstract::grey_level_image) >::check();
+
// Ensure we can instantiate it.
my::image i;
Index: oln/core/typedefs.hh
--- oln/core/typedefs.hh (revision 479)
+++ oln/core/typedefs.hh (working copy)
@@ -95,7 +95,11 @@
// FIXME: To be enabled later.
// --------------------------------------------------------------------
// mlc_decl_typedef(data_type);
-// mlc_decl_typedef(value_type);
+// --------------------------------------------------------------------
+ mlc_decl_typedef(value_type);
+// --------------------------------------------------------------------
+// FIXME: To be enabled later.
+// --------------------------------------------------------------------
// mlc_decl_typedef(neighb_type);
// mlc_decl_typedef(value_storage_type);
// mlc_decl_typedef(storage_type);
@@ -120,10 +124,10 @@
// mlc_decl_typedef(image_constness_type);
// --------------------------------------------------------------------
mlc_decl_typedef(image_dimension_type);
+ mlc_decl_typedef(image_typeness_type);
// --------------------------------------------------------------------
// FIXME: To be enabled later.
// --------------------------------------------------------------------
-// mlc_decl_typedef(image_typeness_type);
// mlc_decl_typedef(image_valuedness_type);
// mlc_decl_typedef(image_rawness_type);
// --------------------------------------------------------------------
Index: oln/core/abstract/image.hh
--- oln/core/abstract/image.hh (revision 479)
+++ oln/core/abstract/image.hh (working copy)
@@ -67,7 +67,11 @@
// FIXME: To be enabled later.
// --------------------------------------------------------------------
// typedef mlc::undefined concrete_type;
-// typedef mlc::undefined value_type;
+// --------------------------------------------------------------------
+ typedef mlc::undefined value_type;
+// --------------------------------------------------------------------
+// FIXME: To be enabled later.
+// --------------------------------------------------------------------
// typedef mlc::undefined point_type;
// typedef mlc::undefined size_type;
@@ -103,7 +107,11 @@
// FIXME: To be enabled later.
// --------------------------------------------------------------------
// typedef oln_type_of(I, concrete) concrete_type;
-// typedef oln_type_of(I, value) value_type;
+// --------------------------------------------------------------------
+ typedef oln_type_of(I, value) value_type;
+// --------------------------------------------------------------------
+// FIXME: To be enabled later.
+// --------------------------------------------------------------------
// typedef oln_type_of(I, point) point_type;
// typedef oln_type_of(I, size) size_type;
@@ -128,6 +136,7 @@
// Defined externally virtual types.
typedef oln_type_of(I, image_dimension) image_dimension_type;
+ typedef oln_type_of(I, image_typeness) image_typeness_type;
/// Pretty-printing.
static void echo(std::ostream& ostr)
@@ -144,7 +153,11 @@
// FIXME: To be enabled later.
// --------------------------------------------------------------------
// << " concrete_type = " << mlc_to_string(concrete_type) << std::endl
-// << " value_type = " << mlc_to_string(value_type) << std::endl
+// --------------------------------------------------------------------
+ << " value_type = " << mlc_to_string(value_type) << std::endl
+// --------------------------------------------------------------------
+// FIXME: To be enabled later.
+// --------------------------------------------------------------------
// << " point_type = " << mlc_to_string(point_type) << std::endl
// << " size_type = " << mlc_to_string(size_type) << std::endl
@@ -165,7 +178,10 @@
// << " image_constness_type = " << mlc_to_string(image_constness_type) << std::endl
// << " image_rawness_type = " << mlc_to_string(image_rawness_type) << std::endl
// --------------------------------------------------------------------
- << " image_dimension_type = " << mlc_to_string(image_dimension_type) << std::endl
+ << " image_dimension_type = " << mlc_to_string(image_dimension_type)
+ << std::endl
+ << " image_typeness_type = " << mlc_to_string(image_typeness_type)
+ << std::endl
<< "}" << std::endl;
}
@@ -179,7 +195,11 @@
// FIXME: To be enabled later.
// --------------------------------------------------------------------
// mlc::assert_< mlc_is_ok(concrete_type) >::check();
-// mlc::assert_< mlc_is_ok(value_type) >::check();
+// --------------------------------------------------------------------
+ mlc::assert_< mlc_is_ok(value_type) >::check();
+// --------------------------------------------------------------------
+// FIXME: To be enabled later.
+// --------------------------------------------------------------------
// mlc::assert_< mlc_is_ok(point_type) >::check();
// mlc::assert_< mlc_is_ok(size_type) >::check();
// mlc::assert_< mlc_is_ok(piter_type) >::check();
@@ -200,6 +220,7 @@
// mlc::assert_< mlc_is_ok(image_rawness_type) >::check();
// --------------------------------------------------------------------
mlc::assert_< mlc_is_ok(image_dimension_type) >::check();
+ mlc::assert_< mlc_is_ok(image_typeness_type) >::check();
}
};
@@ -235,12 +256,16 @@
template <typename E>
struct image : public internal::get_image_impl < image<E>, E >
{
+ /// Typedefs.
// --------------------------------------------------------------------
// 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, value) value_type;
+// --------------------------------------------------------------------
+// FIXME: To be enabled later.
+// --------------------------------------------------------------------
// typedef oln_type_of(E, point) point_type;
// --------------------------------------------------------------------
Index: oln/core/abstract/image_entry.hh
--- oln/core/abstract/image_entry.hh (revision 479)
+++ oln/core/abstract/image_entry.hh (working copy)
@@ -28,9 +28,13 @@
#ifndef OLENA_CORE_ABSTRACT_IMAGE_ENTRY_HH
# define OLENA_CORE_ABSTRACT_IMAGE_ENTRY_HH
-# include <mlc/case.hh>
# include <stc/entry.hh>
-# include <oln/core/abstract/image.hh>
+
+# include <oln/core/abstract/image_abstractions.hh>
+// Abstraction hierachies.
+# include <oln/core/abstract/image_dimension.hh>
+# include <oln/core/abstract/image_typeness.hh>
+
namespace oln
{
@@ -62,22 +66,9 @@
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
-// 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 479)
+++ oln/core/abstract/image_dimension.hh (working copy)
@@ -28,7 +28,10 @@
#ifndef OLENA_CORE_ABSTRACT_IMAGE_DIMENSION_HH
# define OLENA_CORE_ABSTRACT_IMAGE_DIMENSION_HH
+# include <stc/entry.hh>
# include <oln/core/abstract/image.hh>
+# include <oln/core/abstract/image_abstractions.hh>
+
/* Image dimension hierarchy (summary).
@@ -62,55 +65,36 @@
*/
-/*! \namespace oln
-** \brief oln namespace.
-*/
-namespace oln {
+namespace oln
+{
- /*! \namespace oln::abstract
- ** \brief oln::abstract namespace.
- */
- namespace abstract {
+ namespace abstract
+ {
- /*! \class abstract::image1d<E>
- **
- ** Class of 1d images.
- */
+ /// Class of 1D images.
template <typename E>
struct image1d : public virtual image<E>
{
protected:
-
- /*! \brief Constructor (protected, empty).
- */
+ /// Constructor (protected, empty).
image1d() {}
};
- /*! \class abstract::image2d<E>
- **
- ** Class of 2d images.
- */
+ /// Class of 2D images.
template <typename E>
struct image2d : public virtual image<E>
{
protected:
-
- /*! \brief Constructor (protected, empty).
- */
+ /// Constructor (protected, empty).
image2d() {}
};
- /*! \class abstract::image3d<E>
- **
- ** Class of 3d images.
- */
+ /// Class of 3d images.
template <typename E>
struct image3d : public virtual image<E>
{
protected:
-
- /*! \brief Constructor (protected, empty).
- */
+ /// Constructor (protected, empty).
image3d() {}
};
@@ -121,12 +105,10 @@
| Dimension switch. |
`-------------------*/
- /// Forward declarations.
- /// \{
+ // Forward declarations.
class grid1d;
class grid2d;
class grid3d;
- /// \}
/// Case tag for the dimension.
struct grid_dim_tag;
@@ -182,9 +164,11 @@
};
} // end of namespace stc
+
+// FIXME: Is this external property really useful?
namespace oln
{
- /// An external type associated to my::B.
+ /// Image dimension type as an external vtype of abstract::image.
template <typename I>
struct ext_vtype< category::image,
abstract::image<I>,
Index: oln/core/abstract/image_typeness_integre.hh
--- oln/core/abstract/image_typeness_integre.hh (revision 0)
+++ oln/core/abstract/image_typeness_integre.hh (revision 0)
@@ -0,0 +1,161 @@
+// 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.
+
+
+// FIXME: Move this file into Integre? Or in a another project,
+// serving as a glue between Integre and Olena?
+
+#ifndef OLENA_CORE_ABSTRACT_IMAGE_TYPENESS_INTEGRE_HH
+# define OLENA_CORE_ABSTRACT_IMAGE_TYPENESS_INTEGRE_HH
+
+# include <oln/core/abstract/image_typeness.hh>
+
+
+// Forward declarations.
+/* FIXME: These are Integre values; should'nt we let Integre add the
+ necessary cases itself? */
+namespace ntg
+{
+ class bin;
+ template <unsigned nbits, typename behavior> class int_u;
+ template <unsigned nbits, typename behavior> class int_s;
+ template <typename E> class color_value;
+ template <typename E> class enum_value;
+ template <typename E> class real_value;
+
+ /** \brief ``eq'' operator dedicated to ntg::int_u<nbits, behavior> and
+ ntg::int_s<nbits, behavior>, with nbits a known unsigned (e.g.,
+ int_u<1, behavior>).
+
+ Checking whether value_type is a ntg::int_u<1, behavior>
+ (behavior being a template parameter) is a bit tricky: we
+ can't use mlc_eq() since ntg::int_u<1, B> is not a (complete)
+ type, nor mlc_is_a(), since it is a partially-valued template.
+ Hence this dedicated approach, used for ntg::int_u and
+ ntg::int_s.
+
+ (Olena proto-1.0 used to mimic mlc_is_a with its own
+ machinery, for all kind of value type, which is redundant with
+ mlc_is_a).
+ \{ */
+ template< template <unsigned, class> class T, unsigned nbits, typename U >
+ struct eq_ : public mlc::bexpr_<false>
+ {
+ };
+
+ template< template <unsigned, class> class T, unsigned nbits,
+ typename behavior >
+ struct eq_< T, nbits, T<nbits, behavior> > : public mlc::bexpr_<true>
+ {
+ };
+ /** \} */
+
+} // end of namespace ntg
+
+
+namespace oln {
+
+ /*--------------------.
+ | Value type switch. |
+ `--------------------*/
+
+ /// Switch on on the value type.
+ /// \{
+
+ // ----------------------------------------------- //
+ // Cases where the value type is an Integre type. //
+ // ----------------------------------------------- //
+
+ // (The first cases are located in oln/core/abstract/image_typeness.hh).
+
+
+ /// Binary case.
+ template <typename value_type>
+ struct case_<value_type_tag, value_type, 3> :
+ public mlc::where_<
+ mlc::or_list_< mlc_eq(value_type, ntg::bin),
+ ntg::eq_<ntg::int_u, 1, value_type>,
+ ntg::eq_<ntg::int_s, 1, value_type> > >
+ {
+ // Definition of the super class corresponding to this case.
+ typedef stc::abstraction_as_type<abstract::binary_image> super_type;
+ // Definition of the external virtual type (same as the super
+ // class in this case).
+ typedef super_type image_typeness_type;
+ };
+
+ /// Grey-level case.
+ template <typename value_type>
+ struct case_<value_type_tag, value_type, 4> :
+ public mlc::where_< mlc_is_a(value_type, ntg::real_value) >
+ {
+ // Definition of the super class corresponding to this case
+ // (abstract::grey_level_image_ is the conjunction of
+ // abstract::grey_level_image and abstract::not_binary_image).
+ typedef
+ stc::abstraction_as_type<abstract::internal::grey_level_image_>
+ super_type;
+ // Definition of the external virtual type.
+ typedef stc::abstraction_as_type<abstract::grey_level_image>
+ image_typeness_type;
+ };
+
+ /// Label case.
+ template <typename value_type>
+ struct case_<value_type_tag, value_type, 5> :
+ public mlc::where_< mlc_is_a(value_type, ntg::enum_value) >
+ {
+ // Definition of the super class corresponding to this case
+ // (abstract::label_image_ is the conjunction of
+ // abstract::label_image and abstract::not_binary_image).
+ typedef stc::abstraction_as_type<abstract::internal::label_image_>
+ super_type;
+ // Definition of the external virtual type.
+ typedef stc::abstraction_as_type<abstract::label_image>
+ image_typeness_type;
+ };
+
+ /// Color case.
+ template <typename value_type>
+ struct case_<value_type_tag, value_type, 6> :
+ public mlc::where_< mlc_is_a(value_type, ntg::color_value) >
+ {
+ // Definition of the super class corresponding to this case
+ // (abstract::color_image_ is the conjunction of
+ // abstract::color_image and abstract::not_binary_image).
+ typedef stc::abstraction_as_type<abstract::internal::color_image_>
+ super_type;
+ // Definition of the external virtual type.
+ typedef stc::abstraction_as_type<abstract::color_image>
+ image_typeness_type;
+ };
+
+ /// \}
+
+} // end of namespace oln
+
+#endif // ! OLENA_CORE_ABSTRACT_IMAGE_TYPENESS_INTEGRE_HH
Index: oln/core/abstract/image_typeness.hh
--- oln/core/abstract/image_typeness.hh (revision 0)
+++ oln/core/abstract/image_typeness.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
@@ -12,8 +12,8 @@
//
// 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.
+// 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
@@ -28,275 +28,281 @@
#ifndef OLENA_CORE_ABSTRACT_IMAGE_TYPENESS_HH
# define OLENA_CORE_ABSTRACT_IMAGE_TYPENESS_HH
-# include <ntg/decls.hh>
+# include <stc/entry.hh>
# include <oln/core/abstract/image.hh>
+# include <oln/core/abstract/image_abstractions.hh>
-// image
-//
-// ^
-// |
-// -------------------------------------------------
-// | | | | |
-//
-// greylevel_image color_image label_image data_image ...
-//
-// ^
-// |
-//
-// binary_image
+/* Image ``typeness'' hierarchy (summary).
+ /image<I>/
+ ^
+ |
+ ,--------------+-------------+-------------+--------+---------.
+ | | | | | |
+ /grey_level_image/ /color_image/ /label_image/ /data_image/ ... /not_binary_
+ ^ ^ ^ ^ ^ ^ image/
+ | | | | | | ^
+ | | | /binary_image/ | | |
+ | | | ^ | | |
+ | | | | | | |
+ ,---------------------------------------------------------------------.
+ | The selection of the super classe(s) is made according to the value |
+ | of type_of(I, value). |
+ `---------------------------------------------------------------------'
+ | | | | | | |
+ o o o o o o o
+
+ o
+ |
+ stc::set_entry_node<I, typeness_tag>
+ (image typeness selector)
+ ^
+ |
+ /image_entry<I>/
+ ^
+ |
+ I
+ (a concrete image)
-// fwd decls
-namespace oln {
- namespace abstract {
- template <typename E> struct greylevel_image;
- template <typename E> struct color_image;
- template <typename E> struct label_image;
- template <typename E> struct binary_image;
- template <typename E> struct not_binary_image;
- template <typename E> struct data_image;
- }
-}
-
-
-/// Macro.
-# define oln_typeness_of(T) typename typeness::tag_< typeness::of<T>::val >::ret
-
-
-
-/*! \namespace oln
-** \brief oln namespace.
*/
-namespace oln {
-
- /*! \namespace oln::typeness
- ** \brief oln::typeness namespace.
- */
- namespace typeness {
-
- enum {
- _greylevel_tag = 1,
- _color_tag = 2,
- _label_tag = 3,
- _binary_tag = 4,
- _data_tag = 5
- };
-
- struct greylevel_tag;
- struct color_tag;
- struct label_tag;
- struct binary_tag;
- struct data_tag;
-
- template <int tag> struct tag_;
- template <> struct tag_ <_greylevel_tag> { typedef greylevel_tag ret; };
- template <> struct tag_ <_color_tag> { typedef color_tag ret; };
- template <> struct tag_ <_label_tag> { typedef label_tag ret; };
- template <> struct tag_ <_binary_tag> { typedef binary_tag ret; };
- template <> struct tag_ <_data_tag> { typedef data_tag ret; };
+namespace oln {
- template <typename T>
- struct of
+ namespace abstract
{
- protected:
-
- static T* makeT();
- template <int tag> struct tag_is { char c[tag]; };
-
- template <typename E>
- static tag_is<_color_tag> selector(ntg::color_value<E>*);
-
- template <typename E>
- static tag_is<_label_tag> selector(ntg::enum_value<E>*);
+ /// \brief Class of grey-level images.
+ ///
+ /// An image that contains values whose type is \c int or
+ /// <tt>unsigned char</tt>, or ntg::int_u<8> (...) is <b>not</b> a
+ /// grey-level image.
+ ///
+ /// FIXME: Say more.
template <typename E>
- static tag_is<_greylevel_tag> selector(ntg::real_value<E>*);
-
- static tag_is<_greylevel_tag> selector(char*);
- static tag_is<_greylevel_tag> selector(unsigned char*);
-
- static tag_is<_binary_tag> selector(bool*);
- static tag_is<_binary_tag> selector(ntg::bin*);
- template <class b>
- static tag_is<_binary_tag> selector(ntg::int_u<1,b>*);
- template <class b>
- static tag_is<_binary_tag> selector(ntg::int_s<1,b>*);
-
- static tag_is<_data_tag> selector(...); // default
-
- public:
-
- enum { val = sizeof(selector(makeT())) };
+ struct grey_level_image : public virtual image<E>
+ {
+ protected:
+ /// Constructor (protected, empty).
+ grey_level_image() {}
};
-
- // specializations:
-
- template <class T, class interval>
- struct of < ntg::cycle<T, interval> >
+ /// Class of color images.
+ template <typename E>
+ struct color_image : public virtual image<E>
{
- enum { val = of<T>::val };
+ protected:
+ /// Constructor (protected, empty).
+ color_image() {}
};
- template <class T, class interval, class behavior>
- struct of < ntg::range<T, interval, behavior> >
+ /// \brief Class of images whose data are NOT Boolean values.
+ ///
+ /// However such images can derive from abstract::label_image (we
+ /// can have labels that are not binary ones).
+ template <typename E>
+ struct not_binary_image : public virtual image<E>
{
- enum { val = of<T>::val };
+ protected:
+ /// Constructor (protected, empty).
+ not_binary_image() {}
};
-
- // inheritance mechanism:
-
- template <typename tag, typename E>
- struct inheritance_case;
-
- // case: greylevel
+ /// \brief Class of images whose data are labels.
+ ///
+ /// Such images do not support arithmetics.
template <typename E>
- struct inheritance_case <greylevel_tag, E> :
- public abstract::greylevel_image<E>,
- public abstract::not_binary_image<E>
- {};
- // case: color
- template <typename E> struct inheritance_case <color_tag, E> :
- public abstract::color_image<E>,
- public abstract::not_binary_image<E>
- {};
- // case: label
- template <typename E> struct inheritance_case <label_tag, E> :
- public abstract::label_image<E>,
- public abstract::not_binary_image<E>
- {};
- // case: binary
- template <typename E> struct inheritance_case <binary_tag, E> :
- public abstract::binary_image<E>
- {};
- // case: data
- template <typename E> struct inheritance_case <data_tag, E> :
- public abstract::data_image<E>,
- public abstract::not_binary_image<E>
- {};
+ struct label_image : public virtual image<E>
+ {
+ protected:
+ /// Constructor (protected, empty).
+ label_image() {}
+ };
- // switch
+ /// \brief Class of images whose data are Boolean values.
+ ///
+ /// Such images are also oln::abstract::label_image.
template <typename E>
- struct inheritance_switch :
- public inheritance_case < typename tag_< of<oln_type_of(E, value)>::val >::ret, E >
+ struct binary_image : public label_image<E>
{
+ protected:
+ /// Constructor (protected, empty).
+ binary_image() {}
};
-
- } // end of namespace oln::typeness
-
-
-
-
- /*! \namespace oln::abstract
- ** \brief oln::abstract namespace.
- */
- namespace abstract {
-
-
- /*! \class abstract::greylevel_image<E>
- **
- ** Class of greylevel images. An image that contains values whose
- ** type is 'int' or 'unsigned char', or 'ntg::int_u<8>' (...) is
- ** NOT a greylevel image. FIXME: say more.
- */
-
+ /// \brief Class of images whose data cannot be qualified of
+ /// grey-levels, colors, or labels.
template <typename E>
- struct greylevel_image : public virtual image<E>
+ struct data_image : public virtual image<E>
{
protected:
/// Constructor (protected, empty).
- greylevel_image() {}
+ data_image() {}
};
+ /*---------------------.
+ | Conjunctions types. |
+ `---------------------*/
- /*! \class abstract::color_image<E>
- **
- ** Class of color images.
- */
+ namespace internal
+ {
+
+ /// \brief Conjunctions types
+ ///
+ /// These types are helpers to express the inheritance relation
+ /// ``is a X and not_binary_image''. These abstractions are not
+ /// to be used by client code (i.e., algorithms), they are only
+ /// part of the inheritance machinery.
+ //
+ /// \{
+ /// <em>Grey-level image</em> and <em>not binary image</em> abstraction.
template <typename E>
- struct color_image : public virtual image<E>
+ struct grey_level_image_ : public grey_level_image<E>,
+ public not_binary_image<E>
{
protected:
/// Constructor (protected, empty).
- color_image() {}
+ grey_level_image_() {}
};
-
-
- /*! \class abstract::label_image<E>
- **
- ** Class of images whose data are labels. Such images do not
- ** support arithmetics.
- */
-
+ /// <em>Label image</em> and <em>not binary image</em> abstraction.
template <typename E>
- struct label_image : public virtual image<E>
+ struct label_image_ : public label_image<E>,
+ public not_binary_image<E>
{
protected:
/// Constructor (protected, empty).
- label_image() {}
+ label_image_() {}
};
-
-
- /*! \class abstract::binary_image<E>
- **
- ** Class of images whose data are Boolean values. Such images are
- ** abstract::label_image.
- */
-
+ /// <em>Color image</em> and <em>not binary image</em> abstraction.
template <typename E>
- struct binary_image : public label_image<E>
+ struct color_image_ : public color_image<E>,
+ public not_binary_image<E>
{
protected:
/// Constructor (protected, empty).
- binary_image() {}
+ color_image_() {}
};
- /*! \class abstract::not_binary_image<E>
- **
- ** Class of images whose data are NOT Boolean values. However
- ** such images can derive from abstract::label_image (we can have
- ** labels that are not binary ones).
- */
-
+ /// <em>Data image</em> and <em>not binary image</em> abstraction.
template <typename E>
- struct not_binary_image : public virtual image<E>
+ struct data_image_ : public data_image<E>,
+ public not_binary_image<E>
{
protected:
/// Constructor (protected, empty).
- not_binary_image() {}
+ data_image_() {}
};
+ /// \}
+ } // end of namespace oln::abstract::internal
- /*! \class abstract::data_image<E>
- **
- ** Class of images whose data cannot be qualified of greylevels,
- ** colors, or labels.
- */
+ } // end of namespace oln::abstract
- template <typename E>
- struct data_image : public virtual image<E>
+
+ /*--------------------.
+ | Value type switch. |
+ `--------------------*/
+
+ /// Case tag for the dimension.
+ struct value_type_tag;
+
+ /// Switch on on the grid dimension.
+ /// \{
+
+ // ----------------------------------------------- //
+ // Cases where the value type is an builtin type. //
+ // ----------------------------------------------- //
+
+ /// Binary case.
+ template <typename value_type>
+ struct case_<value_type_tag, value_type, 1> :
+ public mlc::where_< mlc_eq(value_type, bool) >
{
- protected:
- /// Constructor (protected, empty).
- data_image() {}
+ // Definition of the super class corresponding to this case.
+ typedef stc::abstraction_as_type<abstract::binary_image> super_type;
+ // Definition of the external virtual type (same as the super
+ // class in this case).
+ typedef super_type image_typeness_type;
};
+ /// Grey-level case.
+ template <typename value_type>
+ struct case_<value_type_tag, value_type, 2> :
+ public mlc::where_<
+ mlc::or_list_< mlc_eq(value_type, char),
+ mlc_eq(value_type, unsigned char),
+ mlc_eq(value_type, unsigned char) > >
+ {
+ // Definition of the super class corresponding to this case
+ // (abstract::grey_level_image_ is the conjunction of
+ // abstract::grey_level_image and abstract::not_binary_image).
+ typedef stc::abstraction_as_type<abstract::internal::grey_level_image_>
+ super_type;
+ // Definition of the external virtual type.
+ typedef stc::abstraction_as_type<abstract::grey_level_image>
+ image_typeness_type;
+ };
- } // end of namespace oln::abstract
+ // -------------- //
+ // Default case. //
+ // -------------- //
+
+ /// Default case: image of ``data''.
+ template <typename value_type>
+ struct default_case_<value_type_tag, value_type>
+ {
+ // Definition of the super class corresponding to this case
+ // (abstract::data_image_ is the conjunction of
+ // abstract::data_image and abstract::not_binary_image).
+ typedef stc::abstraction_as_type<abstract::internal::data_image_>
+ super_type;
+ // Definition of the external virtual type.
+ typedef stc::abstraction_as_type<abstract::data_image>
+ image_typeness_type;
+ };
+ /// \}
} // end of namespace oln
+// Register the dimension switch/case for oln::abstract::image_entry.
+namespace stc
+{
+ template <typename I>
+ struct set_entry_node<I, oln::abstract::typeness_tag> :
+ public oln::case_< oln::value_type_tag, oln_type_of(I, value) >::ret
+ ::super_type::template instantiated_with<I>::ret
+ {
+ };
+} // end of namespace stc
+
+
+// FIXME: Is this external property really useful?
+namespace oln
+{
+ /// Image ``typeness'' as an external vtype of abstract::image.
+ template <typename I>
+ struct ext_vtype< category::image,
+ abstract::image<I>,
+ // FIXME: Get rid of this typedef_:: qualifier.
+ typedef_::image_typeness_type >
+ {
+ // Use the same case as the one use in the inheritance-plugging
+ // mechanism above, but retrieve the external vtype
+ // (image_typename_type), not the super type.
+ typedef
+ typename oln::case_< oln::value_type_tag,
+ oln_type_of(I, value) >::ret::image_typeness_type
+ ret;
+ };
+}
+
#endif // ! OLENA_CORE_ABSTRACT_IMAGE_TYPENESS_HH
Index: oln/core/abstract/image_abstractions.hh
--- oln/core/abstract/image_abstractions.hh (revision 0)
+++ oln/core/abstract/image_abstractions.hh (revision 0)
@@ -0,0 +1,61 @@
+// 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.
+
+#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);
+
+
+namespace oln
+{
+ namespace abstract
+ {
+
+ /// \brief Tags for abstractions.
+ ///
+ /// Use them instead of hard-coded numbers.
+ enum abstraction_tags
+ {
+ // constness_tag,
+ dimension_tag = 1,
+ typeness_tag
+ // valuedness_tag,
+ // rawness_tag,
+ // neighbness_tag,
+ // ...
+ };
+
+ } // end of namespace oln::abstract
+
+} // end of namespace oln
+
+
+#endif // ! OLENA_CORE_ABSTRACT_IMAGE_ABSTRACTIONS_HH
Index: oln/Makefile.am
--- oln/Makefile.am (revision 479)
+++ oln/Makefile.am (working copy)
@@ -13,8 +13,11 @@
core/abstract/any.hh \
core/abstract/grid.hh \
core/abstract/image.hh \
+ core/abstract/image_abstractions.hh \
core/abstract/image_entry.hh \
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
https://svn.lrde.epita.fr/svn/oln/trunk/static
Index: ChangeLog
from Roland Levillain <roland(a)lrde.epita.fr>
Rename some Static entities.
* stc/properties.hh (typeof_): Rename class as...
(type_of_): ...this.
(stc::is_a): Rename class as...
(stc::abstraction_as_type): ...this.
(stc_typeof, stc_typeof_, stc_typeof_in_namespace)
(stc_typeof_in_namespace_): Rename macros as...
(stc_local_type_of, stc_local_type_of_, stc_type_of)
(stc_type_of_): ...these.
* tests/properties.cc: Adjust test.
* tests/entry.cc: Typos in comments.
stc/properties.hh | 41 ++++++++++++++++++++++-------------------
tests/entry.cc | 8 ++++----
tests/properties.cc | 2 +-
3 files changed, 27 insertions(+), 24 deletions(-)
Index: tests/properties.cc
--- tests/properties.cc (revision 471)
+++ tests/properties.cc (working copy)
@@ -38,7 +38,7 @@
typename my_type_of_(FromType, Typedef)
#define my_type_of_(FromType, Typedef) \
- stc_typeof_(my::category::my_cat, FromType, Typedef)
+ stc_local_type_of_(my::category::my_cat, FromType, Typedef)
namespace my
{
Index: tests/entry.cc
--- tests/entry.cc (revision 471)
+++ tests/entry.cc (working copy)
@@ -158,7 +158,7 @@
// Test.
public mlc::where_< mlc_is_a(prop1_type, int) >
{
- // Super class if test succeed.
+ // Super class if test succeeds.
typedef property1a ret;
};
@@ -167,7 +167,7 @@
// Test.
public mlc::where_< mlc_is_a(prop1_type, long) >
{
- // Super class if test succeed.
+ // Super class if test succeeds.
typedef property1b ret;
};
@@ -208,7 +208,7 @@
// Test.
public mlc::where_< mlc_is_a(prop2_type, float) >
{
- // Super class if test succeed.
+ // Super class if test succeeds.
typedef property2a ret;
};
@@ -217,7 +217,7 @@
// Test.
public mlc::where_< mlc_is_a(prop2_type, double) >
{
- // Super class if test succeed.
+ // Super class if test succeeds.
typedef property2b ret;
};
Index: stc/properties.hh
--- stc/properties.hh (revision 471)
+++ stc/properties.hh (working copy)
@@ -88,7 +88,7 @@
};
/// \}
-}
+} // end of namespace mlc
/*------------.
@@ -376,7 +376,7 @@
/* FIXME: Don't query from_type directly, but exact_type(from_type) */ \
/* instead. We need mlc::any for this. */ \
template <typename category, typename from_type, typename typedef_type> \
- struct typeof_ \
+ struct type_of_ \
{ \
/* Look for the typedef as an external type. */ \
typedef typename \
@@ -410,7 +410,7 @@
/// Allow the manipulation of an abstraction (i.e., a template type)
/// as a plain type.
template <template <typename> class abstraction>
- struct is_a
+ struct abstraction_as_type
{
template <typename E>
struct instantiated_with
@@ -418,7 +418,7 @@
typedef abstraction<E> ret;
};
};
-}
+} // end of namespace stc
/*---------.
@@ -469,27 +469,30 @@
# define stc_pseudosuper_(T) \
set_pseudosuper_type<T>::ret
-// FIXME: s/stc_typeof/stc_type_of/.
-
-/// Get the property \a Typedef from \a FromType (version to be used
-/// inside a template).
-#define stc_typeof(Category, FromType, Typedef) \
- typename stc_typeof_(Category, FromType, Typedef)
-
-/// Get the property \a Typedef from \a FromType (version to be used
-/// outside a template).
-#define stc_typeof_(Category, FromType, Typedef) \
- typeof_<Category, FromType, typedef_:: Typedef##_type >::ret
+// FIXME: Perhaps only ``external'' (i.e., non local) versions of
+// stc_type_of are really useful (since they are more precise), and we
+// could get rid of local versions (stc_local_type_of and
+// stc_local_type_of_).
+
+/// Get the property \a Typedef, declared in the current namespace,
+/// from \a FromType (version to be used inside a template).
+#define stc_local_type_of(Category, FromType, Typedef) \
+ typename stc_type_of_(Category, FromType, Typedef)
+
+/// Get the property \a Typedef, declared in the current namespace,
+/// from \a FromType (version to be used outside a template).
+#define stc_local_type_of_(Category, FromType, Typedef) \
+ type_of_<Category, FromType, typedef_:: Typedef##_type >::ret
/// Get the property \a Typedef, declared in \a Namespace, from \a
/// FromType (version to be used inside a template).
-#define stc_typeof_in_namespace(Namespace, Category, FromType, Typedef) \
- typename stc_typeof_in_namespace_(Namespace, Category, FromType, Typedef)
+#define stc_type_of(Namespace, Category, FromType, Typedef) \
+ typename stc_type_of_(Namespace, Category, FromType, Typedef)
/// Get the property \a Typedef, declared in \a Namespace, from \a
/// FromType (version to be used outside a template).
-#define stc_typeof_in_namespace_(Namespace, Category, FromType, Typedef) \
- Namespace::typeof_<Category, FromType, \
+#define stc_type_of_(Namespace, Category, FromType, Typedef) \
+ Namespace::type_of_<Category, FromType, \
Namespace::typedef_:: Typedef##_type >::ret
#endif // ! STATIC_PROPERTIES_HH