* Makefile.am ($(srcdir)/headers.mk): Do not recurse on
rule regen-dist and inline its action instead.
---
milena/ChangeLog | 7 +++++++
milena/Makefile.am | 23 +++++++++++++++++++++--
2 files changed, 28 insertions(+), 2 deletions(-)
diff --git a/milena/ChangeLog b/milena/ChangeLog
index 9ff0c15..79da1c0 100644
--- a/milena/ChangeLog
+++ b/milena/ChangeLog
@@ -1,5 +1,12 @@
2009-05-26 Roland Levillain <roland(a)lrde.epita.fr>
+ Get rid of an infinite recursion in Milena's Makefile.
+
+ * Makefile.am ($(srcdir)/headers.mk): Do not recurse on
+ rule regen-dist and inline its action instead.
+
+2009-05-26 Roland Levillain <roland(a)lrde.epita.fr>
+
Fix the regeneration of headers.mk from Makefile.
* Makefile.am (regen-dist): Do not make headers.mk read-only,
diff --git a/milena/Makefile.am b/milena/Makefile.am
index 2fc5ec9..30cf50a 100644
--- a/milena/Makefile.am
+++ b/milena/Makefile.am
@@ -28,13 +28,32 @@ tools:
.PHONY: regen-dist
regen-dist:
cd $(srcdir) && ./generate_dist_headers.sh
+EXTRA_DIST = generate_dist_headers.sh
+# We do not delegate the action of regenerating `headers.mk' to
+# `regen-dist' like this:
+#
+# $(MAKE) $(AM_MAKEFLAGS) regen-dist
+#
+# to avoid an infinite recursion, since
+#
+# - the generation of `headers.mk' would trigger the update
+# (regeneration) of `Makefile' (due to the behavior of Automade
+# Makefiles);
+#
+# and because
+#
+# - `Makefile' depends on `headers.mk' (because of the `include'
+# statement); and
+# - `headers.mk' depends on `generate_dist_headers.sh'.
+#
+# Hence the redundant action. There may be a better solution.
+
# FIXME: Change generate_dist_headers.sh so that the action looks like this:
#
# $< $@.tmp && mv -f $@.tmp $@ && chmod -w $@
#
-EXTRA_DIST = generate_dist_headers.sh
$(srcdir)/headers.mk: $(srcdir)/generate_dist_headers.sh
- $(MAKE) $(AM_MAKEFLAGS) regen-dist
+ cd $(srcdir) && ./generate_dist_headers.sh
include $(srcdir)/headers.mk
--
1.6.1.2
* Makefile.am (regen-dist): Do not make headers.mk read-only,
since other clients expect it to be writable.
---
milena/ChangeLog | 7 +++++++
milena/Makefile.am | 3 ++-
2 files changed, 9 insertions(+), 1 deletions(-)
diff --git a/milena/ChangeLog b/milena/ChangeLog
index e8366b8..9ff0c15 100644
--- a/milena/ChangeLog
+++ b/milena/ChangeLog
@@ -1,5 +1,12 @@
2009-05-26 Roland Levillain <roland(a)lrde.epita.fr>
+ Fix the regeneration of headers.mk from Makefile.
+
+ * Makefile.am (regen-dist): Do not make headers.mk read-only,
+ since other clients expect it to be writable.
+
+2009-05-26 Roland Levillain <roland(a)lrde.epita.fr>
+
Use fully qualified type names to help Swig.
* mln/core/site_set/box_piter.hh
diff --git a/milena/Makefile.am b/milena/Makefile.am
index e82862f..2fc5ec9 100644
--- a/milena/Makefile.am
+++ b/milena/Makefile.am
@@ -24,9 +24,10 @@ tutorial:
tools:
$(MAKE) -C tools all
+# Force the regeneration of `headers.mk'.
.PHONY: regen-dist
regen-dist:
- cd $(srcdir) && ./generate_dist_headers.sh && chmod -w headers.mk
+ cd $(srcdir) && ./generate_dist_headers.sh
# FIXME: Change generate_dist_headers.sh so that the action looks like this:
#
# $< $@.tmp && mv -f $@.tmp $@ && chmod -w $@
--
1.6.1.2
* python-utils.ixx: New file.
* Makefile.am (meta_wrappers): Add python-utils.ixx.
---
swilena/ChangeLog | 7 +++++
swilena/Makefile.am | 3 +-
swilena/python-utils.ixx | 59 ++++++++++++++++++++++++++++++++++++++++++++++
3 files changed, 68 insertions(+), 1 deletions(-)
create mode 100644 swilena/python-utils.ixx
diff --git a/swilena/ChangeLog b/swilena/ChangeLog
index bca8f39..09b5aea 100644
--- a/swilena/ChangeLog
+++ b/swilena/ChangeLog
@@ -31,6 +31,13 @@
2009-05-26 Roland Levillain <roland(a)lrde.epita.fr>
+ Add Python conversion helper generators to Swilena.
+
+ * python-utils.ixx: New file.
+ * Makefile.am (meta_wrappers): Add python-utils.ixx.
+
+2009-05-26 Roland Levillain <roland(a)lrde.epita.fr>
+
Add concatenating macros to Swilena.
* concat.ixx: New file.
diff --git a/swilena/Makefile.am b/swilena/Makefile.am
index 80a79a9..2e08041 100644
--- a/swilena/Makefile.am
+++ b/swilena/Makefile.am
@@ -6,7 +6,8 @@ SUBDIRS = python
# common parts.
meta_wrappers = \
box_piter.i ch_value.ixx concat.ixx concrete.ixx fill.ixx \
- image2d.ixx intp.ixx int_u.ixx morpho.ixx pgm.ixx println.ixx
+ image2d.ixx intp.ixx int_u.ixx morpho.ixx pgm.ixx println.ixx \
+ python-utils.ixx
# Wrappers (generating actual modules).
wrappers = \
diff --git a/swilena/python-utils.ixx b/swilena/python-utils.ixx
new file mode 100644
index 0000000..ff11922
--- /dev/null
+++ b/swilena/python-utils.ixx
@@ -0,0 +1,59 @@
+// -*- C++ -*-
+// Copyright (C) 2009 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 python-utils.ixx
+/// \brief Utilities for Python wrappers.
+
+/// Generate a helper for the conversion to int.
+%define generate__int__(Type)
+%extend Type
+{
+ int __int__() const { return *$self; }
+}
+%enddef // !generate__int__
+
+/// Generate a helper for the conversion to string.
+%define generate__str__(Type)
+%{
+#include <cstring>
+#include <string>
+#include <sstream>
+%}
+
+%extend Type
+{
+ char* __str__() const
+ {
+ std::ostringstream s;
+ s << *$self;
+ // FIXME: This is admittedly ugly; can't we use std::string as
+ // return type? See Swig's manual.
+ return strdup(s.str().c_str());
+ }
+}
+%enddef // !generate__str__
--
1.6.1.2
* concat.ixx: New file.
* Makefile.am (meta_wrappers): Add concat.ixx
---
swilena/ChangeLog | 7 +++++++
swilena/Makefile.am | 4 ++--
swilena/concat.ixx | 43 +++++++++++++++++++++++++++++++++++++++++++
3 files changed, 52 insertions(+), 2 deletions(-)
create mode 100644 swilena/concat.ixx
diff --git a/swilena/ChangeLog b/swilena/ChangeLog
index bbbe6d7..bca8f39 100644
--- a/swilena/ChangeLog
+++ b/swilena/ChangeLog
@@ -31,6 +31,13 @@
2009-05-26 Roland Levillain <roland(a)lrde.epita.fr>
+ Add concatenating macros to Swilena.
+
+ * concat.ixx: New file.
+ * Makefile.am (meta_wrappers): Add concat.ixx
+
+2009-05-26 Roland Levillain <roland(a)lrde.epita.fr>
+
Wrap iterators on mln::box2d.
* box_piter.ixx, box2d_piter.i: New.
diff --git a/swilena/Makefile.am b/swilena/Makefile.am
index d20d238..80a79a9 100644
--- a/swilena/Makefile.am
+++ b/swilena/Makefile.am
@@ -5,8 +5,8 @@ SUBDIRS = python
# Meta-wrappers (templates), not generating a module, but factoring
# common parts.
meta_wrappers = \
- box_piter.i ch_value.ixx concrete.ixx fill.ixx image2d.ixx \
- intp.ixx int_u.ixx morpho.ixx pgm.ixx println.ixx
+ box_piter.i ch_value.ixx concat.ixx concrete.ixx fill.ixx \
+ image2d.ixx intp.ixx int_u.ixx morpho.ixx pgm.ixx println.ixx
# Wrappers (generating actual modules).
wrappers = \
diff --git a/swilena/concat.ixx b/swilena/concat.ixx
new file mode 100644
index 0000000..bb8c460
--- /dev/null
+++ b/swilena/concat.ixx
@@ -0,0 +1,43 @@
+// -*- C++ -*-
+// Copyright (C) 2009 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 concat.ixx
+/// \brief Macros concatenating their arguments.
+///
+/// These macros are useful to wrap strings containing commas and
+/// passed as arguments other macros. For instance, to pass the
+/// argument <tt>Bar<int, float></tt> to a macro
+/// <tt>instantiate_foo</tt> taking a single argument, use this:
+///
+/// \code
+/// instantiate_foo(concat2(Bar<int, float>))
+/// \endcode
+
+#define concat2(A, B) A, B
+#define concat3(A, B, C) A, B, C
+#define concat4(A, B, C, D) A, B, C, D
--
1.6.1.2
* ch_value.ixx, dpoint2d.i, dynamic_image2d.i, fill.ixx,
* image2d.ixx, image2d_int.i, image2d_int_u8.i, int_u.ixx,
* intp.ixx, morpho.ixx, neighb2d.i, window2d.i,
* python/morpho-fun.py, python/morpho-segm.py:
Here.
---
swilena/ChangeLog | 10 ++++++++++
swilena/ch_value.ixx | 2 +-
swilena/dpoint2d.i | 2 +-
swilena/dynamic_image2d.i | 2 +-
swilena/fill.ixx | 2 +-
swilena/image2d.ixx | 2 +-
swilena/image2d_int.i | 7 +------
swilena/image2d_int_u8.i | 2 +-
swilena/int_u.ixx | 2 +-
swilena/intp.ixx | 13 +++++++++----
swilena/morpho.ixx | 2 +-
swilena/neighb2d.i | 2 +-
swilena/python/morpho-fun.py | 2 +-
swilena/python/morpho-segm.py | 2 +-
swilena/window2d.i | 2 +-
15 files changed, 32 insertions(+), 22 deletions(-)
diff --git a/swilena/ChangeLog b/swilena/ChangeLog
index 4a83499..bbbe6d7 100644
--- a/swilena/ChangeLog
+++ b/swilena/ChangeLog
@@ -1,5 +1,15 @@
2009-05-27 Roland Levillain <roland(a)lrde.epita.fr>
+ Update dates in Swilena's copyright headers.
+
+ * ch_value.ixx, dpoint2d.i, dynamic_image2d.i, fill.ixx,
+ * image2d.ixx, image2d_int.i, image2d_int_u8.i, int_u.ixx,
+ * intp.ixx, morpho.ixx, neighb2d.i, window2d.i,
+ * python/morpho-fun.py, python/morpho-segm.py:
+ Here.
+
+2009-05-27 Roland Levillain <roland(a)lrde.epita.fr>
+
Exercise Swilena/Python iterators.
* python/box2d-misc.py: New test.
diff --git a/swilena/ch_value.ixx b/swilena/ch_value.ixx
index 9ed217c..e48f371 100644
--- a/swilena/ch_value.ixx
+++ b/swilena/ch_value.ixx
@@ -1,5 +1,5 @@
// -*- C++ -*-
-// Copyright (C) 2008 EPITA Research and Development Laboratory (LRDE)
+// Copyright (C) 2008, 2009 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
diff --git a/swilena/dpoint2d.i b/swilena/dpoint2d.i
index 48a4e93..bde8f07 100644
--- a/swilena/dpoint2d.i
+++ b/swilena/dpoint2d.i
@@ -1,5 +1,5 @@
// -*- C++ -*-
-// Copyright (C) 2008 EPITA Research and Development Laboratory (LRDE)
+// Copyright (C) 2008, 2009 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
diff --git a/swilena/dynamic_image2d.i b/swilena/dynamic_image2d.i
index acee985..2ae3c16 100644
--- a/swilena/dynamic_image2d.i
+++ b/swilena/dynamic_image2d.i
@@ -1,5 +1,5 @@
// -*- C++ -*-
-// Copyright (C) 2008 EPITA Research and Development Laboratory (LRDE)
+// Copyright (C) 2008, 2009 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
diff --git a/swilena/fill.ixx b/swilena/fill.ixx
index a1c1e2c..958c5ae 100644
--- a/swilena/fill.ixx
+++ b/swilena/fill.ixx
@@ -1,5 +1,5 @@
// -*- C++ -*-
-// Copyright (C) 2008 EPITA Research and Development Laboratory (LRDE)
+// Copyright (C) 2008, 2009 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
diff --git a/swilena/image2d.ixx b/swilena/image2d.ixx
index 4e46159..75f0f3b 100644
--- a/swilena/image2d.ixx
+++ b/swilena/image2d.ixx
@@ -1,5 +1,5 @@
// -*- C++ -*-
-// Copyright (C) 2008 EPITA Research and Development Laboratory (LRDE)
+// Copyright (C) 2008, 2009 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
diff --git a/swilena/image2d_int.i b/swilena/image2d_int.i
index 095be31..92f3d5e 100644
--- a/swilena/image2d_int.i
+++ b/swilena/image2d_int.i
@@ -1,5 +1,5 @@
// -*- C++ -*-
-// Copyright (C) 2008 EPITA Research and Development Laboratory (LRDE)
+// Copyright (C) 2008, 2009 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
@@ -32,11 +32,6 @@
%module image2d_int
-/* FIXME: Shouldn't it be
-
- %include "intp.i"
-
- instead? After all, module `intp' generates wrappers too. */
%include "intp.ixx"
%include "image2d.ixx"
instantiate_image2d(image2d_int, int)
diff --git a/swilena/image2d_int_u8.i b/swilena/image2d_int_u8.i
index 38f1318..b420445 100644
--- a/swilena/image2d_int_u8.i
+++ b/swilena/image2d_int_u8.i
@@ -1,5 +1,5 @@
// -*- C++ -*-
-// Copyright (C) 2008 EPITA Research and Development Laboratory (LRDE)
+// Copyright (C) 2008, 2009 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
diff --git a/swilena/int_u.ixx b/swilena/int_u.ixx
index cb9c29d..71fc02e 100644
--- a/swilena/int_u.ixx
+++ b/swilena/int_u.ixx
@@ -1,5 +1,5 @@
// -*- C++ -*-
-// Copyright (C) 2008 EPITA Research and Development Laboratory (LRDE)
+// Copyright (C) 2008, 2009 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
diff --git a/swilena/intp.ixx b/swilena/intp.ixx
index 41ad5b7..add19cf 100644
--- a/swilena/intp.ixx
+++ b/swilena/intp.ixx
@@ -1,5 +1,5 @@
// -*- C++ -*-
-// Copyright (C) 2008 EPITA Research and Development Laboratory (LRDE)
+// Copyright (C) 2008, 2009 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
@@ -32,8 +32,13 @@
%module intp
%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);
+
+/* FIXME: Wrapping a class interface around an "int *" using
+
+ %pointer_class(int, intp);
+
+ would be better (see http://www.swig.org/Doc1.3/Library.html#Library_nn4).
+ We might be able to add extra methods (like __str__) this way. */
+
/* Create some functions for working with "int *" */
%pointer_functions(int, intp);
diff --git a/swilena/morpho.ixx b/swilena/morpho.ixx
index 7145a39..5b90a22 100644
--- a/swilena/morpho.ixx
+++ b/swilena/morpho.ixx
@@ -1,5 +1,5 @@
// -*- C++ -*-
-// Copyright (C) 2008 EPITA Research and Development Laboratory (LRDE)
+// Copyright (C) 2008, 2009 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
diff --git a/swilena/neighb2d.i b/swilena/neighb2d.i
index 38a4370..a5c67b2 100644
--- a/swilena/neighb2d.i
+++ b/swilena/neighb2d.i
@@ -1,5 +1,5 @@
// -*- C++ -*-
-// Copyright (C) 2008 EPITA Research and Development Laboratory (LRDE)
+// Copyright (C) 2008, 2009 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
diff --git a/swilena/python/morpho-fun.py b/swilena/python/morpho-fun.py
index 6b8c10e..bf96e48 100644
--- a/swilena/python/morpho-fun.py
+++ b/swilena/python/morpho-fun.py
@@ -1,6 +1,6 @@
#! /usr/bin/env python
-# Copyright (C) 2008 EPITA Research and Development Laboratory (LRDE)
+# Copyright (C) 2008, 2009 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
diff --git a/swilena/python/morpho-segm.py b/swilena/python/morpho-segm.py
index 5874f19..83af24d 100644
--- a/swilena/python/morpho-segm.py
+++ b/swilena/python/morpho-segm.py
@@ -1,6 +1,6 @@
#! /usr/bin/env python
-# Copyright (C) 2008 EPITA Research and Development Laboratory (LRDE)
+# Copyright (C) 2008, 2009 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
diff --git a/swilena/window2d.i b/swilena/window2d.i
index d95b55a..68556c6 100644
--- a/swilena/window2d.i
+++ b/swilena/window2d.i
@@ -1,5 +1,5 @@
// -*- C++ -*-
-// Copyright (C) 2008 EPITA Research and Development Laboratory (LRDE)
+// Copyright (C) 2008, 2009 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
--
1.6.1.2
* python/box2d-misc.py: New test.
* python/Makefile.am (TESTS): Add box2d-misc.py.
---
swilena/ChangeLog | 7 +++++
swilena/python/Makefile.am | 9 ++++++-
swilena/python/box2d-misc.py | 58 ++++++++++++++++++++++++++++++++++++++++++
3 files changed, 73 insertions(+), 1 deletions(-)
create mode 100644 swilena/python/box2d-misc.py
diff --git a/swilena/ChangeLog b/swilena/ChangeLog
index 776aec3..4a83499 100644
--- a/swilena/ChangeLog
+++ b/swilena/ChangeLog
@@ -1,5 +1,12 @@
2009-05-27 Roland Levillain <roland(a)lrde.epita.fr>
+ Exercise Swilena/Python iterators.
+
+ * python/box2d-misc.py: New test.
+ * python/Makefile.am (TESTS): Add box2d-misc.py.
+
+2009-05-27 Roland Levillain <roland(a)lrde.epita.fr>
+
Have Swilena/Python make use of iterators.
* python/dynamic-image2d-misc.py, python/image2d-misc.py:
diff --git a/swilena/python/Makefile.am b/swilena/python/Makefile.am
index be2effc..ad41c3c 100644
--- a/swilena/python/Makefile.am
+++ b/swilena/python/Makefile.am
@@ -195,5 +195,12 @@ $(srcdir)/run.stamp: $(RUN_IN)
$(MAKE) $(AM_MAKEFLAGS) $(RUN)
@mv -f $@.tmp $@
-TESTS = image2d-misc.py morpho-fun.py morpho-segm.py dynamic-image2d-misc.py
+# FIXME: We should not use the `.py' extension: it is not needed, and
+# it prevents us from using the same name for both a module (wrapper)
+# and a test. Alas, the script `run' expects a file name with an
+# extension as argument. We could improve this by adding options such
+# as `--python' to `run'.
+TESTS = \
+ box2d-misc.py \
+ image2d-misc.py morpho-fun.py morpho-segm.py dynamic-image2d-misc.py
EXTRA_DIST += $(TESTS)
diff --git a/swilena/python/box2d-misc.py b/swilena/python/box2d-misc.py
new file mode 100644
index 0000000..7cd3011
--- /dev/null
+++ b/swilena/python/box2d-misc.py
@@ -0,0 +1,58 @@
+#! /usr/bin/env python
+
+# Copyright (C) 2009 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.
+
+from swilena import *
+
+# Generic iterator interface.
+
+b = box2d(2, 3)
+p = iter(b)
+while p.is_valid():
+ print p.site()
+ p.advance()
+
+print
+
+# Python's iterator interface.
+
+# We cannot use
+#
+# for p in box2d(2, 3):
+# print p
+#
+# here because the box2d is a temporary object that may be collected
+# before the end of the iteration. To prevent Python from disposing
+# of it, we use a named variable that will
+#
+# Another possibility would be to have a generator playing with the
+# `thisown' field of the box, to prevent its destruction (see
+# http://www.swig.org/Doc1.3/SWIGDocumentation.html#Python_nn30).
+
+for p in b:
+ print p
--
1.6.1.2
* python/dynamic-image2d-misc.py, python/image2d-misc.py:
Simplify constructions.
Use iterators on domain instead of ad hoc iterations.
---
swilena/ChangeLog | 8 ++++++++
swilena/python/dynamic-image2d-misc.py | 22 ++++------------------
swilena/python/image2d-misc.py | 27 ++++++++++-----------------
3 files changed, 22 insertions(+), 35 deletions(-)
diff --git a/swilena/ChangeLog b/swilena/ChangeLog
index 07d0481..776aec3 100644
--- a/swilena/ChangeLog
+++ b/swilena/ChangeLog
@@ -1,5 +1,13 @@
2009-05-27 Roland Levillain <roland(a)lrde.epita.fr>
+ Have Swilena/Python make use of iterators.
+
+ * python/dynamic-image2d-misc.py, python/image2d-misc.py:
+ Simplify constructions.
+ Use iterators on domain instead of ad hoc iterations.
+
+2009-05-27 Roland Levillain <roland(a)lrde.epita.fr>
+
Add conversion to string to point2d.
* point2d.i (__str__): New method (extension).
diff --git a/swilena/python/dynamic-image2d-misc.py b/swilena/python/dynamic-image2d-misc.py
index f6b73b3..941a929 100644
--- a/swilena/python/dynamic-image2d-misc.py
+++ b/swilena/python/dynamic-image2d-misc.py
@@ -1,6 +1,6 @@
#! /usr/bin/env python
-# Copyright (C) 2008 EPITA Research and Development Laboratory (LRDE)
+# Copyright (C) 2008, 2009 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
@@ -60,25 +60,11 @@ class simple_image(dyn_ima2d):
return True
-# FIXME: Why can't I use
-#
-# b = box2d(10, 10)
-#
-# directly?
-#
-# I think this is probably because SWIG's way to handle overloading in
-# Python depends just on the *number* of arguments, not their types --
-# and we already have a wrapped ctor with 2 arguments, the one taking
-# two mln::point2d's, so the second one (with two int's) is probably
-# hidden). Pay more attention to swig's warnings!
-b = box2d(point2d(0,0), point2d(9,9))
+b = box2d(10, 10)
ima = simple_image(b)
image.fill(ima, int_u8(42))
image.println(ima)
-# FIXME: Doesn't really work yet, since int_u8 is not convertible
-# to int.
-for r in range(0, 10):
- for c in range(0, 10):
- print ima(point2d(r, c))
+for p in ima.domain():
+ print ima(p)
diff --git a/swilena/python/image2d-misc.py b/swilena/python/image2d-misc.py
index 2a406a8..e0b2a91 100644
--- a/swilena/python/image2d-misc.py
+++ b/swilena/python/image2d-misc.py
@@ -1,6 +1,6 @@
#! /usr/bin/env python
-# Copyright (C) 2008 EPITA Research and Development Laboratory (LRDE)
+# Copyright (C) 2008, 2009 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
@@ -32,26 +32,19 @@ from swilena import *
ima = image2d_int.image2d_int(3, 3)
image2d_int.fill(ima, 42)
-# FIXME: For the moment, we can't write
-#
-# ima(point2d(i, j))
-#
-# but I don't know why. Anyway, eventually we'd like to be able to
-# write this:
+# FIXME: Eventually we'd like to be able to write this:
#
# for p in ima.domain():
-# print "ima(" + str(i) + ", " + str(j) + ") = " + ima(p)
+# print "ima(" + str(p) + ") = " + ima(p)
#
# 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 = 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_int.intp_value(ima(p))
- print "ima(" + str(i) + ", " + str(j) + ") = " + str(v)
+for p in ima.domain():
+ # 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_int.intp_value(ima(p))
+ print "ima" + str(p) + " = " + str(v)
# FIXME: This is too complicated. We should be able to write
#
--
1.6.1.2
* box_piter.ixx, box2d_piter.i: New.
* box2d.i (__iter__): New method (extension).
* Makefile.am (meta_wrappers): Add box_piter.i
(wrappers): Add box2d_piter.i.
* python/swilena.py: Import module `box2d' before `point2d'.
* python/Makefile.am (pyexec_LTLIBRARIES): Add _box2d.la.
(nodist__box2d_la_SOURCES, _box2d_la_LIBADD): New variables.
(CLEANFILES): Add $(nodist__box2d_la_SOURCES) box2d.py box2d.py[co]
(nodist_python_PYTHON): Add box2d.py.
---
swilena/ChangeLog | 14 ++++
swilena/Makefile.am | 9 ++-
swilena/box2d.i | 11 +++
swilena/box2d_piter.i | 154 ++++++++++++++++++++++++++++++++++++++++++++
swilena/box_piter.ixx | 39 +++++++++++
swilena/python/Makefile.am | 10 +++
swilena/python/swilena.py | 4 +-
7 files changed, 235 insertions(+), 6 deletions(-)
create mode 100644 swilena/box2d_piter.i
create mode 100644 swilena/box_piter.ixx
diff --git a/swilena/ChangeLog b/swilena/ChangeLog
index 917269e..f9bf4a4 100644
--- a/swilena/ChangeLog
+++ b/swilena/ChangeLog
@@ -1,5 +1,19 @@
2009-05-26 Roland Levillain <roland(a)lrde.epita.fr>
+ Wrap iterators on mln::box2d.
+
+ * box_piter.ixx, box2d_piter.i: New.
+ * box2d.i (__iter__): New method (extension).
+ * Makefile.am (meta_wrappers): Add box_piter.i
+ (wrappers): Add box2d_piter.i.
+ * python/swilena.py: Import module `box2d' before `point2d'.
+ * python/Makefile.am (pyexec_LTLIBRARIES): Add _box2d.la.
+ (nodist__box2d_la_SOURCES, _box2d_la_LIBADD): New variables.
+ (CLEANFILES): Add $(nodist__box2d_la_SOURCES) box2d.py box2d.py[co]
+ (nodist_python_PYTHON): Add box2d.py.
+
+2009-05-26 Roland Levillain <roland(a)lrde.epita.fr>
+
* box2d.i: Add a ctor taking two `int's as argument.
2009-05-26 Roland Levillain <roland(a)lrde.epita.fr>
diff --git a/swilena/Makefile.am b/swilena/Makefile.am
index ef711d8..d20d238 100644
--- a/swilena/Makefile.am
+++ b/swilena/Makefile.am
@@ -5,13 +5,14 @@ SUBDIRS = python
# Meta-wrappers (templates), not generating a module, but factoring
# common parts.
meta_wrappers = \
- ch_value.ixx concrete.ixx fill.ixx image2d.ixx intp.ixx \
- int_u.ixx morpho.ixx pgm.ixx println.ixx
+ box_piter.i ch_value.ixx concrete.ixx fill.ixx image2d.ixx \
+ intp.ixx int_u.ixx morpho.ixx pgm.ixx println.ixx
# Wrappers (generating actual modules).
wrappers = \
- box2d.i dpoint2d.i image2d_int.i image2d_int_u8.i int_u8.i \
- int_u32.i neighb2d.i point2d.i window2d.i \
+ box2d.i box2d_piter.i dpoint2d.i image2d_int.i \
+ image2d_int_u8.i int_u8.i int_u32.i neighb2d.i point2d.i \
+ window2d.i \
\
dynamic_image2d.i
diff --git a/swilena/box2d.i b/swilena/box2d.i
index e24f016..7a25565 100644
--- a/swilena/box2d.i
+++ b/swilena/box2d.i
@@ -31,6 +31,8 @@
%module box2d
+%import box2d_piter.i
+
%{
#include "mln/core/site_set/box.hh"
#include "mln/core/alias/box2d.hh"
@@ -70,6 +72,15 @@
return new mln::box<mln::point2d>(nrows, ncols);
}
+ // FIXME: Shorten using macros...
+ mln::box_fwd_piter_< mln::point<mln::grid::square, mln::def::coord> >
+ __iter__() const
+ {
+ mln::box_fwd_piter_<mln::point2d> p(*$self);
+ p.start();
+ return p;
+ }
+
unsigned nrows() const
{
// FIXME: This is the exact content of box_impl_<2, C, E>::nrows.
diff --git a/swilena/box2d_piter.i b/swilena/box2d_piter.i
new file mode 100644
index 0000000..f5ac026
--- /dev/null
+++ b/swilena/box2d_piter.i
@@ -0,0 +1,154 @@
+// -*- C++ -*-
+// Copyright (C) 2009 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 box2d_piter.i
+/// \brief A wrapper of mln::box_fwd_piter_< mln::point2d >.
+
+%module box2d_piter
+
+%include box_piter.ixx
+
+%{
+#include "mln/core/alias/point2d.hh"
+%}
+
+%import point2d.i
+
+// FIXME: Move reusable parts elsewhere (in box_piter.i and/or another
+// file).
+
+// Ignore internal methods.
+%ignore mln::box_fwd_piter_< mln::point<mln::grid::square, mln::def::coord> >::is_valid_();
+%ignore mln::box_fwd_piter_< mln::point<mln::grid::square, mln::def::coord> >::invalidate_();
+%ignore mln::box_fwd_piter_< mln::point<mln::grid::square, mln::def::coord> >::start_();
+%ignore mln::box_fwd_piter_< mln::point<mln::grid::square, mln::def::coord> >::next_();
+
+// Ignore the backward iterator (for the moment).
+%ignore mln::box_bkd_piter_< mln::point<mln::grid::square, mln::def::coord> >;
+
+
+/*--------------------.
+| Generic interface. |
+`--------------------*/
+
+/* These methods are mostly for debugging purpose: we should use the
+ language's interface (e.g. Python's `next()') to manipulate an
+ iterator. */
+/* FIXME: Except for `site()', these methods could be generated by
+ Swig by wrapping base classes mln::Iterator and mln::Site_Iterator
+ of mln::box_fwd_piter_ (and renaming Site_Iterator's `next()' as
+ `advance()' to avoid a name clash with the new `next()' method
+ added to Python's code. */
+%extend mln::box_fwd_piter_< mln::point<mln::grid::square, mln::def::coord> >
+{
+ // Return the site pointed by an iterator.
+ const mln::point<mln::grid::square, mln::def::coord>
+ site()
+ {
+ return *$self;
+ }
+
+ // Initiate the iterator.
+ void
+ start()
+ {
+ $self->start();
+ }
+
+ // Move the iterator forward.
+ void
+ advance()
+ {
+ $self->next();
+ }
+
+ // Is the iterator valid?
+ bool
+ is_valid()
+ {
+ return $self->is_valid();
+ }
+
+ // Invalidate the iterator.
+ void
+ invalidate()
+ {
+ $self->invalidate();
+ }
+}
+
+
+/*-------------------.
+| Python interface. |
+`-------------------*/
+
+#if SWIGPYTHON
+
+// Handling iterators à la Python.
+
+%extend mln::box_fwd_piter_< mln::point<mln::grid::square, mln::def::coord> >
+{
+ mln::box_fwd_piter_< mln::point<mln::grid::square, mln::def::coord> >&
+ __iter__()
+ {
+ return *$self;
+ }
+}
+
+// Raise a Python `StopIteration' exception on `next()' if the
+// iterator is invalid.
+%exception mln::box_fwd_piter_< mln::point<mln::grid::square, mln::def::coord> >::next
+{
+ /* FIXME: Is it safe to use `arg1'? It seems to be pretty
+ low-level, and may not be part of Swig's standard interface. */
+ if (!arg1->is_valid())
+ {
+ PyErr_SetString(PyExc_StopIteration, "Invalid iterator");
+ return NULL;
+ }
+ $action
+}
+
+%extend mln::box_fwd_piter_< mln::point<mln::grid::square, mln::def::coord> >
+{
+ const mln::point<mln::grid::square, mln::def::coord>
+ next()
+ {
+ // Keep a copy of the current site before incrementation.
+ const mln::point<mln::grid::square, mln::def::coord> current = *$self;
+ // Delegate incrementation to `Super_Iterator's `next()' method.
+ $self->next();
+ return current;
+ }
+}
+
+#endif // !SWIGPYTHON
+
+
+%template(box2d_piter)
+mln::box_fwd_piter_< mln::point<mln::grid::square, mln::def::coord> >;
diff --git a/swilena/box_piter.ixx b/swilena/box_piter.ixx
new file mode 100644
index 0000000..7b34272
--- /dev/null
+++ b/swilena/box_piter.ixx
@@ -0,0 +1,39 @@
+// -*- C++ -*-
+// Copyright (C) 2009 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 box_piter.ixx
+/// \brief A wrapper of mln::box_fwd_piter_<P>.
+
+%module box_piter
+
+%{
+
+#include "mln/core/site_set/box_piter.hh"
+%}
+
+%include "mln/core/site_set/box_piter.hh"
diff --git a/swilena/python/Makefile.am b/swilena/python/Makefile.am
index 110a9c0..be2effc 100644
--- a/swilena/python/Makefile.am
+++ b/swilena/python/Makefile.am
@@ -77,6 +77,16 @@ CLEANFILES += $(nodist__box2d_la_SOURCES) box2d.py box2d.py[co]
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/_box2d-wrap.Pcc@am__quote@
nodist_python_PYTHON += box2d.py
+## box2d_piter.
+pyexec_LTLIBRARIES += _box2d_piter.la
+nodist__box2d_piter_la_SOURCES = box2d_piter-wrap.cc
+_box2d_piter_la_LIBADD = $(AM_LIBADD)
+CLEANFILES += $(nodist__box2d_piter_la_SOURCES) box2d_piter.py box2d_piter.py[co]
+## Include the dependency files. Copied from Automake's generated
+## case for C++.
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/_box2d_piter-wrap.Pcc@am__quote@
+nodist_python_PYTHON += box2d_piter.py
+
## int_u8.
pyexec_LTLIBRARIES += _int_u8.la
nodist__int_u8_la_SOURCES = int_u8-wrap.cc
diff --git a/swilena/python/swilena.py b/swilena/python/swilena.py
index e5a7e45..601b6ee 100644
--- a/swilena/python/swilena.py
+++ b/swilena/python/swilena.py
@@ -1,6 +1,6 @@
#! /usr/bin/env python
-# Copyright (C) 2008 EPITA Research and Development Laboratory (LRDE)
+# Copyright (C) 2008, 2009 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
@@ -32,9 +32,9 @@
import ltihooks
+from box2d import *
from point2d import *
from dpoint2d import *
-from box2d import *
from neighb2d import *
from window2d import *
--
1.6.1.2