Commit b5853d4e authored by Roland Levillain's avatar Roland Levillain
Browse files

Simplify the construction of dyn.data objects in SWIG wrappers.

	* swig/dyn.i (make_data_by_cpy): Remove inlined wrapper.
	(generate_data_ctor)
	(generate_data_ctor_val)
	(generate_data_ctor_ref):
	New macros.
	Use them to generate dyn::data ctors using a proxy-by-value for
	`int' and `std::string'.
	* swig/python/milena.py: Adjust: use dyn.data directly instead of
	helpers dyn.integer and dyn.string.

git-svn-id: https://svn.lrde.epita.fr/svn/oln/trunk@4693 4aad255d-cdde-0310-9447-f3009e2ae8c0
parent 39cb96ef
2009-10-30 Roland Levillain <roland@lrde.epita.fr>
Simplify the construction of dyn.data objects in SWIG wrappers.
* swig/dyn.i (make_data_by_cpy): Remove inlined wrapper.
(generate_data_ctor)
(generate_data_ctor_val)
(generate_data_ctor_ref):
New macros.
Use them to generate dyn::data ctors using a proxy-by-value for
`int' and `std::string'.
* swig/python/milena.py: Adjust: use dyn.data directly instead of
helpers dyn.integer and dyn.string.
2009-10-29 Roland Levillain <roland@lrde.epita.fr>
Fix issues w.r.t. MacPorts' libiberty to have Python bindings work.
......
......@@ -35,7 +35,7 @@
#include "dyn-all.hh"
%}
// Ignore global objects causing trouble.
// Ignore global objects causing trouble to swig.
%ignore dyn::logger;
%ignore dyn::internal::operator_push;
%ignore dyn::internal::operator_pop;
......@@ -49,29 +49,48 @@
%include "dyn-all.hh";
%inline %{
/* The natural, single-argument ctors of dyn::data manipulate the
encapulsated by reference, which is wrong when these data are of
builtin types of the target language (e.g., Pythons' `int's),
because we have no control on them and they can vanish at any
moment.
/*---------------.
| Construction. |
`---------------*/
/* The natural, single-argument ctors of dyn::data manipulate the
encapsulated member by reference, which is wrong when these data
are of builtin types of the target language (e.g., Pythons'
`int's), because we have no control on them and they can vanish at
any moment.
To prevent this, provide construction helpers creating dyn::data
objects manipulating data by value (copy). */
template <typename T>
dyn::data make_data_by_cpy(T i)
To prevent this, provide constructors helpers creating dyn::data
objects manipulating data by value (copy). */
%define generate_data_ctor(Arg, Type)
%extend dyn::data
{
data(Arg v)
{
dyn::proxy_tag* dummy = 0;
// This dummy pointer passed as second argument is required to
// call the right ctor.
dyn::data d(new dyn::data_proxy_by_cpy<T>(i), dummy);
return d;
return new dyn::data(new dyn::data_proxy_by_cpy< Type >(v), dummy);
}
%}
}
%enddef // !generate_data_ctor
// Shortcut to generate a ctor taking its argument by value (copy).
%define generate_data_ctor_val(Type)
generate_data_ctor(Type, Type)
%enddef
// Shortcut to generate a ctor taking its argument by (const) reference.
%define generate_data_ctor_ref(Type)
generate_data_ctor(const Type &, Type)
%enddef
// Generate dyn::data ctors using a proxy-by-value for classic types.
generate_data_ctor_val(int)
generate_data_ctor_ref(std::string)
// Instantiate make_data_by_cpy ctors for some types.
%template(integer) make_data_by_cpy<int>;
%template(string) make_data_by_cpy<std::string>;
/*--------------.
| Conversions. |
`--------------*/
// Instantiate dyn::data explicit conversion routines for some types.
%extend dyn::data
......
......@@ -41,11 +41,11 @@ println = dyn.fun("mln::debug::println")
#
# but we just can't. `mk_image2d_int' only accept `dyn.data' as
# arguments, so we have to encapsulate integers in `dyn.data' objects
# using `dyn.integer' (likewise for strings with `dyn.string').
# (likewise for strings).
ima = mk_image2d_int(dyn.integer(3), dyn.integer(3))
ima = mk_image2d_int(dyn.data(3), dyn.data(3))
fill(ima, dyn.integer(0))
println(dyn.string("ima (before) ="), ima)
fill(ima, dyn.data(0))
println(dyn.data("ima (before) ="), ima)
iota(ima)
println(dyn.string("ima (after) ="), ima)
println(dyn.data("ima (after) ="), ima)
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment