/** * pointer.i * * Generic pointer typemap for MgObject-derived classes (ie. Everything in the MapGuide API) */ /////////////////////////////////////////////////////////// // Custom generic pointer typemaps. This overrides the default // typemap to support downcasting and/or hooking into our refcounting // diagnostics // // Default typemap is to try for the most-derived type // // TODO: We can avoid the most-derived type check if we know SWIGTYPE to not // be an abstract class. Is there a SWIG-typemap-level way to check for this? %typemap(out) SWIGTYPE* { swig_type_info* ty = NULL; if ($1) // Try to resolve most-derived type through its class id { const char* retClassName = ResolveMgClassName(static_cast($1)->GetClassId()); if (NULL != retClassName) { ty = SWIG_TypeQuery(retClassName); } } if (NULL == ty) //Fallback to original descriptor { ty = $1_descriptor; } SWIG_SetPointerZval($result, (void *)$1, ty, 1); /* owner = $owner */ if ($owner) // is owner? NewObjectHook($1); else RefCountHook($1); } // But for certain return types, we want to preserve its base-type-ness, otherwise // we can't pass said instances as arguments to methods that are expecting that base // type (because the PHP type checking in the SWIG wrapper is by exact type and isn't // aware of inheritance, so you can't pass a MgCoordinateXY to an argument expecting // MgCoordinate for example). Also said types are "pure abstract" and the consumer will // almost never need downcast to the most-derived type. // // For now, MgCoordinate is such a return type %typemap(out) MgCoordinate* { swig_type_info* ty = $1_descriptor; SWIG_SetPointerZval($result, (void *)$1, ty, 1); /* owner = $owner */ if ($owner) // is owner? NewObjectHook($1); else RefCountHook($1); }