From: SourceForge.net <no...@so...> - 2009-01-13 16:17:49
|
Bugs item #2502006, was opened at 2009-01-12 11:02 Message generated for change (Comment added) made by qwertie You can respond by visiting: https://sourceforge.net/tracker/?func=detail&atid=101645&aid=2502006&group_id=1645 Please note that this message will contain a full copy of the comment thread, including the initial issue submission, for this request, not just the latest update. Category: preprocessor Group: None Status: Open Resolution: None Priority: 5 Private: No Submitted By: James Masters (jamesm17) Assigned to: Nobody/Anonymous (nobody) Summary: Allow automatic %template injection when reading header file Initial Comment: Currently %template declarations must be made *after* reading in header files. Additionally, %template declarations must be made *before* their usage as a base class. For example, to wrap the three classes below (ArrayBase<int>, Array<int>, IntArray) *with* proper inheritance, I would need the following %template declaration positioning: template <class T> class ArrayBase {}; template <class T> class Array : public ArrayBase<T> {}; %template("IArrayBase") ArrayBase<int>; %template("IArray") Array<int>; class IntArray : public Array<int> {}; Unfortunately, if the header files cannot be edited directly, then a copy of the header files is necessary and manual injection (or through a script) of %template is needed to conform with this precedence requirement (for details see: http://www.nabble.com/Is-there-a-workaround-to-use--template-after-reading-all-header-files--td20861858.html) A possible solution would be to somehow allow SWIG to inject %template into the header files automatically during preprocessing immediately after a template is defined - perhaps by some kind of SWIG interface macro pre-declaration before reading header files. ---------------------------------------------------------------------- Comment By: David Piepgrass (qwertie) Date: 2009-01-13 09:17 Message: I'd like to add one more nuance. If SWIG's developers add this feature (which would be nice because even if you are able to modify the original header files, it's weird putting SWIG directives in the middle of them) it is necessary to wait not just until the template itself is defined, but until the template arguments are also defined. For example: %template(FooOfBar) Foo< Bar<Baz> >; template<class T> class Foo { ... }; template<class T> class Bar { ... }; class Baz { ... }; SWIG shouldn't create FooOfBar until Foo, Bar and Baz are all defined. Most likely SWIG should simply wait until the template is needed before expanding it. For example if SWIG encounters Foo< Bar<Baz> > x; or class DerivedFoo : public Foo< Bar<Baz> > { ... }; that's when it should expand the template (and give a warning, maybe, if Bar and Baz are undefined). At the end of the master .i file if unexpanded templates are still pending, then they should be expanded. ---------------------------------------------------------------------- Comment By: David Piepgrass (qwertie) Date: 2009-01-12 14:21 Message: I agree with this suggestion. One of the difficulties for users using SWIG is getting declarations in the correct order. For example if you give SWIG this: Foo Bar() %typemap(out) Foo { ... } The typemap doesn't work, and SWIG offers no warning. It would be nice if users could be given a simple rule-of-thumb like: "always put SWIG directives ABOVE the types and functions to which they apply". In most cases this rule works, but in the case of %template it does not. ---------------------------------------------------------------------- You can respond by visiting: https://sourceforge.net/tracker/?func=detail&atid=101645&aid=2502006&group_id=1645 |