* 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
Show replies by date