https://svn.lrde.epita.fr/svn/oln/trunk/swilena
Index: ChangeLog
from Roland Levillain <roland(a)lrde.epita.fr>
Add support for mln_concrete in Swilena.
* concrete.ixx: New.
Use it...
* morpho.ixx: ...here.
Wrap mln::morpho::dilation.hh and mln::morpho::erosion directly,
instead of using a simplified declaration (previously used to
circumvent the lack of support of mln_concrete).
Fix documentation.
* image2d_int.i, image2d_int_u8.i: Instantiate
mln::trait::concrete to have swig understand the return types of
mln::morpho::dilation.hh and mln::morpho::erosion.
* ch_value.ixx: Adjust documentation.
* Makefile.am (meta_wrappers, wrappers): New variables.
Use them...
(EXTRA_DIST): ...here.
(meta_wrappers): Add concrete.ixx.
Makefile.am | 10 +++++---
ch_value.ixx | 6 ++---
concrete.ixx | 64 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
image2d_int.i | 3 ++
image2d_int_u8.i | 4 +++
morpho.ixx | 41 ++++++-----------------------------
6 files changed, 88 insertions(+), 40 deletions(-)
Index: image2d_int_u8.i
--- image2d_int_u8.i (revision 2131)
+++ image2d_int_u8.i (working copy)
@@ -64,6 +64,10 @@
%}
%include "morpho.ixx"
+
+// Explicit instantiation of this trait for the return type of
+// mln::morpho::dilation and mln::morpho::erosion.
+%template() mln::trait::concrete< mln::image2d< mln::value::int_u<8> >
>;
/* FIXME: Can't we use `mln::value::int8' directlt here (as we can
use `mln::window2d', which is a really just typedef for
`mln::window< mln::dpoint_<mln::grid::square, int> >')? */
Index: ch_value.ixx
--- ch_value.ixx (revision 2131)
+++ ch_value.ixx (working copy)
@@ -28,12 +28,12 @@
/// \file ch_value.i
/// \brief A wrapper of mln::trait::ch_value.
+///
+/// This is a very limited workaround for the difficult wrapping of
+/// mln::trait::ch_value (or even of a subset of it).
%module ch_value
-/* FIXME: Use this very limited workaround instead of
- mln/trait/ch_value.hh or even a subset of it for the moment. */
-
%{
#include "mln/trait/ch_value.hh"
%}
Index: image2d_int.i
--- image2d_int.i (revision 2131)
+++ image2d_int.i (working copy)
@@ -49,5 +49,8 @@
%}
%include "morpho.ixx"
+// Explicit instantiation of this trait for the return type of
+// mln::morpho::dilation and mln::morpho::erosion.
+%template() mln::trait::concrete< mln::image2d< int > >;
%template(dilation) mln::morpho::dilation< mln::image2d<int>, mln::window2d
>;
%template(erosion) mln::morpho::erosion< mln::image2d<int>, mln::window2d >;
Index: Makefile.am
--- Makefile.am (revision 2131)
+++ Makefile.am (working copy)
@@ -4,13 +4,15 @@
# Meta-wrappers (templates), not generating a module, but factoring
# common parts.
-EXTRA_DIST = \
- ch_value.ixx fill.ixx image2d.ixx intp.ixx int_u.ixx \
- morpho.ixx pgm.ixx println.ixx
+meta_wrappers = \
+ ch_value.ixx concrete.ixx fill.ixx image2d.ixx intp.ixx \
+ int_u.ixx morpho.ixx pgm.ixx println.ixx
# Wrappers (generating actual modules).
-EXTRA_DIST += \
+wrappers = \
dpoint2d.i image2d_int.i image2d_int_u8.i int_u8.i \
int_u32.i neighb2d.i point2d.i window2d.i
+EXTRA_DIST = $(meta_wrappers) $(wrappers)
+
check_SCRIPTS = run
Index: concrete.ixx
--- concrete.ixx (revision 0)
+++ concrete.ixx (revision 0)
@@ -0,0 +1,64 @@
+// -*- C++ -*-
+// Copyright (C) 2008 EPITA Research and Development Laboratory (LRDE)
+//
+// 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.
+// reasons why the executable file might be covered by the GNU General
+// Public License.
+
+/// \file concrete.i
+/// \brief A wrapper of mln::trait::concrete.
+///
+/// This is a very limited workaround for the difficult wrapping of
+/// mln::trait::concrete.
+
+%module concrete
+
+%{
+#include "mln/trait/concrete.hh"
+%}
+
+# define mln_concrete(I) typename mln::trait::concrete< I >::ret
+
+namespace mln
+{
+ namespace trait
+ {
+ /* Swig is not powerful enough to parse difficult templates. For
+ instance, it won't match this specialization.
+
+ mln::trait::concrete depends on mln::trait::ch_value.ixx that
+ swig cannot wrap yet (see ch_value.ixx). So we just give it
+ simple ``inlined'' equivalent traits that are compatible with
+ the ones in mln/trait/ch_value.hh. */
+
+ // By default, assume the concrete type is the paramater itself.
+ template <typename I>
+ struct concrete
+ {
+ typedef I ret;
+ };
+
+ } // end of namespace mln::morpho
+
+} // end of namespace mln
Index: morpho.ixx
--- morpho.ixx (revision 2131)
+++ morpho.ixx (working copy)
@@ -26,49 +26,24 @@
// reasons why the executable file might be covered by the GNU General
// Public License.
-/// \file fill.i
+/// \file morpho.i
/// \brief Wrappers of morphological algorithms from mln::morpho.
%module morpho
-/*---------------------------.
-| Dilation and erxrebosion. |
-`---------------------------*/
+/*-----------------------.
+| Dilation and erosion. |
+`-----------------------*/
+
+%include "concrete.ixx"
%{
#include "mln/morpho/dilation.hh"
#include "mln/morpho/erosion.hh"
%}
-// FIXME: Wrap mln::morpho::erosion by hand, for mln_concrete(I)
-// disturbs swig. Annotate the original source code instead?
-namespace mln
-{
- namespace morpho
- {
-
- /* FIXME: How can we handle concrete in Swilena? Simplify this
- for the moment, and use I directly as return type.
-
- 2008-08-08: Actualy, it's very simple: just ask swig to wrap
- the macro `mln_concrete'. See how we did it with
- `mln_ch_value'.
-
- We should apply this to as many wrappers as we can: we have
- inlined many `mln_*' macros so far, and it is a pain to
- maintain. */
-
- template <typename I, typename W>
- I
- dilation(const Image<I>& input, const Window<W>& win);
-
- template <typename I, typename W>
- I
- erosion(const Image<I>& input, const Window<W>& win);
-
- } // end of namespace mln::morpho
-
-} // end of namespace mln
+%include "mln/morpho/dilation.hh"
+%include "mln/morpho/erosion.hh"
/*------------------------------------.