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