pysequence.cpp
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045 #include "util_common.h"
00046 #include "pysequence.h"
00047 #include "pyobject_macros.h"
00048
00049 namespace lass
00050 {
00051 namespace python
00052 {
00053 namespace impl
00054 {
00055 PY_DECLARE_CLASS( PySequence )
00056
00057
00058
00059 PY_CLASS_METHOD( PySequence, append )
00060 PY_CLASS_METHOD( PySequence, pop )
00061 PY_CLASS_METHOD( PySequence, clear )
00062 PY_CLASS_METHOD( PySequence, reserve )
00063
00064 PySequenceMethods PySequence::pySequenceMethods = {
00065 (lenfunc)PySequence_Length,
00066 (binaryfunc)PySequence_Concat,
00067 (ssizeargfunc)PySequence_Repeat,
00068 (ssizeargfunc)PySequence_Item,
00069 (ssizessizeargfunc)PySequence_Slice,
00070 (ssizeobjargproc)PySequence_AssItem,
00071 (ssizessizeobjargproc)PySequence_AssSlice,
00072 (objobjproc)PySequence_Contains,
00073 (binaryfunc)PySequence_InplaceConcat,
00074 (ssizeargfunc)PySequence_InplaceRepeat,
00075 };
00076
00077 bool PySequence::isInitialized = false;
00078
00079
00080
00081
00082
00083
00084
00085
00086
00087
00088
00089
00090
00091 PySequence::~PySequence()
00092 {
00093 delete pimpl_;
00094 }
00095 void PySequence::initialize()
00096 {
00097 if (!isInitialized)
00098 {
00099
00100 PySequence::_lassPyType.tp_as_sequence= &pySequenceMethods;
00101 #ifdef LASS_PYTHON_INHERITANCE_FROM_EMBEDDING
00102
00103
00104 PySequence::_lassPyType.tp_dictoffset = 0;
00105 PySequence::_lassPyType.tp_flags &= ~Py_TPFLAGS_BASETYPE;
00106 #endif
00107 finalizePyType( PySequence::_lassPyType, *PySequence::_lassPyGetParentType(),
00108 PySequence::_lassPyMethods, PySequence::_lassPyGetSetters,
00109 PySequence::_lassPyStatics, NULL, NULL);
00110 LASS_ENFORCE( PyType_Ready( &_lassPyType ) >= 0 );
00111 isInitialized = true;
00112 }
00113 }
00114
00115 Py_ssize_t PySequence::PySequence_Length( PyObject* iPO)
00116 {
00117 return static_cast<PySequence*>(iPO)->pimpl_->PySequence_Length();
00118 }
00119 PyObject* PySequence::PySequence_Concat(PyObject *iPO, PyObject *bb)
00120 {
00121 return static_cast<PySequence*>(iPO)->pimpl_->PySequence_Concat(bb);
00122 }
00123 PyObject* PySequence::PySequence_Repeat(PyObject *iPO, Py_ssize_t n)
00124 {
00125 return static_cast<PySequence*>(iPO)->pimpl_->PySequence_Repeat(n);
00126 }
00127 PyObject* PySequence::PySequence_Item(PyObject*iPO, Py_ssize_t i)
00128 {
00129 return static_cast<PySequence*>(iPO)->pimpl_->PySequence_Item(i);
00130 }
00131 PyObject* PySequence::PySequence_Slice(PyObject *iPO, Py_ssize_t ilow, Py_ssize_t ihigh)
00132 {
00133 return static_cast<PySequence*>(iPO)->pimpl_->PySequence_Slice(ilow,ihigh);
00134 }
00135 int PySequence::PySequence_AssItem(PyObject *iPO, Py_ssize_t i, PyObject *v)
00136 {
00137 return static_cast<PySequence*>(iPO)->pimpl_->PySequence_AssItem(i,v);
00138 }
00139 int PySequence::PySequence_AssSlice(PyObject *iPO, Py_ssize_t ilow, Py_ssize_t ihigh, PyObject *v)
00140 {
00141 return static_cast<PySequence*>(iPO)->pimpl_->PySequence_AssSlice(ilow,ihigh,v);
00142 }
00143 int PySequence::PySequence_Contains(PyObject *iPO, PyObject *el)
00144 {
00145 return static_cast<PySequence*>(iPO)->pimpl_->PySequence_Contains(el);
00146 }
00147 PyObject * PySequence::PySequence_InplaceConcat(PyObject *iPO, PyObject *other)
00148 {
00149 int r = static_cast<PySequence*>(iPO)->pimpl_->PySequence_InplaceConcat(other);
00150 if (r)
00151 return NULL;
00152 Py_INCREF(iPO);
00153 return iPO;
00154 }
00155 PyObject * PySequence::PySequence_InplaceRepeat(PyObject *iPO, Py_ssize_t n)
00156 {
00157 int r = static_cast<PySequence*>(iPO)->pimpl_->PySequence_InplaceRepeat(n);
00158 if (r)
00159 return NULL;
00160 Py_INCREF(iPO);
00161 return iPO;
00162 }
00163 }
00164
00165 }
00166
00167 }
00168