Re: Typemaps for constructors?
William S Fulton <[email protected]>
| Newsgroups | gmane.comp.programming.swig |
|---|---|
| Message-ID | <CANGqftDgGpUjSdEC4-04MnPAfir+n9jFNVCi-FXw2No5bemTWg@mail.gmail.com> |
Hi Christina I don't know how you have defined TENA::Middleware::SessionPtr, so it is hard to say. I suspect SWIG is having the same problem getting it right if you have not given the full definition to SWIG. If SWIG sees that a type does not have a default constructor, SWIG should not generate code that requires one. As you seem to have templates in your code, make sure you have the appropriate %template directives to provide the full type information. If you provide a cutdown standalone example with the problem, we can probably diagnose what is happening. William On Fri, 24 Jul 2020 at 21:20, Christina Noe via Swig-user < [email protected]> wrote: > Hi all, > > > > I’m trying to create C# wrappers for a C++ toolkit I’m developing. This > toolkit references some data types from a third-party middleware. I’m > trying to avoid wrapping any part of the middleware. I’ve been able to > accomplish this to some extent by referencing existing swig-generated C# > wrappers available for the middleware. For example, for a C++ type called > TENA::Middleware::SessionPtr, I have been able to use a typemap like the > following to construct a C# TENA.Middleware.Session object using a pointer > to the object constructed in C++: > > > > > > %typemap(csout, excode=SWIGEXCODE) TYPE*, TYPE&, TYPE { > > IntPtr ptr = $imcall;$excode > > TENA.Middleware.Session ret = new TENA.Middleware.Session(ptr, > true); > > return ret; > > } > > > > However, I’m having issues doing the same for data types that do not > provide a default constructor. For example, regarding a type called > TENA::PlatformType::LocalClassPtr, functions in the generated C++ wrapper > that try to initialize a TENA:: PlatformType::LocalClassPtr object > experience the following error: > > > > > > > > I can fix this error by altering the generated C++ code so that arg2 > initializes using a different constructor (such as “TENA::PlatformType:: > LocalClassPtr arg2 = TENA::PlatformType::create(0);"), but I want to use > a typemap so that SWIG generates code using this constructor automatically. > Is there a typemap that can do this? Also, has anyone attempted to generate > wrappers that reference other swig-generated wrappers? If so, I would > greatly appreciate any thoughts on feasibility and best practices. > > > > Thanks! > Christina Noe > _______________________________________________ > Swig-user mailing list > [email protected] > https://lists.sourceforge.net/lists/listinfo/swig-user > _______________________________________________ Swig-user mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/swig-user
image003.jpg
(image/jpeg, 31.1 KB) - not displayed