Olena-patches
Threads by month
- ----- 2025 -----
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2024 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2023 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2022 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2021 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2020 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2019 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2018 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2017 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2016 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2015 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2014 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2013 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2012 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2011 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2010 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2009 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2008 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2007 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2006 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2005 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2004 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
October 2006
- 3 participants
- 108 discussions
17 Oct '06
2006-10-17 Thierry GERAUD <theo(a)tegucigalpa.lrde.epita.fr>
Replace the 'is_mutable' property by checking the 'lvalue' type.
* oln/core/automatic/image/image_being_mutable.hh: Rename as...
* oln/core/automatic/image/mutable_image.hh: ...this.
(image_being_mutable): Rename as...
(mutable_image): ...this.
* oln/level/fill.hh: Update.
* oln/core/typedefs.hh (is_mutable_type): Remove; obsolete.
* oln/core/abstract/image/mutability/hierarchy.hh
(include) : Update.
(image_being_mutable): Rename as...
(mutable_image): ...this.
(case_): Rely now on mlc_is_ok(oln_lvalue(E)).
* oln/core/1d/image1d.hh: Update.
* oln/core/2d/image2d.hh: Update.
* oln/core/3d/image3d.hh: Update.
* oln/core/gen/mapimage.hh: Update.
* oln/morpher/value_cast.hh: Update.
* oln/morpher/thru_fun.hh: Update.
* oln/morpher/internal/image_value_morpher.hh: Update.
Index: oln/level/fill.hh
===================================================================
--- oln/level/fill.hh (revision 651)
+++ oln/level/fill.hh (working copy)
@@ -34,7 +34,7 @@
# include <oln/core/abstract/image.hh>
# include <oln/core/abstract/iterator.hh>
-# include <oln/core/automatic/image/image_being_mutable.hh>
+# include <oln/core/automatic/image/mutable_image.hh>
namespace oln
@@ -50,7 +50,7 @@
/// Fwd decl.
template <typename I>
- void fill(abstract::image<I>& input, const oln_type_of(I, value)& val);
+ void fill(abstract::mutable_image<I>& input, const oln_value(I)& val);
# ifndef OLN_INCLUDE_ONLY
@@ -60,10 +60,9 @@
/// Generic version.
template <typename I>
- void fill(abstract::image_being_mutable<I>& input,
- const oln_type_of(I, value)& val)
+ void fill(abstract::mutable_image<I>& input, const oln_value(I)& val)
{
- oln_type_of(I, piter) p(input.topo());
+ oln_piter(I) p(input.topo());
for_all(p)
input(p) = val;
}
@@ -73,14 +72,8 @@
/// Facade.
template <typename I>
- void fill(abstract::image<I>& input, const oln_value(I)& val)
+ void fill(abstract::mutable_image<I>& input, const oln_value(I)& val)
{
- // Precondition.
- mlc::assert_<
- mlc_is_a(I, abstract::image_being_mutable),
- ERROR::FIRST_ARGUMENT_OF_oln_level_fill_IS_NOT_MUTABLE
- >::check();
-
impl::fill(input.exact(), val);
}
Index: oln/core/typedefs.hh
===================================================================
--- oln/core/typedefs.hh (revision 651)
+++ oln/core/typedefs.hh (working copy)
@@ -127,7 +127,6 @@
mlc_decl_typedef(value_type);
mlc_decl_typedef(rvalue_type);
mlc_decl_typedef(lvalue_type);
- mlc_decl_typedef(is_mutable_type);
// --------------------------------------------------------------------
// FIXME: To be enabled later.
Index: oln/core/automatic/image/mutable_image.hh
===================================================================
--- oln/core/automatic/image/mutable_image.hh (revision 650)
+++ oln/core/automatic/image/mutable_image.hh (working copy)
@@ -25,8 +25,8 @@
// reasons why the executable file might be covered by the GNU General
// Public License.
-#ifndef OLN_CORE_AUTOMATIC_IMAGE_IMAGE_BEING_MUTABLE_HH
-# define OLN_CORE_AUTOMATIC_IMAGE_IMAGE_BEING_MUTABLE_HH
+#ifndef OLN_CORE_AUTOMATIC_IMAGE_MUTABLE_IMAGE_HH
+# define OLN_CORE_AUTOMATIC_IMAGE_MUTABLE_IMAGE_HH
# include <oln/core/automatic/impl.hh>
# include <oln/morpher/tags.hh>
@@ -37,7 +37,7 @@
// Forward declaration.
namespace abstract
{
- template <typename E> class image_being_mutable;
+ template <typename E> class mutable_image;
} // end of namespace oln::abstract
@@ -45,9 +45,9 @@
namespace automatic
{
/// Implementation corresponding to the interface
- /// oln::abstract::image_being_mutable for an identity morpher.
+ /// oln::abstract::mutable_image for an identity morpher.
template <typename E>
- class set_impl<abstract::image_being_mutable, morpher::tag::identity, E> :
+ class set_impl<abstract::mutable_image, morpher::tag::identity, E> :
public virtual stc::any__simple<E>
{
public:
@@ -59,7 +59,7 @@
template <typename E>
oln_lvalue(E)
- set_impl<abstract::image_being_mutable, morpher::tag::identity, E>
+ set_impl<abstract::mutable_image, morpher::tag::identity, E>
::impl_op_readwrite(const oln_psite(E)& p)
{
return this->exact().delegate().operator()(p);
@@ -71,4 +71,4 @@
} // end of namespace oln
-#endif // ! OLN_CORE_AUTOMATIC_IMAGE_IMAGE_BEING_MUTABLE_HH
+#endif // ! OLN_CORE_AUTOMATIC_IMAGE_MUTABLE_IMAGE_HH
Index: oln/core/automatic/image/image_being_mutable.hh
===================================================================
--- oln/core/automatic/image/image_being_mutable.hh (revision 651)
+++ oln/core/automatic/image/image_being_mutable.hh (working copy)
@@ -1,74 +0,0 @@
-// 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 OLN_CORE_AUTOMATIC_IMAGE_IMAGE_BEING_MUTABLE_HH
-# define OLN_CORE_AUTOMATIC_IMAGE_IMAGE_BEING_MUTABLE_HH
-
-# include <oln/core/automatic/impl.hh>
-# include <oln/morpher/tags.hh>
-
-
-namespace oln
-{
- // Forward declaration.
- namespace abstract
- {
- template <typename E> class image_being_mutable;
-
- } // end of namespace oln::abstract
-
-
- namespace automatic
- {
- /// Implementation corresponding to the interface
- /// oln::abstract::image_being_mutable for an identity morpher.
- template <typename E>
- class set_impl<abstract::image_being_mutable, morpher::tag::identity, E> :
- public virtual stc::any__simple<E>
- {
- public:
- /// Accessor delegation.
- oln_lvalue(E) impl_op_readwrite(const oln_psite(E)& p);
- };
-
-# ifndef OLN_INCLUDE_ONLY
-
- template <typename E>
- oln_lvalue(E)
- set_impl<abstract::image_being_mutable, morpher::tag::identity, E>
- ::impl_op_readwrite(const oln_psite(E)& p)
- {
- return this->exact().delegate().operator()(p);
- }
-
-# endif
-
- } // end of namespace oln::automatic
-
-} // end of namespace oln
-
-#endif // ! OLN_CORE_AUTOMATIC_IMAGE_IMAGE_BEING_MUTABLE_HH
Index: oln/core/abstract/image/mutability/hierarchy.hh
===================================================================
--- oln/core/abstract/image/mutability/hierarchy.hh (revision 651)
+++ oln/core/abstract/image/mutability/hierarchy.hh (working copy)
@@ -30,7 +30,7 @@
# include <oln/core/abstract/image.hh>
# include <oln/core/abstract/image/hierarchies.hh>
-# include <oln/core/automatic/image/image_being_mutable.hh>
+# include <oln/core/automatic/image/mutable_image.hh>
@@ -46,15 +46,10 @@
/// Image being mutable.
template <typename E>
- struct image_being_mutable :
+ struct mutable_image :
public virtual image<E>,
- public automatic::get_impl<image_being_mutable, E>
+ public automatic::get_impl<mutable_image, E>
{
- private:
-
- typedef oln_type_of(E, lvalue) lvalue_t;
- typedef oln_type_of(E, psite) psite_t;
-
public:
struct decl
@@ -68,15 +63,15 @@
using image<E>::operator();
- lvalue_t operator()(const psite_t& p);
+ oln_lvalue(E) operator()(const oln_psite(E)& p);
protected:
/// Constructor (protected, empty).
- image_being_mutable();
+ mutable_image();
/// Destructor (protected).
- ~image_being_mutable();
+ ~mutable_image();
};
@@ -84,19 +79,19 @@
# ifndef OLN_INCLUDE_ONLY
template <typename E>
- typename image_being_mutable<E>::lvalue_t
- image_being_mutable<E>::operator()(const typename image_being_mutable<E>::psite_t& p)
+ oln_lvalue(E)
+ mutable_image<E>::operator()(const oln_psite(E)& p)
{
return this->exact().impl_op_readwrite(p);
}
template <typename E>
- image_being_mutable<E>::image_being_mutable()
+ mutable_image<E>::mutable_image()
{
}
template <typename E>
- image_being_mutable<E>::~image_being_mutable()
+ mutable_image<E>::~mutable_image()
{
decl();
}
@@ -113,9 +108,9 @@
/// With mutability.
template <typename E>
struct case_< image_hierarchy_wrt_mutability, E, 1 > :
- where_< mlc::eq_< oln_type_of(E, is_mutable), mlc::true_ > >
+ where_< mlc_is_ok(oln_lvalue(E)) >
{
- typedef abstract::image_being_mutable<E> ret;
+ typedef abstract::mutable_image<E> ret;
};
} // end of namespace oln
Index: oln/core/1d/image1d.hh
===================================================================
--- oln/core/1d/image1d.hh (revision 651)
+++ oln/core/1d/image1d.hh (working copy)
@@ -61,7 +61,6 @@
typedef mlc::false_ is_computed_type;
typedef T value_type;
typedef T& lvalue_type;
- typedef mlc::true_ is_mutable_type;
typedef image1d<T> real_type;
};
Index: oln/core/2d/image2d.hh
===================================================================
--- oln/core/2d/image2d.hh (revision 651)
+++ oln/core/2d/image2d.hh (working copy)
@@ -61,7 +61,6 @@
typedef mlc::false_ is_computed_type;
typedef T value_type;
typedef T& lvalue_type;
- typedef mlc::true_ is_mutable_type;
typedef image2d<T> real_type;
};
Index: oln/core/3d/image3d.hh
===================================================================
--- oln/core/3d/image3d.hh (revision 651)
+++ oln/core/3d/image3d.hh (working copy)
@@ -61,7 +61,6 @@
typedef mlc::false_ is_computed_type;
typedef T value_type;
typedef T& lvalue_type;
- typedef mlc::true_ is_mutable_type;
typedef image3d<T> real_type;
};
Index: oln/core/gen/mapimage.hh
===================================================================
--- oln/core/gen/mapimage.hh (revision 651)
+++ oln/core/gen/mapimage.hh (working copy)
@@ -57,8 +57,6 @@
typedef mlc::false_ is_computed_type;
typedef value_t value_type;
-
- typedef mlc::true_ is_mutable_type;
typedef value_t& lvalue_type;
typedef void real_type; // FIXME
Index: oln/morpher/value_cast.hh
===================================================================
--- oln/morpher/value_cast.hh (revision 651)
+++ oln/morpher/value_cast.hh (working copy)
@@ -59,7 +59,6 @@
{
typedef mlc::true_ is_computed_type;
typedef Value value_type;
- typedef mlc::false_ is_mutable_type;
};
template <typename Image, typename Value>
Index: oln/morpher/thru_fun.hh
===================================================================
--- oln/morpher/thru_fun.hh (revision 651)
+++ oln/morpher/thru_fun.hh (working copy)
@@ -62,7 +62,6 @@
public:
typedef mlc::true_ is_computed_type;
typedef xtd_res_1(Fun, old_value_type) value_type;
- typedef mlc::false_ is_mutable_type;
};
Index: oln/morpher/internal/image_value_morpher.hh
===================================================================
--- oln/morpher/internal/image_value_morpher.hh (revision 651)
+++ oln/morpher/internal/image_value_morpher.hh (working copy)
@@ -68,7 +68,6 @@
typedef mlc::undefined is_computed_type;
typedef mlc::undefined lvalue_type;
typedef mlc::undefined value_type;
- typedef mlc::undefined is_mutable_type;
};
template <typename Image, typename Exact>
1
0
2006-10-17 Thierry GERAUD <theo(a)tegucigalpa.lrde.epita.fr>
Add computability image hierarchy.
* oln/core/abstract/image/computability: New.
* oln/core/abstract/image/computability/hierarchy.hh: New.
* oln/core/typedefs.hh (is_computed_type): New.
* oln/core/image_entry.hh (is_computed_type): New in vtypes.
* oln/core/abstract/image.hh (decl): Update.
* oln/core/abstract/image/hierarchies.hh
(image_hierarchy_wrt_computability): New.
(hierarchy): Update ids.
* oln/core/abstract/image/all.hh
(include): Add computability/hierarchy.hh.
* oln/core/1d/image1d.hh: Update.
* oln/core/2d/image2d.hh: Likewise.
* oln/core/3d/image3d.hh: Likewise.
* oln/core/gen/mapimage.hh: Likewise.
* oln/morpher/value_cast.hh: Likewise.
* oln/morpher/thru_fun.hh: Likewise.
* oln/morpher/internal/image_value_morpher.hh: Likewise.
Index: oln/core/typedefs.hh
===================================================================
--- oln/core/typedefs.hh (revision 649)
+++ oln/core/typedefs.hh (working copy)
@@ -123,6 +123,7 @@
// --------------------------------------------------------------------
// mlc_decl_typedef(data_type);
// --------------------------------------------------------------------
+ mlc_decl_typedef(is_computed_type);
mlc_decl_typedef(value_type);
mlc_decl_typedef(rvalue_type);
mlc_decl_typedef(lvalue_type);
Index: oln/core/image_entry.hh
===================================================================
--- oln/core/image_entry.hh (revision 649)
+++ oln/core/image_entry.hh (working copy)
@@ -71,6 +71,8 @@
// psite_type: see below.
typedef mlc::undefined point_type;
+
+ typedef mlc::undefined is_computed_type;
typedef mlc::undefined value_type;
// rvalue_type: see below.
Index: oln/core/abstract/image.hh
===================================================================
--- oln/core/abstract/image.hh (revision 649)
+++ oln/core/abstract/image.hh (working copy)
@@ -75,6 +75,8 @@
// // oln_virtual_typedef(fwd_piter);
// // oln_virtual_typedef(bkd_piter);
+ oln_virtual_typedef(is_computed);
+
// oln_virtual_typedef(value);
// oln_virtual_typedef(rvalue);
Index: oln/core/abstract/image/hierarchies.hh
===================================================================
--- oln/core/abstract/image/hierarchies.hh (revision 649)
+++ oln/core/abstract/image/hierarchies.hh (working copy)
@@ -40,13 +40,14 @@
typedef hierarchy<abstract::image, 4> image_hierarchy_wrt_bbox;
typedef hierarchy<abstract::image, 5> image_hierarchy_wrt_accessibility;
typedef hierarchy<abstract::image, 6> image_hierarchy_wrt_mutability;
+ typedef hierarchy<abstract::image, 7> image_hierarchy_wrt_computability;
- typedef hierarchy<abstract::image, 7> image_hybrid_hierarchy_wrt_classical;
+ typedef hierarchy<abstract::image, 8> image_hybrid_hierarchy_wrt_classical;
// FIXME: To be continued.
#if 0
- typedef hierarchy<abstract::image, 8> image_hierarchy_wrt_value;
- typedef hierarchy<abstract::image, 9> image_hierarchy_wrt_data_retrieval;
+ typedef hierarchy<abstract::image, 9> image_hierarchy_wrt_value;
+ typedef hierarchy<abstract::image, 10> image_hierarchy_wrt_data_retrieval;
// ...
#endif
Index: oln/core/abstract/image/computability/hierarchy.hh
===================================================================
--- oln/core/abstract/image/computability/hierarchy.hh (revision 0)
+++ oln/core/abstract/image/computability/hierarchy.hh (revision 0)
@@ -0,0 +1,111 @@
+// 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 OLN_CORE_ABSTRACT_IMAGE_COMPUTABILITY_HIERARCHY_HH
+# define OLN_CORE_ABSTRACT_IMAGE_COMPUTABILITY_HIERARCHY_HH
+
+# include <oln/core/abstract/image.hh>
+# include <oln/core/abstract/image/hierarchies.hh>
+// # include <oln/core/automatic/image/computed_image.hh>
+// # include <oln/core/automatic/image/plain_image.hh>
+
+
+
+namespace oln
+{
+
+ /*--------------.
+ | Abstraction. |
+ `---------------*/
+
+ namespace abstract
+ {
+
+ /// Image whose data are computed.
+ template <typename E>
+ struct computed_image :
+ public virtual image<E> //, public automatic::get_impl< computed_image, E>
+ {
+ protected:
+
+ /// Constructor (protected, empty).
+ computed_image();
+ };
+
+
+ /// Image whose data are *not* computed so they are *plain*.
+ template <typename E>
+ struct plain_image :
+ public virtual image<E> //, public automatic::get_impl< plain_image, E>
+ {
+ protected:
+
+ /// Constructor (protected, empty).
+ plain_image();
+ };
+
+
+# ifndef OLN_INCLUDE_ONLY
+
+ template <typename E>
+ computed_image<E>::computed_image()
+ {
+ }
+
+ template <typename E>
+ plain_image<E>::plain_image()
+ {
+ }
+
+# endif
+
+ } // end of namespace oln::abstract
+
+
+ /*--------------------.
+ | Computability switch. |
+ `--------------------*/
+
+ /// With computability.
+ template <typename E>
+ struct case_< image_hierarchy_wrt_computability, E, 1 > :
+ where_< mlc::eq_< oln_type_of(E, is_computed), mlc::true_ > >
+ {
+ typedef abstract::computed_image<E> ret;
+ };
+
+ template <typename E>
+ struct case_< image_hierarchy_wrt_computability, E, 2 > :
+ where_< mlc::eq_< oln_type_of(E, is_computed), mlc::false_ > >
+ {
+ typedef abstract::plain_image<E> ret;
+ };
+
+} // end of namespace oln
+
+
+#endif // ! OLN_CORE_ABSTRACT_IMAGE_COMPUTABILITY_HIERARCHY_HH
Index: oln/core/abstract/image/all.hh
===================================================================
--- oln/core/abstract/image/all.hh (revision 649)
+++ oln/core/abstract/image/all.hh (working copy)
@@ -44,7 +44,10 @@
# include <oln/core/abstract/image/accessibility/hierarchy.hh>
// Hierarchy 6: image w.r.t. data mutability.
# include <oln/core/abstract/image/mutability/hierarchy.hh>
-// Hybrid hierarchy 7: image w.r.t. classical features.
+// Hierarchy 7: image w.r.t. computability.
+# include <oln/core/abstract/image/computability/hierarchy.hh>
+
+// Hybrid hierarchy 8: image w.r.t. classical features.
# include <oln/core/abstract/image/hybrid/classical.hh>
#endif // ! OLN_CORE_ABSTRACT_IMAGE_ALL_HH
Index: oln/core/1d/image1d.hh
===================================================================
--- oln/core/1d/image1d.hh (revision 650)
+++ oln/core/1d/image1d.hh (working copy)
@@ -58,6 +58,7 @@
typedef point1d point_type;
+ typedef mlc::false_ is_computed_type;
typedef T value_type;
typedef T& lvalue_type;
typedef mlc::true_ is_mutable_type;
Index: oln/core/2d/image2d.hh
===================================================================
--- oln/core/2d/image2d.hh (revision 650)
+++ oln/core/2d/image2d.hh (working copy)
@@ -58,6 +58,7 @@
typedef point2d point_type;
+ typedef mlc::false_ is_computed_type;
typedef T value_type;
typedef T& lvalue_type;
typedef mlc::true_ is_mutable_type;
Index: oln/core/3d/image3d.hh
===================================================================
--- oln/core/3d/image3d.hh (revision 650)
+++ oln/core/3d/image3d.hh (working copy)
@@ -58,6 +58,7 @@
typedef point3d point_type;
+ typedef mlc::false_ is_computed_type;
typedef T value_type;
typedef T& lvalue_type;
typedef mlc::true_ is_mutable_type;
Index: oln/core/gen/mapimage.hh
===================================================================
--- oln/core/gen/mapimage.hh (revision 650)
+++ oln/core/gen/mapimage.hh (working copy)
@@ -55,6 +55,7 @@
typedef fwd_piter_bbox_<topo_type> fwd_piter_type;
typedef bkd_piter_bbox_<topo_type> bkd_piter_type;
+ typedef mlc::false_ is_computed_type;
typedef value_t value_type;
typedef mlc::true_ is_mutable_type;
Index: oln/morpher/value_cast.hh
===================================================================
--- oln/morpher/value_cast.hh (revision 649)
+++ oln/morpher/value_cast.hh (working copy)
@@ -57,6 +57,7 @@
template <typename Image, typename Value>
struct vtypes< morpher::value_cast<Image, Value> >
{
+ typedef mlc::true_ is_computed_type;
typedef Value value_type;
typedef mlc::false_ is_mutable_type;
};
Index: oln/morpher/thru_fun.hh
===================================================================
--- oln/morpher/thru_fun.hh (revision 649)
+++ oln/morpher/thru_fun.hh (working copy)
@@ -59,7 +59,8 @@
{
private:
typedef oln_type_of(Image, rvalue) old_value_type;
- public:
+ public:
+ typedef mlc::true_ is_computed_type;
typedef xtd_res_1(Fun, old_value_type) value_type;
typedef mlc::false_ is_mutable_type;
};
Index: oln/morpher/internal/image_value_morpher.hh
===================================================================
--- oln/morpher/internal/image_value_morpher.hh (revision 649)
+++ oln/morpher/internal/image_value_morpher.hh (working copy)
@@ -64,8 +64,11 @@
{
// Morpher type.
typedef oln::morpher::tag::identity morpher_type; // FIXME: Wrong!
+
+ typedef mlc::undefined is_computed_type;
typedef mlc::undefined lvalue_type;
typedef mlc::undefined value_type;
+ typedef mlc::undefined is_mutable_type;
};
template <typename Image, typename Exact>
1
0
2006-10-17 Thierry GERAUD <theo(a)tegucigalpa.lrde.epita.fr>
Adjust lvalue so that it handles a '&' when needed.
* oln/core/automatic/image/image1d.hh (impl_at): Adjust.
* oln/core/automatic/image/image2d.hh: Likewise.
* oln/core/automatic/image/image3d.hh: Likewise.
* oln/core/automatic/image/image_being_mutable.hh: Likewise.
* oln/core/abstract/image/mutability/hierarchy.hh: Likewise.
* oln/core/abstract/image/dimension/1d.hh: Likewise.
* oln/core/abstract/image/dimension/2d.hh: Likewise.
* oln/core/abstract/image/dimension/3d.hh: Likewise.
* oln/core/1d/image1d.hh: Likewise.
* oln/core/2d/image2d.hh: Likewise.
* oln/core/3d/image3d.hh: Likewise.
* oln/core/gen/mapimage.hh: Likewise.
* oln/core/abstract/image/type/integre.hh: Fix case number wrt
those defined in hierarchy.hh.
Index: oln/core/automatic/image/image1d.hh
===================================================================
--- oln/core/automatic/image/image1d.hh (revision 649)
+++ oln/core/automatic/image/image1d.hh (working copy)
@@ -58,7 +58,7 @@
oln_rvalue(E) impl_at(const oln_coord(E)& index) const;
// FIXME: Hack.
- oln_lvalue(E)& impl_at(const oln_coord(E)& index);
+ oln_lvalue(E) impl_at(const oln_coord(E)& index);
bool impl_has_at(const oln_coord(E)& index) const;
};
@@ -76,7 +76,7 @@
oln_rvalue(E) impl_at(const oln_coord(E)& index) const;
// FIXME: Hack.
- oln_lvalue(E)& impl_at(const oln_coord(E)& index);
+ oln_lvalue(E) impl_at(const oln_coord(E)& index);
bool impl_has_at(const oln_coord(E)& index) const;
};
@@ -98,7 +98,7 @@
}
template <typename E, typename tag>
- oln_lvalue(E)&
+ oln_lvalue(E)
set_impl<abstract::image1d, tag, E>
::impl_at(const oln_coord(E)& index)
{
@@ -127,7 +127,7 @@
}
template <typename E>
- oln_lvalue(E)&
+ oln_lvalue(E)
set_impl<abstract::image1d, morpher::tag::identity, E>
::impl_at(const oln_coord(E)& index)
{
Index: oln/core/automatic/image/image2d.hh
===================================================================
--- oln/core/automatic/image/image2d.hh (revision 649)
+++ oln/core/automatic/image/image2d.hh (working copy)
@@ -58,7 +58,7 @@
oln_rvalue(E) impl_at(const oln_coord(E)& row, const oln_coord(E)& col) const;
// FIXME: Hack.
- oln_lvalue(E)& impl_at(const oln_coord(E)& row, const oln_coord(E)& col);
+ oln_lvalue(E) impl_at(const oln_coord(E)& row, const oln_coord(E)& col);
bool impl_has_at(const oln_coord(E)& row, const oln_coord(E)& col) const;
};
@@ -76,7 +76,7 @@
oln_rvalue(E) impl_at(const oln_coord(E)& row, const oln_coord(E)& col) const;
// FIXME: Hack.
- oln_lvalue(E)& impl_at(const oln_coord(E)& row, const oln_coord(E)& col);
+ oln_lvalue(E) impl_at(const oln_coord(E)& row, const oln_coord(E)& col);
bool impl_has_at(const oln_coord(E)& row, const oln_coord(E)& col) const;
};
@@ -98,7 +98,7 @@
}
template <typename E, typename tag>
- oln_lvalue(E)&
+ oln_lvalue(E)
set_impl<abstract::image2d, tag, E>
::impl_at(const oln_coord(E)& row, const oln_coord(E)& col)
{
@@ -127,7 +127,7 @@
}
template <typename E>
- oln_lvalue(E)&
+ oln_lvalue(E)
set_impl<abstract::image2d, morpher::tag::identity, E>
::impl_at(const oln_coord(E)& row, const oln_coord(E)& col)
{
Index: oln/core/automatic/image/image3d.hh
===================================================================
--- oln/core/automatic/image/image3d.hh (revision 649)
+++ oln/core/automatic/image/image3d.hh (working copy)
@@ -60,9 +60,9 @@
const oln_coord(E)& col) const;
// FIXME: Hack.
- oln_lvalue(E)& impl_at(const oln_coord(E)& slice,
- const oln_coord(E)& row,
- const oln_coord(E)& col);
+ oln_lvalue(E) impl_at(const oln_coord(E)& slice,
+ const oln_coord(E)& row,
+ const oln_coord(E)& col);
bool impl_has_at(const oln_coord(E)& slice,
const oln_coord(E)& row,
const oln_coord(E)& col) const;
@@ -84,9 +84,9 @@
const oln_coord(E)& col) const;
// FIXME: Hack.
- oln_lvalue(E)& impl_at(const oln_coord(E)& slice,
- const oln_coord(E)& row,
- const oln_coord(E)& col);
+ oln_lvalue(E) impl_at(const oln_coord(E)& slice,
+ const oln_coord(E)& row,
+ const oln_coord(E)& col);
bool impl_has_at(const oln_coord(E)& slice,
const oln_coord(E)& row,
const oln_coord(E)& col) const;
@@ -112,7 +112,7 @@
}
template <typename E, typename tag>
- oln_lvalue(E)&
+ oln_lvalue(E)
set_impl<abstract::image3d, tag, E>
::impl_at(const oln_coord(E)& slice,
const oln_coord(E)& row,
@@ -147,7 +147,7 @@
}
template <typename E>
- oln_lvalue(E)&
+ oln_lvalue(E)
set_impl<abstract::image3d, morpher::tag::identity, E>
::impl_at(const oln_coord(E)& slice,
const oln_coord(E)& row,
Index: oln/core/automatic/image/image_being_mutable.hh
===================================================================
--- oln/core/automatic/image/image_being_mutable.hh (revision 649)
+++ oln/core/automatic/image/image_being_mutable.hh (working copy)
@@ -52,13 +52,13 @@
{
public:
/// Accessor delegation.
- oln_lvalue(E)& impl_op_readwrite(const oln_psite(E)& p);
+ oln_lvalue(E) impl_op_readwrite(const oln_psite(E)& p);
};
# ifndef OLN_INCLUDE_ONLY
template <typename E>
- oln_lvalue(E)&
+ oln_lvalue(E)
set_impl<abstract::image_being_mutable, morpher::tag::identity, E>
::impl_op_readwrite(const oln_psite(E)& p)
{
Index: oln/core/abstract/image/type/integre.hh
===================================================================
--- oln/core/abstract/image/type/integre.hh (revision 649)
+++ oln/core/abstract/image/type/integre.hh (working copy)
@@ -96,7 +96,7 @@
/// Binary case.
template <typename E>
- struct case_< image_hierarchy_wrt_type, E, 3 > :
+ struct case_< image_hierarchy_wrt_type, E, 5 > :
where_< mlc::or_list_< mlc::eq_<oln_type_of(E, value), ntg::bin>,
ntg::eq_<ntg::int_u, 1, oln_type_of(E, value)>,
ntg::eq_<ntg::int_s, 1, oln_type_of(E, value)> > >
@@ -107,7 +107,7 @@
/// Grey-level case.
template <typename E>
- struct case_< image_hierarchy_wrt_type, E, 4 > :
+ struct case_< image_hierarchy_wrt_type, E, 6 > :
where_< mlc_is_a( oln_type_of(E, value), ntg::real_value ) >
{
// Definition of the super class corresponding to this case
@@ -118,7 +118,7 @@
/// Label case.
template <typename E>
- struct case_< image_hierarchy_wrt_type, E, 5 > :
+ struct case_< image_hierarchy_wrt_type, E, 7 > :
where_< mlc_is_a( oln_type_of(E, value), ntg::enum_value ) >
{
// Definition of the super class corresponding to this case
@@ -129,7 +129,7 @@
/// Color case.
template <typename E>
- struct case_< image_hierarchy_wrt_type, E, 6 > :
+ struct case_< image_hierarchy_wrt_type, E, 8 > :
where_< mlc_is_a( oln_type_of(E, value), ntg::color_value ) >
{
// Definition of the super class corresponding to this case
Index: oln/core/abstract/image/mutability/hierarchy.hh
===================================================================
--- oln/core/abstract/image/mutability/hierarchy.hh (revision 649)
+++ oln/core/abstract/image/mutability/hierarchy.hh (working copy)
@@ -68,7 +68,7 @@
using image<E>::operator();
- lvalue_t& operator()(const psite_t& p);
+ lvalue_t operator()(const psite_t& p);
protected:
@@ -84,7 +84,7 @@
# ifndef OLN_INCLUDE_ONLY
template <typename E>
- typename image_being_mutable<E>::lvalue_t&
+ typename image_being_mutable<E>::lvalue_t
image_being_mutable<E>::operator()(const typename image_being_mutable<E>::psite_t& p)
{
return this->exact().impl_op_readwrite(p);
Index: oln/core/abstract/image/dimension/1d.hh
===================================================================
--- oln/core/abstract/image/dimension/1d.hh (revision 649)
+++ oln/core/abstract/image/dimension/1d.hh (working copy)
@@ -49,7 +49,7 @@
oln_rvalue(E) at(const oln_coord(E)& index) const;
// FIXME: Hack (should be elsewhere)!
- oln_lvalue(E)& at(const oln_coord(E)& index);
+ oln_lvalue(E) at(const oln_coord(E)& index);
bool has_at(const oln_coord(E)& index) const;
protected:
@@ -73,7 +73,7 @@
}
template <typename E>
- oln_lvalue(E)&
+ oln_lvalue(E)
image1d<E>::at(const oln_coord(E)& index)
{
return this->exact().impl_at(index);
Index: oln/core/abstract/image/dimension/2d.hh
===================================================================
--- oln/core/abstract/image/dimension/2d.hh (revision 649)
+++ oln/core/abstract/image/dimension/2d.hh (working copy)
@@ -49,7 +49,7 @@
oln_rvalue(E) at(const oln_coord(E)& row, const oln_coord(E)& col) const;
// FIXME: Hack (should be elsewhere)!
- oln_lvalue(E)& at(const oln_coord(E)& row, const oln_coord(E)& col);
+ oln_lvalue(E) at(const oln_coord(E)& row, const oln_coord(E)& col);
bool has_at(const oln_coord(E)& row, const oln_coord(E)& col) const;
protected:
@@ -73,7 +73,7 @@
}
template <typename E>
- oln_lvalue(E)&
+ oln_lvalue(E)
image2d<E>::at(const oln_coord(E)& row, const oln_coord(E)& col)
{
return this->exact().impl_at(row, col);
Index: oln/core/abstract/image/dimension/3d.hh
===================================================================
--- oln/core/abstract/image/dimension/3d.hh (revision 649)
+++ oln/core/abstract/image/dimension/3d.hh (working copy)
@@ -51,9 +51,9 @@
const oln_coord(E)& col) const;
// FIXME: Hack (should be elsewhere)!
- oln_lvalue(E)& at(const oln_coord(E)& slice,
- const oln_coord(E)& row,
- const oln_coord(E)& col);
+ oln_lvalue(E) at(const oln_coord(E)& slice,
+ const oln_coord(E)& row,
+ const oln_coord(E)& col);
bool has_at(const oln_coord(E)& slice,
const oln_coord(E)& row,
const oln_coord(E)& col) const;
@@ -81,7 +81,7 @@
}
template <typename E>
- oln_lvalue(E)&
+ oln_lvalue(E)
image3d<E>::at(const oln_coord(E)& slice,
const oln_coord(E)& row,
const oln_coord(E)& col)
Index: oln/core/1d/image1d.hh
===================================================================
--- oln/core/1d/image1d.hh (revision 649)
+++ oln/core/1d/image1d.hh (working copy)
@@ -59,7 +59,7 @@
typedef point1d point_type;
typedef T value_type;
- typedef T lvalue_type;
+ typedef T& lvalue_type;
typedef mlc::true_ is_mutable_type;
typedef image1d<T> real_type;
Index: oln/core/2d/image2d.hh
===================================================================
--- oln/core/2d/image2d.hh (revision 649)
+++ oln/core/2d/image2d.hh (working copy)
@@ -59,7 +59,7 @@
typedef point2d point_type;
typedef T value_type;
- typedef T lvalue_type;
+ typedef T& lvalue_type;
typedef mlc::true_ is_mutable_type;
typedef image2d<T> real_type;
Index: oln/core/3d/image3d.hh
===================================================================
--- oln/core/3d/image3d.hh (revision 649)
+++ oln/core/3d/image3d.hh (working copy)
@@ -59,7 +59,7 @@
typedef point3d point_type;
typedef T value_type;
- typedef T lvalue_type;
+ typedef T& lvalue_type;
typedef mlc::true_ is_mutable_type;
typedef image3d<T> real_type;
Index: oln/core/gen/mapimage.hh
===================================================================
--- oln/core/gen/mapimage.hh (revision 649)
+++ oln/core/gen/mapimage.hh (working copy)
@@ -58,7 +58,7 @@
typedef value_t value_type;
typedef mlc::true_ is_mutable_type;
- typedef value_t lvalue_type;
+ typedef value_t& lvalue_type;
typedef void real_type; // FIXME
};
1
0
https://svn.lrde.epita.fr/svn/oln/trunk/olena
Index: ChangeLog
from Roland Levillain <roland(a)lrde.epita.fr>
Adjust tests.
* tests/window2d.cc: Disable display.
* tests/image_entry.cc, tests/identity_morpher.cc,
* tests/add_neighborhood_morpher.cc, tests/morphers.cc:
Remove mlc_is_a tests w.r.t to oln::abstract::grey_level_image,
since its definition has changed.
add_neighborhood_morpher.cc | 4 ----
identity_morpher.cc | 4 ----
image_entry.cc | 3 ---
morphers.cc | 2 --
window2d.cc | 14 ++++++++++++++
5 files changed, 14 insertions(+), 13 deletions(-)
Index: tests/window2d.cc
--- tests/window2d.cc (revision 648)
+++ tests/window2d.cc (working copy)
@@ -45,10 +45,21 @@
oln_qiter(I) q(p, win);
for_all(p)
{
+#if 0
+ // Disable the display to speed up the test.
std::cout << unsigned(ima(p)) << ": ";
+#endif
for_all(q)
+ {
+#if 0
+ // Likewise.
std::cout << unsigned(ima(q)) << " ";
+#endif
+ }
+#if 0
+ // Likewise.
std::cout << std::endl;
+#endif
}
}
@@ -60,7 +71,10 @@
using namespace oln;
image2d<unsigned char> ima = io::load_pgm(rdata("lena32.pgm"));
+#if 0
+ // Disable the display to speed up the test.
debug::println(ima);
+#endif
window2d win;
win
Index: tests/morphers.cc
--- tests/morphers.cc (revision 648)
+++ tests/morphers.cc (working copy)
@@ -48,8 +48,6 @@
// 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();
image_t ima(42, 51);
Index: tests/image_entry.cc
--- tests/image_entry.cc (revision 648)
+++ tests/image_entry.cc (working copy)
@@ -94,9 +94,6 @@
// Check its image dimension abstraction.
mlc::assert_< mlc_is_a_(my::image, oln::abstract::image2d) >::check();
- // Check its image type abstraction.
- mlc::assert_< mlc_is_a_(my::image,
- oln::abstract::grey_level_image) >::check();
// Ensure we can instantiate it.
my::image i;
Index: tests/add_neighborhood_morpher.cc
--- tests/add_neighborhood_morpher.cc (revision 648)
+++ tests/add_neighborhood_morpher.cc (working copy)
@@ -46,8 +46,6 @@
// 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();
image_t ima(42, 51);
@@ -62,8 +60,6 @@
// 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();
// Check the type of neighborhood.
mlc::assert_< mlc_eq(oln_type_of_(image_with_nbh_t, neighborhood),
oln::neighb2d) >::check();
Index: tests/identity_morpher.cc
--- tests/identity_morpher.cc (revision 648)
+++ tests/identity_morpher.cc (working copy)
@@ -46,8 +46,6 @@
// 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();
image_t ima(42, 51);
@@ -61,8 +59,6 @@
// Check that the instantiated identity morpher realizes the same
// 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();
image_id_t ima_id(ima);
}
1
0
16 Oct '06
https://svn.lrde.epita.fr/svn/oln/trunk/olena
Index: ChangeLog
from Roland Levillain <roland(a)lrde.epita.fr>
Polish the accesses to bbox_<point> as a virtual type.
* oln/core/gen/bbox.hh (oln::bbox_::self_t): Rename as...
(oln::bbox_::self_type): ...this.
Make it public.
(oln::bbox_::super_t): Adjust.
* oln/core/gen/topo_lbbox.hh
(vtypes< topo_lbbox_<point> >::bbox_type): Adjust.
* oln/core/gen/topo_bbox.hh (oln::vtypes< topo_lbbox_<point> >):
Define this virtul type using `bbox_<point>::self_t' instead of
just `bbox_<point>' to force the instiantiation of
oln::bbox_<point> at this point.
(oln::topo_bbox_<point>::bbox_t): Use oln_type_of to define it.
bbox.hh | 9 +++++++--
topo_bbox.hh | 56 ++++++++++++++++++++++++++++++++++++++++++++++++++++++--
topo_lbbox.hh | 2 +-
3 files changed, 62 insertions(+), 5 deletions(-)
Index: oln/core/gen/bbox.hh
--- oln/core/gen/bbox.hh (revision 647)
+++ oln/core/gen/bbox.hh (working copy)
@@ -72,8 +72,13 @@
class bbox_ : public point_set_entry< bbox_<point_t> >,
private mlc::assert_< mlc_is_a(point_t, abstract::point) >
{
- typedef bbox_<point_t> self_t;
- typedef point_set_entry<self_t> super_t;
+ // Make self_type public so that is can be used to define a
+ // virtual type of oln::topo_bbox_ and oln::topo_lbbox_.
+ public:
+ typedef bbox_<point_t> self_type;
+
+ private:
+ typedef point_set_entry<self_type> super_t;
typedef oln_type_of(point_t, coord) coord_t;
Index: oln/core/gen/topo_bbox.hh
--- oln/core/gen/topo_bbox.hh (revision 647)
+++ oln/core/gen/topo_bbox.hh (working copy)
@@ -52,7 +52,59 @@
template <typename point>
struct vtypes< topo_bbox_<point> >
{
- typedef bbox_<point> bbox_type;
+ /* Trick to force the instantiation of bbox_<point>.
+
+ As bbox_<point> is a template type used to define the `bbox'
+ virtual type of topo_bbox_<point>, it requires some attention
+ regarding its instantiation.
+
+
+ Metalic's mlc_is_a is used by the static hierarchy mechanism of
+ Static. mlc_is_a performs a static typedef introspection,
+ taking advantage of the SFINAE rule. However, there two
+ phenomena seem to happen here (probably due to the very nature
+ of SFINAE):
+
+ 1. the statement `mlc_is_a(B, A)' requires the knowledge of the
+ entire declaration of the inspected class to answer
+ positively if a `B' actually *is a* `A'. If B is a template
+ class, this implies that B must have been instantiated for
+ mlc_is_a to be able to inspect it;
+
+ 2. mlc_is_a does *not* trigger the instantiation of the
+ inspected type (probably to prevent any error, in accordance
+ to the SFINAE rule).
+
+ When a template type is used to define a virtual type, it
+ *must* have been instantiated, because it might be used during
+ the construction of the base classes of the class it belongs
+ to. That is the case of bbox_<point> here.
+
+ So, how one can trigger such an instantiation? We used to
+ address this problem by using explicit template instantiations
+ placed before the definition of the class holding the template
+ type used a virtual type :
+
+ template class bbox_<point1d>;
+ template class bbox_<point2d>;
+ template class bbox_<point3d>;
+
+ And so on. But this is not good w.r.t. software engineering:
+ one must take care of the correct explicit instantiations at
+ the right place, which is error-prone --and the C++ compiler
+ won't produces easily understandable messages!-- and requires a
+ manual addition for each instantiation of the template type
+ potentially used as a definition of a virtual type.
+
+ A better solution is to force the compiler to instantiate the
+ type at the definition site of the virtual type (here, as for
+ bbox_<point>). Such an instantiation can be triggered by
+ requesting the use of a typedef contained within this type. As
+ many template types define a typedef `self_t' to refer to
+ themselves, we use this typename to both trigger the
+ instantiation of bbox_<point>, and to define
+ `vtypes< topo_bbox_<point> >::bbox_type'. */
+ typedef typename bbox_<point>::self_t bbox_type;
typedef point point_type;
typedef mlc::true_ is_random_accessible_type;
};
@@ -66,7 +118,7 @@
{
typedef topo_bbox_<point> self_t;
typedef topology_entry<self_t> super_t;
- typedef bbox_<point> bbox_t;
+ typedef oln_type_of(self_t, bbox) bbox_t;
public:
Index: oln/core/gen/topo_lbbox.hh
--- oln/core/gen/topo_lbbox.hh (revision 647)
+++ oln/core/gen/topo_lbbox.hh (working copy)
@@ -106,7 +106,7 @@
themselves, we use this typename to both trigger the
instantiation of bbox_<point>, and to define
`vtypes< topo_lbbox_<point> >::bbox_type'. */
- typedef typename bbox_<point>::self_t bbox_type;
+ typedef typename bbox_<point>::self_type bbox_type;
typedef point point_type;
typedef mlc::true_ is_random_accessible_type;
};
1
0
2006-10-16 Thierry GERAUD <theo(a)tegucigalpa.lrde.epita.fr>
Add value cast image morpher.
* tests/value_cast.cc: New.
* tests/Makefile.am: Update.
* oln/morpher/value_cast.hh: New.
* oln/Makefile.am: Update.
* oln/morpher/internal/image_value_morpher.hh (lvalue): Change
definition mode from single_vtype to vtypes.
Index: tests/Makefile.am
===================================================================
--- tests/Makefile.am (revision 646)
+++ tests/Makefile.am (working copy)
@@ -40,6 +40,7 @@
\
identity_morpher \
add_neighborhood_morpher \
+ value_cast \
morphers \
\
fill
@@ -67,6 +68,7 @@
# Morphers.
identity_morpher_SOURCES = identity_morpher.cc
add_neighborhood_morpher_SOURCES = add_neighborhood_morpher.cc
+value_cast_SOURCES = value_cast.cc
morphers_SOURCES = morphers.cc
# Algorithms.
Index: tests/value_cast.cc
===================================================================
--- tests/value_cast.cc (revision 0)
+++ tests/value_cast.cc (revision 0)
@@ -0,0 +1,85 @@
+// 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 oln::value_cast.cc.
+
+#include <iostream>
+
+#include <oln/basics2d.hh>
+#include <oln/value/all.hh>
+#include <oln/morpher/value_cast.hh>
+
+
+template <typename T>
+void print(T)
+{
+ std::cout << "?" << std::endl;
+}
+
+
+void print(int)
+{
+ std::cout << "int" << std::endl;
+}
+
+void print(float)
+{
+ std::cout << "float" << std::endl;
+}
+
+void print(unsigned char)
+{
+ std::cout << "unsigned char" << std::endl;
+}
+
+
+
+
+int main()
+{
+ using namespace oln;
+
+ using oln::value::gl8;
+
+ point2d p(0,0);
+
+ {
+ image2d<int> ima(1,1);
+ print( value_cast<float>(ima)(p) );
+ }
+
+ {
+ image2d<bool> ima(1,1);
+ print( value_cast<int>(ima)(p) );
+ }
+
+ {
+ image2d<gl8> ima(1,1);
+ print( value_cast<unsigned char>(ima)(p) );
+ }
+
+}
Index: oln/Makefile.am
===================================================================
--- oln/Makefile.am (revision 646)
+++ oln/Makefile.am (working copy)
@@ -151,6 +151,7 @@
morpher/identity.hh \
morpher/tags.hh \
morpher/thru_fun.hh \
+ morpher/value_cast.hh \
\
value/all.hh \
value/default.hh \
Index: oln/morpher/value_cast.hh
===================================================================
--- oln/morpher/value_cast.hh (revision 0)
+++ oln/morpher/value_cast.hh (revision 0)
@@ -0,0 +1,129 @@
+// 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 OLN_MORPHER_VALUE_CAST
+# define OLN_MORPHER_VALUE_CAST
+
+# include <xtd/abstract/open_nary_fun.hh>
+# include <xtd/res.hh>
+# include <oln/morpher/internal/image_value_morpher.hh>
+
+
+
+namespace oln
+{
+
+ namespace morpher
+ {
+ // Forward declaration.
+ template <typename Image, typename Value> struct value_cast;
+
+ } // end of namespace oln::morpher
+
+
+ /// Super type.
+ template <typename Image, typename Value>
+ struct set_super_type< morpher::value_cast<Image, Value> >
+ {
+ typedef morpher::value_cast<Image, Value> self_t;
+ typedef morpher::internal::image_value_morpher<Image, self_t> ret;
+ };
+
+
+ template <typename Image, typename Value>
+ struct vtypes< morpher::value_cast<Image, Value> >
+ {
+ typedef Value value_type;
+ typedef mlc::false_ is_mutable_type;
+ };
+
+ template <typename Image, typename Value>
+ struct single_vtype< morpher::value_cast<Image, Value>, typedef_::rvalue_type >
+ {
+ typedef Value ret;
+ };
+
+
+
+ namespace morpher
+ {
+
+ /// 'Image thru Valuection' morpher.
+ template <typename Image, typename Value>
+ class value_cast : public internal::image_value_morpher< Image,
+ value_cast<Image, Value> >
+ {
+ private:
+
+ typedef value_cast<Image, Value> self_t;
+ typedef internal::image_value_morpher<Image, self_t> super_t;
+
+ typedef oln_type_of(self_t, psite) psite_t;
+ typedef oln_type_of(self_t, rvalue) rvalue_t;
+
+ public:
+
+ value_cast(const Image& image);
+ };
+
+
+# ifndef OLN_INCLUDE_ONLY
+
+ template <typename Image, typename Value>
+ value_cast<Image, Value>::value_cast(const Image& image) :
+ super_t(image)
+ {
+ }
+
+# endif
+
+ } // end of namespace oln::morpher
+
+
+ template <typename Value, typename I>
+ morpher::value_cast<I, Value>
+ value_cast(const abstract::image<I>& ima);
+
+
+# ifndef OLN_INCLUDE_ONLY
+
+ template <typename Value, typename I>
+ morpher::value_cast<I, Value>
+ value_cast(const abstract::image<I>& ima)
+ {
+ morpher::value_cast<I, Value> tmp(ima.exact());
+ return tmp;
+ }
+
+# endif
+
+
+} // end of namespace oln
+
+
+
+#endif // ! OLN_MORPHER_VALUE_CAST
Index: oln/morpher/internal/image_value_morpher.hh
===================================================================
--- oln/morpher/internal/image_value_morpher.hh (revision 646)
+++ oln/morpher/internal/image_value_morpher.hh (working copy)
@@ -64,7 +64,7 @@
{
// Morpher type.
typedef oln::morpher::tag::identity morpher_type; // FIXME: Wrong!
-
+ typedef mlc::undefined lvalue_type;
typedef mlc::undefined value_type;
};
@@ -75,14 +75,7 @@
typedef mlc::undefined ret;
};
- template <typename Image, typename Exact>
- struct single_vtype< morpher::internal::image_value_morpher<Image, Exact>,
- typedef_::lvalue_type >
- {
- typedef mlc::undefined ret;
- };
-
namespace morpher
{
namespace internal
1
0
2006-10-16 Thierry GERAUD <theo(a)tegucigalpa.lrde.epita.fr>
* xtd/optraits.hh (get_trait_): Change mlc_is_found into mlc::is_ok_
so that mlc::undefined means 'not user-defined'.
Index: xtd/optraits.hh
===================================================================
--- xtd/optraits.hh (revision 645)
+++ xtd/optraits.hh (working copy)
@@ -187,7 +187,7 @@
typedef typename get_case_< op_<name>, mlc::pair_<L, R> >::ret case_t;
typedef mlc_ret(case_t) case_ret;
- typedef typename mlc::if_< mlc_is_found(user_ret), user_ret, case_ret >::ret ret;
+ typedef typename mlc::if_< mlc::is_ok_<user_ret>, user_ret, case_ret >::ret ret;
};
@@ -205,7 +205,7 @@
typedef typename get_case_< op_<name>, T >::ret case_t;
typedef mlc_ret(case_t) case_ret;
- typedef typename mlc::if_< mlc_is_found(user_ret), user_ret, case_ret >::ret ret;
+ typedef typename mlc::if_< mlc::is_ok_<user_ret>, user_ret, case_ret >::ret ret;
};
} // end of namespace xtd::internal
1
0
16 Oct '06
Index: ChangeLog
===================================================================
--- ChangeLog (revision 644)
+++ ChangeLog (working copy)
@@ -1,5 +1,20 @@
2006-10-16 Thierry GERAUD <theo(a)tegucigalpa.lrde.epita.fr>
+ Add binary value type plus update image hierarchy plugs.
+
+ * oln/value/tags.hh: New.
+ * oln/value/bin.hh: New.
+ * oln/value/all.hh: New.
+ * oln/core/abstract/image/type/hierarchy.hh (case_): Rely on value
+ tags.
+ (case_): Overload to handle other value types.
+ (include): Update.
+ * oln/value/greylevel.hh (greylevel_): New conversion operator.
+ (gl1): Remove; now replaced by value::bin.
+ * oln/Makefile.am: Update.
+
+2006-10-16 Thierry GERAUD <theo(a)tegucigalpa.lrde.epita.fr>
+
Add grey-level types.
* tests/grey.cc: New.
Index: oln/core/abstract/image/type/hierarchy.hh
===================================================================
--- oln/core/abstract/image/type/hierarchy.hh (revision 644)
+++ oln/core/abstract/image/type/hierarchy.hh (working copy)
@@ -30,7 +30,7 @@
# include <oln/core/abstract/image.hh>
# include <oln/core/abstract/image/hierarchies.hh>
-# include <xtd/valtraits.hh>
+# include <oln/value/tags.hh>
/* Image ``type'' hierarchy (summary).
@@ -93,34 +93,50 @@
namespace oln
{
- /// Switch on on the grid dimension.
+ /// Switch on the value type.
/// \{
- // ----------------------------------------------- //
- // Cases where the value type is an builtin type. //
- // ----------------------------------------------- //
+ // ------------------------------------- //
+ // Cases where the value type is known. //
+ // ------------------------------------- //
/// Binary case.
template <typename E>
struct case_< image_hierarchy_wrt_type, E, 1 > :
- where_< xtd_is_binary(oln_type_of(E, value)) >
+ where_< value::is_binary<oln_type_of(E, value)> >
{
// Definition of the super class corresponding to this case.
typedef abstract::binary_image<E> ret;
};
- /// Grey-level case.
+ /// Color case.
template <typename E>
struct case_< image_hierarchy_wrt_type, E, 2 > :
- where_< mlc::or_list_< mlc::eq_<oln_type_of(E, value), char>,
- mlc::eq_<oln_type_of(E, value), signed char>,
- mlc::eq_<oln_type_of(E, value), unsigned char> > >
+ where_< value::is_color<oln_type_of(E, value)> >
{
// Definition of the super class corresponding to this case.
+ typedef abstract::color_image<E> ret;
+ };
+
+ /// Grey-level case.
+ template <typename E>
+ struct case_< image_hierarchy_wrt_type, E, 3 > :
+ where_< value::is_grey_level<oln_type_of(E, value)> >
+ {
+ // Definition of the super class corresponding to this case.
typedef abstract::grey_level_image<E> ret;
};
+ /// Label case.
+ template <typename E>
+ struct case_< image_hierarchy_wrt_type, E, 4 > :
+ where_< value::is_label<oln_type_of(E, value)> >
+ {
+ // Definition of the super class corresponding to this case.
+ typedef abstract::label_image<E> ret;
+ };
+
// -------------- //
// Default case. //
// -------------- //
Index: oln/Makefile.am
===================================================================
--- oln/Makefile.am (revision 644)
+++ oln/Makefile.am (working copy)
@@ -152,8 +152,10 @@
morpher/tags.hh \
morpher/thru_fun.hh \
\
+ value/all.hh \
value/default.hh \
value/greylevel.hh \
+ value/tags.hh \
\
basics1d.hh \
basics2d.hh \
Index: oln/value/bin.hh
===================================================================
--- oln/value/bin.hh (revision 0)
+++ oln/value/bin.hh (revision 0)
@@ -0,0 +1,110 @@
+// 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 OLN_CORE_VALUE_BIN_HH
+# define OLN_CORE_VALUE_BIN_HH
+
+# include <mlc/bexpr.hh>
+# include <xtd/optraits.hh>
+# include <xtd/valtraits.hh>
+# include <oln/value/greylevel.hh>
+
+
+namespace oln
+{
+
+ namespace value
+ {
+
+ typedef greylevel_<1> bin;
+
+
+ // Binary ops.
+ bin operator and(bin lhs, bin rhs);
+ bin operator or(bin lhs, bin rhs);
+ bin operator xor(bin lhs, bin rhs);
+
+ // Unary ops.
+ bin operator not(bin val);
+
+
+# ifndef OLN_INCLUDE_ONLY
+
+ bin operator and(bin lhs, bin rhs)
+ {
+ return bin(bool(lhs) and bool(rhs));
+ }
+
+ bin operator or(bin lhs, bin rhs)
+ {
+ return bin(bool(lhs) or bool(rhs));
+ }
+
+ bin operator xor(bin lhs, bin rhs)
+ {
+ return bin(bool(lhs) xor bool(rhs));
+ }
+
+ bin operator not(bin val)
+ {
+ return bin(not bool(val));
+ }
+
+# endif
+
+ } // end of namespace oln::value
+
+} // end of namespace oln
+
+
+
+namespace xtd
+{
+
+ using oln::value::bin;
+
+
+ // Logical traits.
+
+ template <> struct set_trait_< op_land, bin, bin > { typedef bin ret; };
+ template <> struct set_trait_< op_land, bool, bin > { typedef bin ret; };
+ template <> struct set_trait_< op_land, bin, bool > { typedef bin ret; };
+
+ template <> struct set_trait_< op_lor, bin, bin > { typedef bin ret; };
+ template <> struct set_trait_< op_lor, bool, bin > { typedef bin ret; };
+ template <> struct set_trait_< op_lor, bin, bool > { typedef bin ret; };
+
+ template <> struct set_trait_< op_lxor, bin, bin > { typedef bin ret; };
+ template <> struct set_trait_< op_lxor, bool, bin > { typedef bin ret; };
+ template <> struct set_trait_< op_lxor, bin, bool > { typedef bin ret; };
+
+ template <> struct set_trait_< op_lnot, bin > { typedef bin ret; };
+
+} // end of namespace xtd
+
+
+#endif // ! OLN_CORE_VALUE_BIN_HH
Index: oln/value/all.hh
===================================================================
--- oln/value/all.hh (revision 0)
+++ oln/value/all.hh (revision 0)
@@ -0,0 +1,41 @@
+// 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 OLN_VALUE_ALL_HH
+# define OLN_VALUE_ALL_HH
+
+
+# include <oln/value/tags.hh>
+
+# include <oln/value/greylevel.hh>
+# include <oln/value/bin.hh>
+# include <oln/value/default.hh>
+
+# include <oln/color/rgb.hh>
+
+
+#endif // ! OLN_VALUE_ALL_HH
Index: oln/value/greylevel.hh
===================================================================
--- oln/value/greylevel.hh (revision 644)
+++ oln/value/greylevel.hh (working copy)
@@ -30,10 +30,12 @@
# include <iostream>
# include <mlc/contract.hh>
+# include <mlc/bexpr.hh>
# include <xtd/optraits.hh>
# include <oln/core/abstract/value.hh>
+
namespace oln
{
@@ -71,11 +73,14 @@
greylevel_();
/// Ctor.
- explicit greylevel_(typename internal::encoding<nbits>::ret val);
+ explicit greylevel_(const typename internal::encoding<nbits>::ret& val);
/// Access to std type.
typename internal::encoding<nbits>::ret value() const;
+ /// Op encoding_t.
+ operator typename internal::encoding<nbits>::ret() const;
+
/// Op greylevel.
operator greylevel() const;
@@ -96,7 +101,6 @@
/// Aliases.
- typedef greylevel_<1> gl1;
typedef greylevel_<8> gl8;
typedef greylevel_<16> gl16;
typedef greylevel_<32> gl32;
@@ -183,7 +187,7 @@
}
template <unsigned nbits>
- greylevel_<nbits>::greylevel_(typename internal::encoding<nbits>::ret val)
+ greylevel_<nbits>::greylevel_(const typename internal::encoding<nbits>::ret& val)
: val_(val)
{
}
@@ -203,6 +207,12 @@
}
template <unsigned nbits>
+ greylevel_<nbits>::operator typename internal::encoding<nbits>::ret() const
+ {
+ return val_;
+ }
+
+ template <unsigned nbits>
bool greylevel_<nbits>::operator<(const greylevel_<nbits>& rhs) const
{
return val_ < rhs.val_;
Index: oln/value/tags.hh
===================================================================
--- oln/value/tags.hh (revision 0)
+++ oln/value/tags.hh (revision 0)
@@ -0,0 +1,105 @@
+// 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 OLN_VALUE_TAGS_HH
+# define OLN_VALUE_TAGS_HH
+
+# include <mlc/bexpr.hh>
+
+
+namespace oln
+{
+
+
+ namespace color
+ {
+ template <typename T> class rgb_;
+ } // end of namespace oln::color
+
+
+ namespace value
+ {
+
+ // Color trait.
+
+ template <typename T>
+ struct is_color : public mlc::bexpr_<false>
+ {
+ };
+
+ template <typename T>
+ struct is_color < color::rgb_<T> > : public mlc::bexpr_<true> {};
+
+
+ // Grey-level trait.
+
+ template <typename T>
+ struct is_grey_level : public mlc::bexpr_<false>
+ {};
+
+ template <unsigned nbits>
+ class greylevel_;
+
+ template <unsigned nbits>
+ struct is_grey_level < greylevel_<nbits> > : public mlc::bexpr_<true> {};
+
+ class greylevel;
+
+ template <>
+ struct is_grey_level < greylevel > : public mlc::bexpr_<true> {};
+
+
+ // Binary trait.
+
+ template <typename T>
+ struct is_binary : public mlc::bexpr_<false>
+ {
+ };
+
+ template <>
+ struct is_binary < bool > : public mlc::bexpr_<true> {};
+
+ typedef greylevel_<1> bin;
+
+ template <>
+ struct is_binary < bin > : public mlc::bexpr_<true> {};
+
+
+ // Label trait.
+
+ template <typename T>
+ struct is_label : public mlc::bexpr_<false>
+ {
+ };
+
+
+ } // end of namespace oln::value
+
+} // end of namespace oln
+
+
+#endif // ! OLN_VALUE_TAGS_HH
1
0
2006-10-16 Thierry GERAUD <theo(a)tegucigalpa.lrde.epita.fr>
Add grey-level types.
* tests/grey.cc: New.
* tests/Makefile.am: Update.
* oln/value/default.hh: New.
* oln/value/greylevel.hh: New.
* oln/Makefile.am: Update.
* oln/core/abstract/value.hh (value): Remove inheritance
so that a value type is not a regular oln type.
Index: tests/grey.cc
===================================================================
--- tests/grey.cc (revision 0)
+++ tests/grey.cc (revision 0)
@@ -0,0 +1,42 @@
+// 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 oln::grey.
+#include <oln/value/greylevel.hh>
+#include <oln/value/default.hh>
+
+
+int main()
+{
+ using namespace oln::value;
+
+ gl8 a = white;
+ gl16 b = white;
+ assert((a == b) == true);
+ gl8 c = (a + b) / 2;
+ assert(c == white);
+}
Index: tests/Makefile.am
===================================================================
--- tests/Makefile.am (revision 643)
+++ tests/Makefile.am (working copy)
@@ -35,6 +35,7 @@
\
at \
\
+ grey \
io_pnm \
\
identity_morpher \
@@ -60,6 +61,9 @@
# I/O.
io_pnm_SOURCES = io_pnm.cc
+# Value.
+grey_SOURCES = grey.cc
+
# Morphers.
identity_morpher_SOURCES = identity_morpher.cc
add_neighborhood_morpher_SOURCES = add_neighborhood_morpher.cc
Index: oln/core/abstract/value.hh
===================================================================
--- oln/core/abstract/value.hh (revision 643)
+++ oln/core/abstract/value.hh (working copy)
@@ -35,7 +35,9 @@
namespace abstract {
- struct value : public oln::type
+ // A value is not an oln::type. As a consequence,
+ // traits are basically defined.
+ struct value
{
protected:
value();
Index: oln/Makefile.am
===================================================================
--- oln/Makefile.am (revision 643)
+++ oln/Makefile.am (working copy)
@@ -152,6 +152,9 @@
morpher/tags.hh \
morpher/thru_fun.hh \
\
+ value/default.hh \
+ value/greylevel.hh \
+ \
basics1d.hh \
basics2d.hh \
basics3d.hh
Index: oln/value/default.hh
===================================================================
--- oln/value/default.hh (revision 0)
+++ oln/value/default.hh (revision 0)
@@ -0,0 +1,59 @@
+// 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 OLN_VALUE_DEFAULT_HH
+# define OLN_VALUE_DEFAULT_HH
+
+# include <oln/value/greylevel.hh>
+
+
+namespace oln
+{
+
+ namespace value
+ {
+
+ /// White.
+ extern const greylevel white;
+
+ /// Black.
+ extern const greylevel black;
+
+
+# ifndef OLN_INCLUDE_ONLY
+
+ const greylevel white = greylevel(1, 1);
+ const greylevel black = greylevel(1, 0);
+
+# endif
+
+ } // end of namespace oln::value
+
+} // end of namespace oln
+
+
+#endif // ! OLN_VALUE_DEFAULT_HH
Index: oln/value/greylevel.hh
===================================================================
--- oln/value/greylevel.hh (revision 0)
+++ oln/value/greylevel.hh (revision 0)
@@ -0,0 +1,494 @@
+// 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 OLN_CORE_VALUE_GREYLEVEL_HH
+# define OLN_CORE_VALUE_GREYLEVEL_HH
+
+# include <iostream>
+# include <mlc/contract.hh>
+# include <xtd/optraits.hh>
+# include <oln/core/abstract/value.hh>
+
+
+namespace oln
+{
+
+ namespace value
+ {
+
+
+ namespace internal
+ {
+
+ template <unsigned nbits>
+ struct encoding;
+
+ template <> struct encoding <1> { typedef bool ret; };
+ template <> struct encoding <8> { typedef unsigned char ret; };
+ template <> struct encoding <16> { typedef unsigned short ret; };
+ template <> struct encoding <32> { typedef unsigned long ret; };
+
+ } // end of oln::value::internal
+
+
+ /// Fwd decl.
+ class greylevel;
+
+
+ /// General grey-level class on n bits.
+ template <unsigned nbits>
+ class greylevel_ : public oln::abstract::value
+ {
+ typedef typename internal::encoding<nbits>::ret encoding_t;
+
+ public:
+
+ /// Ctor.
+ greylevel_();
+
+ /// Ctor.
+ explicit greylevel_(typename internal::encoding<nbits>::ret val);
+
+ /// Access to std type.
+ typename internal::encoding<nbits>::ret value() const;
+
+ /// Op greylevel.
+ operator greylevel() const;
+
+ /// Op<.
+ bool operator<(const greylevel_<nbits>& rhs) const;
+
+ /// Op==.
+ bool operator==(const greylevel_<nbits>& rhs) const;
+
+ protected:
+ encoding_t val_;
+ };
+
+
+ /// Op<<.
+ template <unsigned nbits>
+ std::ostream& operator<<(std::ostream& ostr, const greylevel_<nbits>& g);
+
+
+ /// Aliases.
+ typedef greylevel_<1> gl1;
+ typedef greylevel_<8> gl8;
+ typedef greylevel_<16> gl16;
+ typedef greylevel_<32> gl32;
+
+
+ template <unsigned nbits, unsigned mbits>
+ bool operator==(const greylevel_<nbits>& lhs, const greylevel_<mbits>& rhs);
+
+ template <unsigned nbits, unsigned mbits>
+ greylevel operator+(const greylevel_<nbits>& lhs, const greylevel_<mbits>& rhs);
+
+ template <unsigned nbits, unsigned mbits>
+ greylevel operator-(const greylevel_<nbits>& lhs, const greylevel_<mbits>& rhs);
+
+ template <unsigned nbits>
+ greylevel operator*(int s, const greylevel_<nbits>& rhs);
+
+ template <unsigned nbits>
+ greylevel operator*(const greylevel_<nbits>& lhs, int s);
+
+ template <unsigned nbits>
+ greylevel operator/(const greylevel_<nbits>& lhs, int s);
+
+
+
+ /// General grey-level class where n bits is not know at compile-time.
+ /// This class is used for exchange between grey-level types purpose.
+ class greylevel : public oln::abstract::value
+ {
+ public:
+
+ /// Ctor.
+ greylevel();
+
+ /// Ctor.
+ template <unsigned n>
+ greylevel(const greylevel_<n>& val);
+
+ /// Ctor.
+ greylevel(unsigned nbits, unsigned long val);
+
+ /// Access to std type.
+ unsigned long value() const;
+
+ unsigned nbits() const;
+
+ void set_nbits(unsigned nbits);
+
+ greylevel to_nbits(unsigned nbits) const;
+
+ template <unsigned n>
+ operator greylevel_<n>() const;
+
+ bool operator<(const greylevel& rhs) const;
+
+ bool operator==(const greylevel& rhs) const;
+
+ protected:
+ unsigned nbits_;
+ unsigned long val_;
+ };
+
+
+ std::ostream& operator<<(std::ostream& ostr, const greylevel& g);
+
+
+ greylevel operator+(const greylevel& lhs, const greylevel& rhs);
+ greylevel operator-(const greylevel& lhs, const greylevel& rhs);
+
+ greylevel operator*(int s, const greylevel& rhs);
+ greylevel operator*(const greylevel& lhs, int s);
+
+ greylevel operator/(const greylevel& lhs, int s);
+
+
+
+# ifndef OLN_INCLUDE_ONLY
+
+ // Greylevel_<nbits>.
+
+ template <unsigned nbits>
+ greylevel_<nbits>::greylevel_()
+ {
+ }
+
+ template <unsigned nbits>
+ greylevel_<nbits>::greylevel_(typename internal::encoding<nbits>::ret val)
+ : val_(val)
+ {
+ }
+
+ template <unsigned nbits>
+ typename internal::encoding<nbits>::ret
+ greylevel_<nbits>::value() const
+ {
+ return val_;
+ }
+
+ template <unsigned nbits>
+ greylevel_<nbits>::operator greylevel() const
+ {
+ greylevel tmp(nbits, val_);
+ return tmp;
+ }
+
+ template <unsigned nbits>
+ bool greylevel_<nbits>::operator<(const greylevel_<nbits>& rhs) const
+ {
+ return val_ < rhs.val_;
+ }
+
+ template <unsigned nbits>
+ bool greylevel_<nbits>::operator==(const greylevel_<nbits>& rhs) const
+ {
+ return val_ == rhs.val_;
+ }
+
+ template <unsigned nbits>
+ std::ostream& operator<<(std::ostream& ostr, const greylevel_<nbits>& g)
+ {
+ return ostr << g.value();
+ }
+
+
+ template <unsigned nbits, unsigned mbits>
+ bool operator==(const greylevel_<nbits>& lhs, const greylevel_<mbits>& rhs)
+ {
+ return greylevel(lhs) == greylevel(rhs);
+ }
+
+ template <unsigned nbits, unsigned mbits>
+ greylevel operator+(const greylevel_<nbits>& lhs, const greylevel_<mbits>& rhs)
+ {
+ return greylevel(lhs) + greylevel(rhs);
+ }
+
+ template <unsigned nbits, unsigned mbits>
+ greylevel operator-(const greylevel_<nbits>& lhs, const greylevel_<mbits>& rhs)
+ {
+ return greylevel(lhs) - greylevel(rhs);
+ }
+
+ template <unsigned nbits>
+ greylevel operator*(int s, const greylevel_<nbits>& rhs)
+ {
+ precondition(s >= 0);
+ greylevel tmp(nbits, s * rhs.value());
+ return tmp;
+ }
+
+ template <unsigned nbits>
+ greylevel operator*(const greylevel_<nbits>& lhs, int s)
+ {
+ precondition(s >= 0);
+ greylevel tmp(nbits, lhs.value() * s);
+ return tmp;
+ }
+
+ template <unsigned nbits>
+ greylevel operator/(const greylevel_<nbits>& lhs, int s)
+ {
+ precondition(s > 0);
+ greylevel tmp(nbits, lhs.value() / s);
+ return tmp;
+ }
+
+
+
+ // Greylevel.
+
+ greylevel::greylevel()
+ : nbits_(0)
+ {
+ }
+
+ template <unsigned n>
+ greylevel::greylevel(const greylevel_<n>& g)
+ : nbits_(n),
+ val_(g.value())
+ {
+ }
+
+ greylevel::greylevel(unsigned nbits, unsigned long val)
+ : nbits_(nbits),
+ val_(val)
+ {
+ }
+
+ unsigned long greylevel::value() const
+ {
+ invariant(nbits_ != 0);
+ return val_;
+ }
+
+ unsigned greylevel::nbits() const
+ {
+ return nbits_;
+ }
+
+ namespace internal
+ {
+
+ unsigned long two_pow_(unsigned n)
+ {
+ if (n == 0)
+ return 1;
+ else
+ return 2 * two_pow_(n - 1);
+ }
+
+ unsigned long two_pow_n_minus_1(unsigned n)
+ {
+ return two_pow_(n) - 1;
+ }
+
+ template <unsigned n_dest>
+ unsigned long convert(unsigned n_src, unsigned long val)
+ {
+ if (n_dest == n_src)
+ return val;
+ else
+ if (n_dest > n_src)
+ return val * two_pow_n_minus_1(n_dest) / two_pow_n_minus_1(n_src);
+ else
+ return val / two_pow_(n_src - n_dest);
+ }
+
+ } // end of oln::value::internal
+
+
+ void greylevel::set_nbits(unsigned nbits)
+ {
+ precondition(nbits != 0);
+ invariant(nbits_ != 0);
+ if (nbits == nbits_)
+ return;
+ if (nbits > nbits_)
+ {
+ val_ *= internal::two_pow_n_minus_1(nbits);
+ val_ /= internal::two_pow_n_minus_1(nbits_);
+ }
+ else // nbits < nbits_
+ {
+ val_ /= internal::two_pow_(nbits_ - nbits);
+ }
+ nbits_ = nbits;
+ }
+
+
+ greylevel greylevel::to_nbits(unsigned nbits) const
+ {
+ precondition(nbits != 0);
+ invariant(nbits_ != 0);
+ greylevel tmp(*this);
+ tmp.set_nbits(nbits);
+ return tmp;
+ }
+
+
+ template <unsigned n>
+ greylevel::operator greylevel_<n>() const
+ {
+ precondition(nbits_ != 0);
+ greylevel_<n> tmp(internal::convert<n>(nbits_, val_));
+ assert(tmp.value() < internal::two_pow_(n));
+ return tmp;
+ }
+
+ bool greylevel::operator<(const greylevel& rhs) const
+ {
+ precondition(nbits_ != 0 and rhs.nbits() != 0);
+ if (rhs.nbits() == nbits_)
+ return rhs.value() < val_;
+ if (nbits_ > rhs.nbits())
+ return val_ < rhs.to_nbits(nbits_).value();
+ else
+ return this->to_nbits(rhs.nbits()).value() < rhs.value();
+ }
+
+ bool greylevel::operator==(const greylevel& rhs) const
+ {
+ precondition(nbits_ != 0 and rhs.nbits() != 0);
+ if (rhs.nbits() == nbits_)
+ return rhs.value() == val_;
+ if (nbits_ > rhs.nbits())
+ return val_ == rhs.to_nbits(nbits_).value();
+ else
+ return this->to_nbits(rhs.nbits()).value() == rhs.value();
+ }
+
+ std::ostream& operator<<(std::ostream& ostr, const greylevel& g)
+ {
+ return ostr << g.value() << '/' << g.nbits() << "nbits";
+ }
+
+ greylevel operator+(const greylevel& lhs, const greylevel& rhs)
+ {
+ precondition(lhs.nbits() != 0 and rhs.nbits() != 0);
+ if (lhs.nbits() > rhs.nbits())
+ {
+ greylevel tmp(lhs.nbits(),
+ lhs.value() + rhs.to_nbits(lhs.nbits()).value());
+ return tmp;
+ }
+ else
+ {
+ greylevel tmp(rhs.nbits(),
+ lhs.to_nbits(rhs.nbits()).value() + rhs.value());
+ return tmp;
+ }
+ }
+
+ greylevel operator-(const greylevel& lhs, const greylevel& rhs)
+ {
+ precondition(lhs.nbits() != 0 and rhs.nbits() != 0);
+ if (lhs.nbits() > rhs.nbits())
+ {
+ unsigned long l = rhs.to_nbits(lhs.nbits()).value();
+ assert(lhs.value() >= l);
+ greylevel tmp(lhs.nbits(),
+ lhs.value() - l);
+ return tmp;
+ }
+ else
+ {
+ unsigned long l = lhs.to_nbits(rhs.nbits()).value();
+ assert(l >= rhs.value());
+ greylevel tmp(rhs.nbits(),
+ l - rhs.value());
+ return tmp;
+ }
+ }
+
+ greylevel operator*(int s, const greylevel& rhs)
+ {
+ precondition(s >= 0);
+ greylevel tmp(rhs.nbits(), rhs.value() * s);
+ return tmp;
+ }
+
+ greylevel operator*(const greylevel& lhs, int s)
+ {
+ precondition(s >= 0);
+ greylevel tmp(lhs.nbits(), lhs.value() * s);
+ return tmp;
+ }
+
+ greylevel operator/(const greylevel& lhs, int s)
+ {
+ precondition(s > 0);
+ greylevel tmp(lhs.nbits(), lhs.value() / s);
+ return tmp;
+ }
+
+# endif
+
+
+ } // end of namespace oln::value
+
+} // end of namespace oln
+
+
+
+namespace xtd
+{
+
+ using oln::value::greylevel;
+
+ template <> struct set_trait_<op_plus, greylevel, greylevel> { typedef greylevel ret; };
+ template <> struct set_trait_<op_minus, greylevel, greylevel> { typedef greylevel ret; };
+ template <> struct set_trait_<op_mult, int, greylevel> { typedef greylevel ret; };
+ template <> struct set_trait_<op_mult, greylevel, int > { typedef greylevel ret; };
+ template <> struct set_trait_<op_div, greylevel, int > { typedef greylevel ret; };
+
+ using oln::value::greylevel_;
+
+ template <unsigned nbits, unsigned mbits>
+ struct set_trait_< op_plus, greylevel_<nbits>, greylevel_<mbits> > { typedef greylevel ret; };
+
+ template <unsigned nbits, unsigned mbits>
+ struct set_trait_< op_minus, greylevel_<nbits>, greylevel_<mbits> > { typedef greylevel ret; };
+
+ template <unsigned nbits>
+ struct set_trait_< op_mult, int, greylevel_<nbits> > { typedef greylevel ret; };
+
+ template <unsigned nbits>
+ struct set_trait_< op_mult, greylevel_<nbits>, int > { typedef greylevel ret; };
+
+ template <unsigned nbits>
+ struct set_trait_< op_div, greylevel_<nbits>, int > { typedef greylevel ret; };
+
+} // end of namespace xtd
+
+
+#endif // ! OLN_CORE_VALUE_GREYLEVEL_HH
1
0
643: Enhance xtd traits mechanism so that set of traits can be defined.
by Thierry GERAUD 16 Oct '06
by Thierry GERAUD 16 Oct '06
16 Oct '06
2006-10-16 Thierry GERAUD <theo(a)tegucigalpa.lrde.epita.fr>
Enhance xtd traits mechanism so that set of traits can be defined.
* xtd/optraits.hh (from_set_traits_): New.
* xtd/traits.hh (set_traits_): New.
(from_set_traits_): New.
(set_trait_): New specialization.
Index: xtd/optraits.hh
===================================================================
--- xtd/optraits.hh (revision 642)
+++ xtd/optraits.hh (working copy)
@@ -63,7 +63,6 @@
};
-
// logic
struct land : public abstract::op_tag {};
@@ -112,8 +111,27 @@
+ namespace internal
+ {
+ // Unary operators (op_lnot and op_uminus) can be fetched from type traits.
+ template < typename T >
+ struct from_set_traits_< op_lnot, T >
+ {
+ typedef typename xtd::set_traits_<T>::op_lnot_ret ret;
+ };
+
+ template < typename T >
+ struct from_set_traits_< op_uminus, T >
+ {
+ typedef typename xtd::set_traits_<T>::op_uminus_ret ret;
+ };
+
+ } // end of namespace xtd::internal
+
+
+
template < typename name,
typename data >
struct default_case_ < op_<name>, data >
Index: xtd/traits.hh
===================================================================
--- xtd/traits.hh (revision 642)
+++ xtd/traits.hh (working copy)
@@ -42,15 +42,69 @@
+ // This class aims at being specialized by the client.
+ template < typename T >
+ struct set_traits_ : public mlc::undefined
+ {
+ // Unary operators.
+ typedef mlc::undefined op_lnot_ret;
+ typedef mlc::undefined op_uminus_ret;
+
+ // Values.
+ typedef mlc::undefined min_ret;
+ typedef mlc::undefined max_ret;
+ typedef mlc::undefined zero_ret;
+ typedef mlc::undefined one_ret;
+
+ // Quantization.
+ typedef mlc::undefined nbits;
+
+ // Features.
+ typedef mlc::undefined is_scalar;
+ typedef mlc::undefined is_signed;
+
+ // FIXME: ...
+ };
+
+
+
+ namespace internal
+ {
+
+ // This class should be specialized for each 'subject' so
+ // that set_trait_ gets related to set_traits_.
+ template < typename subject,
+ typename T >
+ struct from_set_traits_ : public mlc::undefined
+ {
+ // FIXME: Add a static check to make sure that this class has
+ // been specialized.
+ };
+
+ } // end of namespace xtd::internal
+
+
+
+ // This class aims at being specialized by the client.
template < typename subject,
typename T1,
typename T2 = mlc::none >
struct set_trait_ : public mlc::undefined
{
+ // A definition, e.g.,
+ // typedef int ret;
};
+ template < typename subject,
+ typename T >
+ struct set_trait_< subject, T, mlc::none > : public internal::from_set_traits_<subject, T>
+ {
+ // A definition, e.g.,
+ // typedef int ret;
+ };
+
namespace internal
{
1
0