Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Class Members | File Members | Related Pages

vector.sip

Go to the documentation of this file.
00001 /* -*- mode:c++ -*- */
00002 
00016 %MappedType std::vector<double>
00017 {
00018 %TypeHeaderCode
00019 #include <vector>
00020 %End
00021 
00022 %ConvertFromTypeCode
00023         // Handle no list.
00024 
00025         if (!sipCpp)
00026                 return PyList_New(0);
00027 
00028         // Convert to a Python list of doubles
00029 
00030         PyObject *l;
00031 
00032         // Create the list.
00033         int size = static_cast < int > ( sipCpp -> size () );
00034         if ( ( l = PyList_New ( size ) ) == NULL)
00035                 return NULL;
00036 
00037         // Get it.
00038 
00039         for ( unsigned int i = 0; i < sipCpp -> size(); ++i)
00040           if (PyList_SetItem(l,i,PyFloat_FromDouble((double)(*sipCpp)[i])) < 0)
00041                 {
00042                         Py_DECREF(l);
00043 
00044                         return NULL;
00045                 }
00046 
00047         return l;
00048 %End
00049 
00050 %ConvertToTypeCode
00051         // Convert a Python list of double to a vector<double> on the heap.
00052  
00053         if (sipIsErr == NULL)
00054                 return PyList_Check(sipPy);
00055 
00056         if (sipPy == Py_None)
00057         {
00058                 *sipCppPtr = NULL;
00059 
00060                 return 0;
00061         }
00062         int size = PyList_GET_SIZE(sipPy);      
00063         vector<double> *qvl = new vector<double> ( size );
00064         PyErr_Clear();
00065 
00066         for (int i = 0; i < size; ++i)
00067         {
00068           qvl -> operator [] (i) 
00069                = ((double)PyFloat_AsDouble(PyList_GET_ITEM(sipPy,i)));
00070  
00071                 if (PyErr_Occurred() != NULL)
00072                 {
00073                         delete qvl;
00074                         *sipIsErr = 1;
00075 
00076                         return 0;
00077                 }
00078         }
00079  
00080         *sipCppPtr = qvl;
00081  
00082         return 1;
00083 %End
00084 };
00085 
00086 %MappedType std::vector<bool>
00087 {
00088 %TypeHeaderCode
00089 #include <vector>
00090 %End
00091 
00092 %ConvertFromTypeCode
00093         // Handle no list.
00094 
00095         if (!sipCpp)
00096                 return PyList_New(0);
00097 
00098         // Convert to a Python list of ints
00099 
00100         PyObject *l;
00101 
00102         // Create the list.
00103         int size = static_cast < int > ( sipCpp -> size () );
00104         if ( ( l = PyList_New ( size ) ) == NULL)
00105                 return NULL;
00106 
00107         // Get it.
00108 
00109         for ( unsigned int i = 0; i < sipCpp -> size(); ++i) {
00110           bool yes = sipCpp -> operator [] ( i );
00111           long j = yes ? 1 : 0;
00112           if ( PyList_SetItem ( l, i, PyInt_FromLong ( j ) ) < 0 )
00113                 {
00114                         Py_DECREF(l);
00115 
00116                         return NULL;
00117                 }
00118         }
00119         return l;
00120 %End
00121 
00122 %ConvertToTypeCode
00123         // Convert a Python list of double to a vector<double> on the heap.
00124  
00125         if (sipIsErr == NULL)
00126                 return PyList_Check(sipPy);
00127 
00128         if (sipPy == Py_None)
00129         {
00130                 *sipCppPtr = NULL;
00131 
00132                 return 0;
00133         }
00134         int size = PyList_GET_SIZE(sipPy);      
00135         vector < bool> *qvl = new vector < bool > ( size );
00136         PyErr_Clear();
00137 
00138         for (int i = 0; i < size; ++i)
00139         {
00140           long j = ((long)PyInt_AsLong(PyList_GET_ITEM(sipPy,i)));
00141  
00142                 if (PyErr_Occurred() != NULL)
00143                 {
00144                         delete qvl;
00145                         *sipIsErr = 1;
00146 
00147                         return 0;
00148                 }
00149           qvl -> operator [] (i) = ( j == 0 ) ? false : true;
00150         }
00151  
00152         *sipCppPtr = qvl;
00153  
00154         return 1;
00155 %End
00156 };
00157 
00158 %MappedType std::vector<int>
00159 {
00160 %TypeHeaderCode
00161 #include <vector>
00162 %End
00163 
00164 %ConvertFromTypeCode
00165         // Handle no list.
00166 
00167         if (!sipCpp)
00168                 return PyList_New(0);
00169 
00170         // Convert to a Python list of ints
00171 
00172         PyObject *l;
00173 
00174         // Create the list.
00175         int size = static_cast < int > ( sipCpp -> size () );
00176         if ( ( l = PyList_New ( size ) ) == NULL)
00177                 return NULL;
00178 
00179         // Get it.
00180 
00181         for ( unsigned int i = 0; i < sipCpp -> size(); ++i) {
00182           long j = sipCpp -> operator [] ( i );
00183           if ( PyList_SetItem ( l, i, PyInt_FromLong ( j ) ) < 0 )
00184                 {
00185                         Py_DECREF(l);
00186 
00187                         return NULL;
00188                 }
00189         }
00190         return l;
00191 %End
00192 
00193 %ConvertToTypeCode
00194         // Convert a Python list of int to a vector<int> on the heap.
00195  
00196         if (sipIsErr == NULL)
00197                 return PyList_Check(sipPy);
00198 
00199         if (sipPy == Py_None)
00200         {
00201                 *sipCppPtr = NULL;
00202 
00203                 return 0;
00204         }
00205         int size = PyList_GET_SIZE(sipPy);      
00206         vector < int> *qvl = new vector < int > ( size );
00207         PyErr_Clear();
00208 
00209         for (int i = 0; i < size; ++i)
00210         {
00211           long j = ((long)PyInt_AsLong(PyList_GET_ITEM(sipPy,i)));
00212  
00213                 if (PyErr_Occurred() != NULL)
00214                 {
00215                         delete qvl;
00216                         *sipIsErr = 1;
00217 
00218                         return 0;
00219                 }
00220                 qvl -> operator [] (i) = j;
00221         }
00222  
00223         *sipCppPtr = qvl;
00224  
00225         return 1;
00226 %End
00227 };
00228 
00229 %MappedType std::vector<std::string>
00230 {
00231 %TypeHeaderCode
00232 #include <string>
00233 #include <vector>
00234 
00235 using std::string;
00236 using std::vector;
00237 %End
00238 
00239 %ConvertFromTypeCode
00240         // Handle no list.
00241 
00242         if (!sipCpp)
00243                 return PyList_New(0);
00244 
00245         // Convert to a Python list of doubles
00246 
00247         PyObject *l;
00248 
00249         // Create the list.
00250         int size = static_cast < int > ( sipCpp -> size () );
00251         if ( ( l = PyList_New( size ) ) == NULL )
00252                 return NULL;
00253 
00254         // Get it.
00255 
00256         for ( unsigned int i = 0; i < sipCpp -> size(); ++i)
00257           if (PyList_SetItem(l, i,
00258                   PyString_FromString( (*sipCpp)[i].c_str())) < 0)
00259                 {
00260                         Py_DECREF(l);
00261 
00262                         return NULL;
00263                 }
00264 
00265         return l;
00266 %End
00267 
00268 %ConvertToTypeCode
00269         // Convert a Python list of string to a vector<string> on the heap.
00270  
00271         if (sipIsErr == NULL)
00272                 return PyList_Check(sipPy);
00273 
00274         if (sipPy == Py_None)
00275         {
00276                 *sipCppPtr = NULL;
00277 
00278                 return 0;
00279         }
00280 
00281         vector<string> *qvl = new vector<string>;
00282         PyErr_Clear();
00283 
00284         for (int i = 0; i < PyList_GET_SIZE(sipPy); ++i)
00285         {
00286           qvl -> push_back( PyString_AsString(PyList_GET_ITEM(sipPy,i)));
00287  
00288                 if (PyErr_Occurred() != NULL)
00289                 {
00290                         delete qvl;
00291                         *sipIsErr = 1;
00292 
00293                         return 0;
00294                 }
00295         }
00296  
00297         *sipCppPtr = qvl;
00298  
00299         return 1;
00300 %End
00301 };

Generated on Wed Sep 7 14:51:29 2005 for SiHippo by  doxygen 1.4.3