From: Macumber, D. <Dan...@nr...> - 2013-12-21 05:24:04
|
Thank you William! This is almost certainly what I am looking for. However, now I am stuck on another problem! I have another module (IDD) that imports my path class. Previously (including with my in and freearg typemaps) the IDD module had this line in it: #define SWIGTYPE_p_openstudio__path swig_types[66] The typemap declarations were: %typemap(in) const path& { // stuff including use of SWIGTYPE_p_openstudio__path } %typemap(freearg) const path& { //stuff } When I add the following code, the #define SWIGTYPE_p_openstudio__path swig_types is no longer written to my IDD module wrapper and my wrapper code does not compile: %typecheck(SWIG_TYPECHECK_STRING) const path& { bool stringType = (TYPE($input) == T_STRING); bool pathType = false; if (!stringType){ void *vptr = 0; int res = SWIG_ConvertPtr($input, &vptr, SWIGTYPE_p_openstudio__path, 0); pathType = (SWIG_IsOK(res) && (vptr != 0)); } $1 = (stringType || pathType) ? 1 : 0; } What is really weird is that if I change '%typecheck(SWIG_TYPECHECK_STRING) const path&' to '%typecheck(SWIG_TYPECHECK_STRING) const path', the SWIGTYPE_p_openstudio__path variable is once again defined in the IDD module. I have tried running with --debug-classes and --debug-typemaps and the path variable shows up in all cases, including the typecheck typemap. This leads me to believe SWIG is parsing the variable type but failing to write it out for some reason? Do you know what is going wrong when I use '%typecheck(SWIG_TYPECHECK_STRING) const path&'? Why does this cause SWIGTYPE_p_openstudio__path to not be generated in my wrapper? Thanks so much! Dan -----Original Message----- From: William Fulton [mailto:wi...@fu...] On Behalf Of William S Fulton Sent: Thursday, December 19, 2013 11:41 AM To: Macumber, Daniel Cc: swi...@li... Subject: Re: [Swig-user] Implicit conversion in Ruby? On 17/12/13 03:50, Macumber, Daniel wrote: > Thanks everyone for the help so far. However, now I am hitting something that looks even worse. I was able to use an in typemap to convert a String in Ruby into my Path class. This works great for methods that take a single Path argument. However, I am having trouble with this function: > > bool save(const openstudio::path& p, bool overwrite=false); > > SWIG generates three methods (typemap and generated code is below). The first is wrap_Workspace_save__SWIG_0(int argc, VALUE *argv, VALUE self) and seems to handle the case with two arguments, my Path typemap code is applied correctly here. The second method is _wrap_Workspace_save__SWIG_1(int argc, VALUE *argv, VALUE self) and seems to handle the case with one argument, my Path typemap code is applied correctly here. The final method is _wrap_Workspace_save(int nargs, VALUE *args, VALUE self) and seems to choose which of the previous methods to call. However, my typemap code is NOT applied in _wrap_Workspace_save(int nargs, VALUE *args, VALUE self), it simply fails when it cannot convert the first argument from a String to a Path. If it had just passed the argument through, _wrap_Workspace_save__SWIG_0 would have correctly mapped the String to a Path. I am using SWIG 2.0.10 on Windows. Does anyone have any ideas? You need to provide a typecheck typemap to take account of the method overloading. http://swig.org/Doc2.0/Typemaps.html#Typemaps_overloading http://swig.org/Doc2.0/Ruby.html#Ruby_typecheck_typemap William |