21 May 2012 20:37
Re: Fwd: Updates on Template with nested structure
William S Fulton <wsf <at> fultondesigns.co.uk>
2012-05-21 18:37:31 GMT
2012-05-21 18:37:31 GMT
Using fully qualified types usually works better. The following modified
interface file works for me (Mycustomlist deriving from MyArray):
%module example
%{
#include "MyArray.h"
%}
//%include "SWIG/Lib/csharp/typemaps.i"
%include "typemaps.i"
%include "MyArray.h"
// Note full qualification here
%template(CustomArray)
MyArray<AK::SoundEngine::DynamicDialogue::CustomItem,
AK::SoundEngine::DynamicDialogue::CustomItem const &>;
namespace AK
{
namespace SoundEngine
{
namespace DynamicDialogue
{
%template(MyCustomlist) CustomList<CustomItem, CustomItem const &>;
}
}
}
William
On 18/05/12 23:16, Build Master wrote:
> Forgot to reply to the list instead of the user that answered my question.
>
> ---------- Forwarded message ----------
> From: *Build Master* <akbuildmaster <at> gmail.com
> <mailto:akbuildmaster <at> gmail.com>>
> Date: Fri, May 18, 2012 at 5:31 PM
> Subject: Re: [Swig-user] Updates on Template with nested structure
> To: David Piepgrass <dpiepgrass <at> mentoreng.com
> <mailto:dpiepgrass <at> mentoreng.com>>
>
>
> I attached an example.
>
> Say on Windows,
> put the two files under same folder, e.g., "C:\MyTest"
>
> and assume SWIG folder is at "C:\MyTest\SWIG"
>
> Run this command:
>
> SWIG\swig.exe -oMyWrapper_wrap.cxx -c++ -csharp hello_template.swig
>
> You will see the errors that I posted.
>
> If you comment out all the namespaces in both the .swig file and .h file,
> the example works perfectly.
>
> K
>
>
>
> On Fri, May 18, 2012 at 4:56 PM, David Piepgrass
> <dpiepgrass <at> mentoreng.com <mailto:dpiepgrass <at> mentoreng.com>> wrote:
>
> What namespace is MyArray in? Try qualifying with that namespace (or
> ::MyArray if no namespace). Also, I noticed the args were
> “aCustomType const &” in one place and “const aCustomType &” in
> another... better make it the same in both places, just in case.____
>
> ____
>
> If you need further help, I suggest you reduce the problem to a
> simple, complete, compilable example that exhibits the problem.____
>
> __ __
>
> *From:*Build Master [mailto:akbuildmaster <at> gmail.com
> <mailto:akbuildmaster <at> gmail.com>]
> *Sent:* Friday, May 18, 2012 2:44 PM
> *To:* swig-user <at> lists.sourceforge.net
> <mailto:swig-user <at> lists.sourceforge.net>
> *Subject:* [Swig-user] Updates on Template with nested structure____
>
> __ __
>
> Hello,
>
> Here is an update about my earlier post today (see below the original)
> I've narrowed down the problem.
> My original problem was that the generated C# subclass
> CustomList turned out to be inherited from IDisposal (default)
> instead of its true parent MyArray.
>
> I found that this has nothing to do with the nested Iterator struct,
> but with the fact that
> the C++ class CustomList was defined in nested namespaces like this
>
> namespace Name1
> {
> namespace Name2
> {
> class CustomList : public MyArray<aCustomType, const
> aCustomType&, anotherCustomType, 4>
> {
> ....
> }
> }
>
> }
>
> With the namespace, I got these errors
> > 1>HeaderBlob.h(3397) : Warning 401: Nothing known about base class
> > 'MyArray< aCustomType, aCustomType const &, anotherCustomType, 4 >'.
> > Ignored.
> > 1>HeaderBlob.h(3397) : Warning 401: Maybe you forgot to instantiate
> > 'MyArray< aCustomType, aCustomType const &, anotherCustomType,4 >'
> > using %template.
> >
>
> Even after defined this class with namespaces in my SWIG interface
> like this:
> namespace AK
> {
> namespace SoundEngine
> {
> namespace DynamicDialogue
> {
> %template(AkPlaylist) Playlist<PlaylistItem,
> PlaylistItem const &, ArrayPoolDefault, 4>;
> }
> }
> }
>
> I still got the same errors.
>
> Any help would be appreciated.
>
> K
>
>
> ======================
> Original question
> ======================
> Hello,
>
> I'm generating C# bindings for C++ that need to expose templates.
> Now I'm having errors related to nested structures in template class.
>
> I read from SWIG doc that SWIG has only limited support to nested
> structures.
> I now have to expose a template class that contains a nest struct,
> something looking like this
>
> // MyArray.h
> template <class T, class T1, class T2, unsigned long P> class MyArray {
> public:
>
> MyArray() ....{}
>
> struct Iterator
> {
> T* pItem;
> Iterator& operator++() { ... }
> Iterator& operator--() { ... }
> .....
> }
>
> Iterator Begin() const { ... }
> Iterator End() const { ... }
>
> ...
> }
>
>
> Then in my interface I have this statement based on this class:
>
> > %include <MyArray.h>
> > %template(CustomArray) MyArray<aCustomType, aCustomType const &,
> > anotherCustomType, 4>;
> >
> > %include <HeaderBlob.h>
> >
>
> In HeaderBlob.h, I have classes that looks like:
>
> > class CustomList : public MyArray<aCustomType, const aCustomType&,
> > anotherCustomType, 4>
> >
>
>
> When using SWIG to generate bindings, I'm getting these errors:
>
> 1>MyArray.h(84) : Warning 325: Nested struct not currently supported
> > (Iterator ignored)
> > 1>HeaderBlob.h(3397) : Warning 401: Nothing known about base class
> > 'MyArray< aCustomType, aCustomType const &, anotherCustomType, 4 >'.
> > Ignored.
> > 1>HeaderBlob.h(3397) : Warning 401: Maybe you forgot to instantiate
> > 'MyArray< aCustomType, aCustomType const &, anotherCustomType,4 >'
> > using %template.
> >
>
> SWIG generates CustomList, aCustomType C# class and CustomArray C#
> class that have no connections.
>
> Also two orphan types are generated
>
> >
> >
> SWIGTYPE_p_MyArrayT_aCustomType_aCustomType_const_R_anotherCustomeType
> > _4_t__Iteratorcs
> > SWIGTYPE_p_aCustomType.cs
> >
>
> I wonder if this is due to the nested Iterator struct, or the fact
> that I'm missing some required typemaps or other SWIG constructs??
>
> Regards,
> K____
>
>
>
>
>
> ------------------------------------------------------------------------------
> Live Security Virtual Conference
> Exclusive live event will cover all the ways today's security and
> threat landscape has changed and how IT managers can respond. Discussions
> will include endpoint security, mobile security and the latest in malware
> threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
>
>
>
> _______________________________________________
> Swig-user mailing list
> Swig-user <at> lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/swig-user
------------------------------------------------------------------------------
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and
threat landscape has changed and how IT managers can respond. Discussions
will include endpoint security, mobile security and the latest in malware
threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
RSS Feed