[PATCH 13/19] Factor some Swilena code using Python conversion helper generators.
* int_u.ixx, point2d.i: Here. --- swilena/ChangeLog | 6 ++++++ swilena/int_u.ixx | 30 ++++++++---------------------- swilena/point2d.i | 17 ++++++----------- 3 files changed, 20 insertions(+), 33 deletions(-) diff --git a/swilena/ChangeLog b/swilena/ChangeLog index 09b5aea..ee39aa4 100644 --- a/swilena/ChangeLog +++ b/swilena/ChangeLog @@ -31,6 +31,12 @@ 2009-05-26 Roland Levillain <roland@lrde.epita.fr> + Factor some Swilena code using Python conversion helper generators. + + * int_u.ixx, point2d.i: Here. + +2009-05-26 Roland Levillain <roland@lrde.epita.fr> + Add Python conversion helper generators to Swilena. * python-utils.ixx: New file. diff --git a/swilena/int_u.ixx b/swilena/int_u.ixx index 71fc02e..855898f 100644 --- a/swilena/int_u.ixx +++ b/swilena/int_u.ixx @@ -112,27 +112,13 @@ namespace mln } // 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> -%} +/*--------------------------------. +| Conversion helpers for Python. | +`--------------------------------*/ -%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()); - } -} +#if SWIGPYTHON +%include python-utils.ixx +generate__int__(mln::value::int_u) +generate__str__(mln::value::int_u) +#endif // !SWIGPYTHON diff --git a/swilena/point2d.i b/swilena/point2d.i index 0bf9142..a07fb50 100644 --- a/swilena/point2d.i +++ b/swilena/point2d.i @@ -90,16 +90,11 @@ int col() const { return $self->operator[](1); } } -%extend mln::point< mln::grid::square, mln::def::coord > -{ - 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()); - } -} +// Conversion helper for Python. +#if SWIGPYTHON +%include concat.ixx +%include python-utils.ixx +generate__str__(concat2(mln::point< mln::grid::square,mln::def::coord >)) +#endif // !SWIGPYTHON %template(point2d) mln::point<mln::grid::square, mln::def::coord>; -- 1.6.1.2
participants (1)
-
Roland Levillain