pymap.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 "pymap.h"
00047 #include "pyobject_macros.h"
00048
00049 namespace lass
00050 {
00051 namespace python
00052 {
00053 namespace impl
00054 {
00055 PY_DECLARE_CLASS( PyMap )
00056 PY_CLASS_METHOD( PyMap, keys )
00057 PY_CLASS_METHOD( PyMap, values )
00058
00059 bool PyMap::isInitialized = false;
00060
00061 PyMappingMethods PyMap::pyMappingMethods = {
00062 (lenfunc)PyMap::PyMap_Length,
00063 (binaryfunc)PyMap::PyMap_Subscript,
00064 (objobjargproc)PyMap::PyMap_AssSubscript,
00065 };
00066
00067 void PyMap::initialize()
00068 {
00069 if (!isInitialized)
00070 {
00071 PyMap::_lassPyType.tp_as_mapping = &pyMappingMethods;
00072 PyMap::_lassPyType.tp_iter = (getiterfunc) &PyMap::PyMap_Iter;
00073 #ifdef LASS_PYTHON_INHERITANCE_FROM_EMBEDDING
00074
00075
00076
00077 PyMap::_lassPyType.tp_dictoffset = 0;
00078 PyMap::_lassPyType.tp_flags &= ~Py_TPFLAGS_BASETYPE;
00079 #endif
00080 finalizePyType( PyMap::_lassPyType, *PyMap::_lassPyGetParentType(), PyMap::_lassPyMethods,
00081 PyMap::_lassPyGetSetters, PyMap::_lassPyStatics, NULL, NULL);
00082 LASS_ENFORCE( PyType_Ready( &_lassPyType ) >= 0 );
00083 isInitialized = true;
00084 }
00085 }
00086
00087
00088 PyMap::PyMap()
00089 {
00090 LASS_THROW( "PyMap needs a std::map to initialize" );
00091 }
00092
00093 PyMap::~PyMap()
00094 {
00095 delete pimpl_;
00096 }
00097
00098
00099 #pragma LASS_TODO("check the IPO for a PyMap type")
00100
00101 Py_ssize_t PyMap::PyMap_Length( PyObject* iPO)
00102 {
00103 return static_cast<PyMap*>(iPO)->pimpl_->PyMap_Length();
00104 }
00105
00106 PyObject* PyMap::PyMap_Subscript( PyObject* iPO, PyObject* iKey)
00107 {
00108 return static_cast<PyMap*>(iPO)->pimpl_->PyMap_Subscript(iKey);
00109 }
00110
00111 int PyMap::PyMap_AssSubscript( PyObject* iPO, PyObject* iKey, PyObject* iValue)
00112 {
00113 return static_cast<PyMap*>(iPO)->pimpl_->PyMap_AssSubscript(iKey, iValue);
00114 }
00115
00116
00117 PyObject* PyMap::PyMap_Iter( PyObject* iPO)
00118 {
00119 return static_cast<PyMap*>(iPO)->pimpl_->PyMap_Iter();
00120 }
00121
00122
00123 }
00124
00125 }
00126
00127 }