* int_u.ixx (__int__, __str__): New methods (extensions).
* python/dynamic-image2d-misc.py: Revive dead code.
---
swilena/ChangeLog | 7 +++++++
swilena/int_u.ixx | 25 +++++++++++++++++++++++++
swilena/python/dynamic-image2d-misc.py | 6 +++---
3 files changed, 35 insertions(+), 3 deletions(-)
diff --git a/swilena/ChangeLog b/swilena/ChangeLog
index 135d84c..398b9ab 100644
--- a/swilena/ChangeLog
+++ b/swilena/ChangeLog
@@ -1,5 +1,12 @@
2009-05-14 Roland Levillain <roland(a)lrde.epita.fr>
+ Improve Swilena.
+
+ * int_u.ixx (__int__, __str__): New methods (extensions).
+ * python/dynamic-image2d-misc.py: Revive dead code.
+
+2009-05-14 Roland Levillain <roland(a)lrde.epita.fr>
+
Revive Swilena (again).
* box2d.i, dpoint2d.i, dynamic_image2d.i, fill.ixx, image2d.ixx,
diff --git a/swilena/int_u.ixx b/swilena/int_u.ixx
index 0926122..cb9c29d 100644
--- a/swilena/int_u.ixx
+++ b/swilena/int_u.ixx
@@ -111,3 +111,28 @@ namespace mln
} // end of namespace mln::value
} // end of namespace mln
+
+// Helper for the conversion to int.
+%extend mln::value::int_u
+{
+ int __int__() const { return *$self; }
+}
+
+// Helper for the conversion to string.
+%{
+#include <cstring>
+#include <string>
+#include <sstream>
+%}
+
+%extend mln::value::int_u
+{
+ 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());
+ }
+}
diff --git a/swilena/python/dynamic-image2d-misc.py
b/swilena/python/dynamic-image2d-misc.py
index ffcb709..f6b73b3 100644
--- a/swilena/python/dynamic-image2d-misc.py
+++ b/swilena/python/dynamic-image2d-misc.py
@@ -79,6 +79,6 @@ 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 r in range(0, 10):
+ for c in range(0, 10):
+ print ima(point2d(r, c))
--
1.6.1.2
Show replies by date