/* Copyright (C) 2005 Reed Hedges, Hugh Perkins This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ // Lets you pass VUtil::vRef< classname > into a function instead of classname * // Instantiate for each class, eg: // vrefinput( MyClass ); %define vrefinput( ClassName ) %typemap( python, in ) ClassName *{ // cout << "typemap ClassName *" << endl; VUtil::vRef * argp; if( SWIG_Python_ConvertPtr($input, (void **)&argp, $descriptor( VUtil::vRef< ClassName >* ), 0) != -1 ) { $1 = *argp; } else { SWIG_Python_ConvertPtr($input, (void **)&$1, $descriptor( ClassName * ), SWIG_POINTER_EXCEPTION | 0); if (SWIG_arg_fail(1)) { SWIG_fail; } } } %enddef // returns py_None instead of vRef if the vRef is an empty pointer // you can instantiate this for example by doing: // vrefnullablereturn( VOS::Message ) %define vrefnullablereturn( Classname ) %typemap(python,out) const VUtil::vRef< Classname > { if( $1.isValid() ) { VUtil::vRef * resultptr; resultptr = new VUtil::vRef((VUtil::vRef const &)($1)); $result = SWIG_NewPointerObj((void *)(resultptr), $descriptor( VUtil::vRef< Classname >*), 1); } else { Py_INCREF( Py_None ); $result = Py_None; } } %enddef /* Return Python lists from methods instead of iterators. */ // Put into %define by Hugh Perkins May 2005 %define vositeratortypemap( IteratorClass, ElementClass ) %typemap(python,out) IteratorClass { //std::cerr << "(IteratorClass typemap)\n"; //std::cerr << "(size=" << $1.size() << ")\n"; $result = PyList_New($1.size()); int i = 0; for(IteratorClass it = $1; it.hasMore(); it++) { PyObject *p = SWIG_NewPointerObj((*it), $descriptor(ElementClass*), 1); PyList_SetItem($result, i++, p); } } %enddef vositeratortypemap( VOS::RSSEIterator, VOS::RemoteSocketSiteExtension ); vositeratortypemap( VOS::PCRIterator, VOS::ParentChildRelation); vositeratortypemap( VOS::VobjectIterator, VOS::Vobject); /* replaced by vositeratortypemap usage above %typemap(python,out) VOS::PCRIterator { //std::cerr << "(PCRIterator typemap)\n"; //std::cerr << "(size=" << $1.size() << ")\n"; $result = PyList_New($1.size()); int i = 0; for(VOS::PCRIterator it = $1; it.hasMore(); it++) { PyObject *p = SWIG_NewPointerObj((*it), $descriptor(VOS::ParentChildRelation*), 0); PyList_SetItem($result, i++, p); } } %typemap(python,out) VOS::VobjectIterator { $result = PyList_New($1.size()); int i = 0; for(VOS::VobjectIterator it = $1; it.hasMore(); it++) { PyObject *p = SWIG_NewPointerObj((*it), $descriptor(VOS::Vobject*), 1); PyList_SetItem($result, i++, p); } } */ %typemap(python,out) VOS::StringIterator { $result = PyList_New($1.size()); int i = 0; for(VOS::StringIterator it = $1; it.hasMore(); it++) { PyObject *p = PyString_FromStringAndSize((*it).data(), (*it).size()); PyList_SetItem($result, i++, p); } } // Used to append arguments to the list of returned values // in Python // You'll need to instantiate this for each class you want to use in your .i file // eg: argoutfn( MyClassName ) // Note that %defines in Swig are multi-line: they end at the %enddef marker // Note: for this to work, operator= must work correctly for the class %define argoutfn( ClassName ) %typemap(argout) ClassName &{ PyObject *oArgToReturn, *oOldReturnValue, *o3; ClassName *preturnedblah = new ClassName; *preturnedblah = *$1; oArgToReturn = SWIG_NewPointerObj( preturnedblah, $1_descriptor, 1 ); if ((!$result) || ($result == Py_None)) { $result = oArgToReturn; } else { if (!PyTuple_Check($result)) { PyObject *oOldReturnValue = $result; $result = PyTuple_New(1); PyTuple_SetItem($result,0,oOldReturnValue); } o3 = PyTuple_New(1); PyTuple_SetItem(o3,0,oArgToReturn); oOldReturnValue = $result; $result = PySequence_Concat(oOldReturnValue,o3); Py_DECREF(oOldReturnValue); Py_DECREF(o3); } } %typemap(in,numinputs=0) ClassName &(ClassName temp ) { $1 = &temp; } %enddef %typemap(argout) double &{ PyObject *oArgToReturn, *oOldReturnValue, *o3; oArgToReturn = PyFloat_FromDouble( *$1 ); if ((!$result) || ($result == Py_None)) { $result = oArgToReturn; } else { if (!PyTuple_Check($result)) { PyObject *oOldReturnValue = $result; $result = PyTuple_New(1); PyTuple_SetItem($result,0,oOldReturnValue); } o3 = PyTuple_New(1); PyTuple_SetItem(o3,0,oArgToReturn); oOldReturnValue = $result; $result = PySequence_Concat(oOldReturnValue,o3); Py_DECREF(oOldReturnValue); Py_DECREF(o3); } } %typemap(in,numinputs=0) double &(double temp ) { $1 = &temp; } %typemap(argout) int &{ PyObject *oArgToReturn, *oOldReturnValue, *o3; oArgToReturn = PyInt_FromLong( *$1 ); if ((!$result) || ($result == Py_None)) { $result = oArgToReturn; } else { if (!PyTuple_Check($result)) { PyObject *oOldReturnValue = $result; $result = PyTuple_New(1); PyTuple_SetItem($result,0,oOldReturnValue); } o3 = PyTuple_New(1); PyTuple_SetItem(o3,0,oArgToReturn); oOldReturnValue = $result; $result = PySequence_Concat(oOldReturnValue,o3); Py_DECREF(oOldReturnValue); Py_DECREF(o3); } } %typemap(in,numinputs=0) int &(int temp ) { $1 = &temp; } %typemap(argout) bool &{ PyObject *oArgToReturn, *oOldReturnValue, *o3; oArgToReturn = PyInt_FromLong( (long)*$1 ); if ((!$result) || ($result == Py_None)) { $result = oArgToReturn; } else { if (!PyTuple_Check($result)) { PyObject *oOldReturnValue = $result; $result = PyTuple_New(1); PyTuple_SetItem($result,0,oOldReturnValue); } o3 = PyTuple_New(1); PyTuple_SetItem(o3,0,oArgToReturn); oOldReturnValue = $result; $result = PySequence_Concat(oOldReturnValue,o3); Py_DECREF(oOldReturnValue); Py_DECREF(o3); } } %typemap(in,numinputs=0) bool &(bool temp ) { $1 = &temp; } %typemap( python, in ) VOS::Vobject *{ // cout << "typemap VOS::Vobject *" << endl; VUtil::vRef * argp; VUtil::vRef * argpmetaobject; VUtil::vRef * argpproperty; if( SWIG_Python_ConvertPtr($input, (void **)&argp, $descriptor( VUtil::vRef< VOS::Vobject >* ), 0) != -1 ) { $1 = *argp; } else if( SWIG_Python_ConvertPtr($input, (void **)&argpmetaobject, $descriptor( VUtil::vRef< VOS::MetaObject >* ), 0) != -1 ) { $1 = *argpmetaobject; } else if( SWIG_Python_ConvertPtr($input, (void **)&argpproperty, $descriptor( VUtil::vRef< VOS::Property >* ), 0) != -1 ) { $1 = *argpproperty; } else { SWIG_Python_ConvertPtr($input, (void **)&$1, $descriptor( ClassName * ), SWIG_POINTER_EXCEPTION | 0); if (SWIG_arg_fail(1)) { SWIG_fail; } } }