
https://svn.lrde.epita.fr/svn/oln/trunk/swilena Index: ChangeLog from Roland Levillain <roland@lrde.epita.fr> Break Swilena's image2d into modules. * image2d.i: Rename as... * image2d.ixx: ...this. Move parts not directly related to mln::image2d<T>... * intpx.ixx, point2d.ixx, fill.ixx, println.ixx, image2d_int.i: ...here (new files). * python/swilena.py: Adjust. Inject the contents of module point2d. * python/sps.py, python/test.py: Adjust. * python/Makefile.am: Handle module point2d. fill.ixx | 48 +++++++++++++++++++++++++++ image2d.ixx | 94 +---------------------------------------------------- image2d_int.i | 43 ++++++++++++++++++++++++ intp.ixx | 37 ++++++++++++++++++++ point2d.i | 63 +++++++++++++++++++++++++++++++++++ println.ixx | 36 ++++++++++++++++++++ python/Makefile.am | 26 ++++++++++---- python/sps.py | 6 +-- python/swilena.py | 4 +- python/test.py | 12 +++--- 10 files changed, 260 insertions(+), 109 deletions(-) Index: image2d.ixx --- image2d.ixx (revision 2099) +++ image2d.ixx (working copy) @@ -27,63 +27,11 @@ // Public License. /// \file image2d.i -/// \brief A simple wrapping of mln::image2d<int> along with some -/// algorithms. - +/// \brief A wrapper of mln::image2d<T>. %module image2d - -/*------. -| int. | -`------*/ - -%include "cpointer.i" -// Wrap a class interface around an "int *" (see -// // http://www.swig.org/Doc1.3/Library.html#Library_nn4). -// %pointer_class(int, intp); -/* Create some functions for working with "int *" */ -%pointer_functions(int, intp); - - -/*---------------. -| mln::point2d. | -`---------------*/ - -%{ -#include "mln/core/point.hh" -#include "mln/core/point2d.hh" -%} - -%include "mln/core/point.hh"; -%include "mln/core/point2d.hh"; -/* FIXME: Ignore `mln::point_<M,C>::origin' to circumvent a swig bug. - Without this ignore clause, the generated code would trigger this - error : - - image2d-wrap.cc:3115:144: error: macro "SWIG_as_voidptr" passed 2 - arguments, but takes just 1 - image2d-wrap.cc: In function 'PyObject* point2d_origin_get()': - image2d-wrap.cc:3115: error: 'SWIG_as_voidptr' was not declared in this - scope - - Check whether this bug has been fixed in a recent release of SWIG - or if it has been reported. */ -%ignore mln::point_<mln::grid::square,int>::origin; -// Ignoring to_h_vec saves us the wrapping of -%ignore mln::point_<mln::grid::square,int>::to_h_vec; -// Swig tries to wrap everything by default; prevent it from wrapping -// invalid methods (1D and 3D ctors for a point2d). -%ignore mln::point_<mln::grid::square,int>::point_(const literal::zero_t&); -%ignore mln::point_<mln::grid::square,int>::point_(const literal::one_t&); -%ignore mln::point_<mln::grid::square,int>::point_(int); -%ignore mln::point_<mln::grid::square,int>::point_(int, int, int); -// point2d. -%template(point2d) mln::point_<mln::grid::square,int>; - -/*--------------------. -| mln::image2d<int>. | -`--------------------*/ +%import "point2d.i" %{ #include "mln/core/image2d.hh" @@ -208,41 +156,3 @@ }; } // end of namespace mln - -%template(image2d_int) mln::image2d<int>; - - -/*-------------------. -| mln::level::fill. | -`-------------------*/ - -%{ -#include "mln/level/fill.hh" -%} - -// FIXME: Wrap mln::level::fill by hand, for mln_value(I) disturbs -// swig. Annotate the original source code instead? -namespace mln -{ - namespace level - { - template <typename I> - void fill(mln::Image<I>& ima, const typename I::value& v); - } // end of namespace mln::level - -} // end of namespace mln - -%template(fill_image2d_int) mln::level::fill< mln::image2d<int> >; - - -/*----------------------. -| mln::debug::println. | -`----------------------*/ - -%{ - #include "mln/debug/println.hh" -%} - -%include "mln/debug/println.hh" - -%template(println_image2d_int) mln::debug::println< mln::image2d<int> >; Index: python/test.py --- python/test.py (revision 2099) +++ python/test.py (working copy) @@ -29,12 +29,12 @@ from swilena import * -ima = image2d.image2d_int(3, 3) -image2d.fill_image2d_int(ima, 42) +ima = image2d_int.image2d_int(3, 3) +image2d_int.fill(ima, 42) # FIXME: For the moment, we can't write # -# ima(image2d.point2d(i, j)) +# ima(point2d(i, j)) # # but I don't know why. Anyway, eventually we'd like to be able to # write this: @@ -45,13 +45,13 @@ # as it is generic and way closer to what we do in C++. for i in range(0, 3): for j in range(0, 3): - p = image2d.point2d(i, j) + p = point2d(i, j) # FIXME: Handling POD types (like int) as value types is not # transparent: ima(p) returns a pointer to int wrapped in a SWIG # object, and cannot be easily converted to a Python integer # value. Hence this explicit conversion using `intp_value'. - v = image2d.intp_value(ima(p)) + v = image2d_int.intp_value(ima(p)) print "ima(" + str(i) + ", " + str(j) + ") = " + str(v) print -image2d.println_image2d_int(ima) +image2d_int.println(ima) Index: python/Makefile.am --- python/Makefile.am (revision 2099) +++ python/Makefile.am (working copy) @@ -37,16 +37,28 @@ ## FIXME: All of this should be generated. ## Don't forget to add a `deps-reset' target as in TC. -## image2d. -pyexec_LTLIBRARIES = _image2d.la -nodist__image2d_la_SOURCES = image2d-wrap.cc -_image2d_la_LIBADD = $(AM_LIBADD) -CLEANFILES += $(nodist__image2d_la_SOURCES) image2d.py image2d.py[co] +nodist_python_PYTHON = +pyexec_LTLIBRARIES = + +## point2d. +pyexec_LTLIBRARIES += _point2d.la +nodist__point2d_la_SOURCES = point2d-wrap.cc +_point2d_la_LIBADD = $(AM_LIBADD) +CLEANFILES += $(nodist__point2d_la_SOURCES) point2d.py point2d.py[co] ## Include the dependency files. Copied from Automake's generated ## case for C++. -@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/_image2d-wrap.Pcc@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/_point2d-wrap.Pcc@am__quote@ +nodist_python_PYTHON += point2d.py -nodist_python_PYTHON = image2d.py +## image2d_int. +pyexec_LTLIBRARIES += _image2d_int.la +nodist__image2d_int_la_SOURCES = image2d_int-wrap.cc +_image2d_int_la_LIBADD = $(AM_LIBADD) +CLEANFILES += $(nodist__image2d_int_la_SOURCES) image2d_int.py image2d_int.py[co] +## Include the dependency files. Copied from Automake's generated +## case for C++. +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/_image2d_int-wrap.Pcc@am__quote@ +nodist_python_PYTHON += image2d_int.py ## ---------------------------- ## Index: python/swilena.py --- python/swilena.py (revision 2099) +++ python/swilena.py (working copy) @@ -28,4 +28,6 @@ # Public License. import ltihooks -import image2d + +from point2d import * +import image2d_int Index: python/sps.py --- python/sps.py (revision 2099) +++ python/sps.py (working copy) @@ -41,9 +41,9 @@ The following example creates a 2-d image of integers with 3 rows and 3 columns, then fills its cells with the value `42' and prints it: - ima = image2d.image2d_int(3, 3) - image2d.fill_image2d_int(ima, 42) - image2d.println_image2d_int(ima) + ima = image2d_int.image2d_int(3, 3) + image2d_int.fill(ima, 42) + image2d_int.println(ima) You can try it by copying and pasting each line on the following prompt. ''') Index: intp.ixx --- intp.ixx (revision 0) +++ intp.ixx (revision 0) @@ -0,0 +1,37 @@ +// -*- 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 intp.i +/// \brief A wrapper of int pointers. + +%include "cpointer.i" +// Wrap a class interface around an "int *" (see +// // http://www.swig.org/Doc1.3/Library.html#Library_nn4). +// %pointer_class(int, intp); +/* Create some functions for working with "int *" */ +%pointer_functions(int, intp); Index: point2d.i --- point2d.i (revision 0) +++ point2d.i (revision 0) @@ -0,0 +1,63 @@ +// -*- 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 point2d.i +/// \brief A wrapper of mln::point2d. + +%module point2d + +%{ +#include "mln/core/point.hh" +#include "mln/core/point2d.hh" +%} + +%include "mln/core/point.hh"; +%include "mln/core/point2d.hh"; +/* FIXME: Ignore `mln::point_<M,C>::origin' to circumvent a swig bug. + Without this ignore clause, the generated code would trigger this + error : + + image2d-wrap.cc:3115:144: error: macro "SWIG_as_voidptr" passed 2 + arguments, but takes just 1 + image2d-wrap.cc: In function 'PyObject* point2d_origin_get()': + image2d-wrap.cc:3115: error: 'SWIG_as_voidptr' was not declared in this + scope + + Check whether this bug has been fixed in a recent release of SWIG + or if it has been reported. */ +%ignore mln::point_<mln::grid::square,int>::origin; +// Ignoring to_h_vec saves us the wrapping of +%ignore mln::point_<mln::grid::square,int>::to_h_vec; +// Swig tries to wrap everything by default; prevent it from wrapping +// invalid methods (1D and 3D ctors for a point2d). +%ignore mln::point_<mln::grid::square,int>::point_(const literal::zero_t&); +%ignore mln::point_<mln::grid::square,int>::point_(const literal::one_t&); +%ignore mln::point_<mln::grid::square,int>::point_(int); +%ignore mln::point_<mln::grid::square,int>::point_(int, int, int); + +%template(point2d) mln::point_<mln::grid::square,int>; Index: image2d_int.i --- image2d_int.i (revision 0) +++ image2d_int.i (revision 0) @@ -0,0 +1,43 @@ +// -*- 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 image2d.i +/// \brief A simple wrapping of mln::image2d<int> along with some +/// algorithms. + +%module image2d_int + +%include intp.ixx +%include image2d.ixx +%template(image2d_int) mln::image2d<int>; + +%include fill.ixx +%template(fill) mln::level::fill< mln::image2d<int> >; + +%include println.ixx +%template(println) mln::debug::println< mln::image2d<int> >; Index: fill.ixx --- fill.ixx (revision 0) +++ fill.ixx (revision 0) @@ -0,0 +1,48 @@ +// -*- 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 fill.i +/// \brief A wrapper of mln::level::fill. + +%module fill + +%{ +#include "mln/level/fill.hh" +%} + +// FIXME: Wrap mln::level::fill by hand, for mln_value(I) disturbs +// swig. Annotate the original source code instead? +namespace mln +{ + namespace level + { + template <typename I> + void fill(mln::Image<I>& ima, const typename I::value& v); + } // end of namespace mln::level + +} // end of namespace mln Index: println.ixx --- println.ixx (revision 0) +++ println.ixx (revision 0) @@ -0,0 +1,36 @@ +// -*- 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 println.i +/// \brief A wrapper of mln::debug::println. + +%{ + #include "mln/debug/println.hh" +%} + +%include "mln/debug/println.hh"