Re: [pygccxml-development] Template constructors
Brought to you by:
mbaas,
roman_yakovenko
From: Roman Y. <rom...@gm...> - 2008-03-17 12:05:16
|
On Sun, Mar 16, 2008 at 11:08 PM, Matthias Baas <mat...@gm...> wrote: > Hi, Hello. Welcome back. > after being away from the "wrapping business" for quite a while I'm now > back and trying to wrap another library that is heavily template based. > As I'm starting from scratch, I'm now using the official module builder > instead of my own version. > So as a first general question, is there meanwhile some special support > for templates? Can I tell Py++ what template arguments to use and it > takes care of instantiating it? > I'm assuming that's not (yet) the case, so I was instantiating the stuff > myself. > But I ran into a problem with a template constructor inside a template > class. I could only wrap the non-template constructors whereas the other > ones don't seem to be reported by gccxml. > Here is an example: > > ///////////////////// File: header.h > template<class T> > class Spam > { > T x; > T y; > public: > > Spam() : x(0),y(0) {} > template<class V> > Spam(V a, V b) : x(a),y(b) {} > }; > > // Instantiate the template > inline void dummy() > { > Spam<double> c0(1, 2); > } > > ####################### File: generate.py > > from pyplusplus.module_builder import module_builder_t > > mb = module_builder_t(files = ['header.h']) > > spam = mb.class_("Spam<double>") > spam.include() > > # Print all declarations that are available on the class > decls = spam.decls() > for decl in decls: > print decl > > mb.build_code_creator(module_name="spammod") > mb.split_module(dir_name="bindings") > > > When I run the Python script, the declarations that get printed are the > following: > > Spam<double>::Spam(Spam<double> const & arg0) [copy constructor] > Spam<double>::Spam() [constructor] > Spam<double>::x [variable] > Spam<double>::y [variable] > > I would also have expected a constructor that takes two ints, but it > isn't there and so it isn't wrapped. Is there another way to instantiate > the class that would make the constructor visible? Matthias unfortunately the problem is on the GCCXML side I don't see any work around to the problem :-(. It seems that template constructors of template class is a special case, that GCCXML could\does not treat. I think the best solution in this case is to add "constructor declaration" to the classes. -- Roman Yakovenko C++ Python language binding http://www.language-binding.net/ |