Re: Re: Replacements in SWIG?
Michael Terry <mterry <at> gmail.com>
2005-03-01 15:31:27 GMT
Hi all -
Thanks for the suggestions on typemaps. While I think I could get
close to my goal, from what I can understand, the issue with typemaps
is that they are essentially a language-dependent solution that
requires marshalling code to be written.
It would be much more elegant if I could define the desired class in
C++, have SWIG systematically perform a replacement of the old type
with the new type (the new class defined in C++), then have it
generate wrappers in the target language for the C++ class. This way,
I can define the desired/necessary functionality once (in the C++
class), and the benefits translate to any target language.
Granted, my specific needs (wrapping a char* in a C++ class that
interprets that char* as a pointer to pixel data) may be
idiosyncratic, but I can imagine other cases where it would be helpful
to wrap generic pointers with C++ classes that perform domain-specific
functions on the data. Again, the advantage is that one can specify
all functionality associated with that pointer type in one spot, then
SWIG can wrap the C++ class for the target language, avoiding the
I have actually written a C-to-C module for SWIG that performs this
intermediate step, and the resulting API in the target language is
much cleaner. Also, the interface files for SWIG (the .i files) are
relatively sparse and clean, with no language-specific marshalling.
One of the caveats of this approach right now is that it requires two
passes by SWIG -- one to create the intermediate C code (where
specific pointer types are replaced with classes), and the other to