Advertisement
Guest User

Michele Petrazzo

a guest
Jan 12th, 2010
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 6.52 KB | None | 0 0
  1. michele:/home/devel/pyside/shiboken$ cat /home/devel/pyside/shiboken/tests/samplebinding/sample/abstractmodifications_wrapper.cpp
  2.  
  3. //workaround to access protected functions
  4. #define protected public
  5.  
  6. // default includes
  7. #include <shiboken.h>
  8. #include "sample_python.h"
  9.  
  10. #include "abstractmodifications_wrapper.h"
  11.  
  12. // Extra includes
  13. #include <point.h>
  14. #include <utility>
  15.  
  16. using namespace Shiboken;
  17.  
  18. // Native ---------------------------------------------------------
  19.  
  20. AbstractModificationsWrapper::AbstractModificationsWrapper() : AbstractModifications() {
  21.     // ... middle
  22. }
  23.  
  24. void AbstractModificationsWrapper::pointlessPureVirtualMethod()
  25. {
  26.     PyObject* py_override = BindingManager::instance().getOverride(this, "pointlessPureVirtualMethod");
  27.     if (!py_override) {
  28.         PyErr_SetString(PyExc_NotImplementedError, "pure virtual method 'AbstractModifications.pointlessPureVirtualMethod()' not implemented.");
  29.         return;
  30.     }
  31.  
  32.     PyObject* pyargs = PyTuple_New(0);
  33.  
  34.     PyGILState_STATE gil_state = PyGILState_Ensure();
  35.     PyObject_Call(py_override, pyargs, NULL);
  36.     PyGILState_Release(gil_state);
  37.  
  38.     Py_XDECREF(pyargs);
  39.     Py_XDECREF(py_override);
  40.  
  41.     // check and set Python error here...
  42. }
  43.  
  44. const char * AbstractModificationsWrapper::className()
  45. {
  46.     PyObject* py_override = BindingManager::instance().getOverride(this, "name");
  47.     if (!py_override) {
  48.         return this->Modifications::className();
  49.     }
  50.  
  51.     PyObject* pyargs = PyTuple_New(0);
  52.  
  53.     PyGILState_STATE gil_state = PyGILState_Ensure();
  54.     PyObject* py_result = PyObject_Call(py_override, pyargs, NULL);
  55.     PyGILState_Release(gil_state);
  56.  
  57.     Py_XDECREF(pyargs);
  58.     Py_XDECREF(py_override);
  59.  
  60.     // check and set Python error here...
  61.     return Shiboken::Converter<const char * >::toCpp(py_result);
  62. }
  63.  
  64. AbstractModificationsWrapper::~AbstractModificationsWrapper()
  65. {
  66.     BindingManager::instance().invalidateWrapper(this);
  67. }
  68.  
  69. // Target ---------------------------------------------------------
  70.  
  71. PyObject*
  72. SbkAbstractModifications_New(Shiboken::SbkBaseWrapperType* type, PyObject* args, PyObject* kwds)
  73. {
  74.     PyObject* self;
  75.     AbstractModificationsWrapper* cptr;
  76.  
  77.     if (type == &SbkAbstractModifications_Type) {
  78.         PyErr_SetString(PyExc_NotImplementedError,
  79.             "'AbstractModifications' represents a C++ abstract class and cannot be instanciated");
  80.         return 0;
  81.     }
  82.  
  83.     if (!PyType_IsSubtype((PyTypeObject*)type, (PyTypeObject*)&SbkAbstractModifications_Type))
  84.         return 0;
  85.  
  86.     // AbstractModifications()
  87.     cptr = new AbstractModificationsWrapper();
  88.     self = Shiboken::SbkBaseWrapper_New(type, cptr, 1, 1);
  89.  
  90.     if (!self) {
  91.         if (cptr) delete cptr;
  92.         return 0;
  93.     }
  94.  
  95.     return self;
  96. }
  97.  
  98. static PyObject*
  99. SbkAbstractModifications_invert(PyObject* self, PyObject* arg)
  100. {
  101.     if (Shiboken::cppObjectIsInvalid(self))
  102.         return 0;
  103.  
  104.     PyObject* py_result = 0;
  105.     if (PyBool_Check(arg)) {
  106.         bool cpp_arg0 = Shiboken::Converter<bool >::toCpp(arg);
  107.         // invert(bool)
  108.         py_result = Shiboken::Converter<bool >::toPython(
  109.             SbkAbstractModifications_cptr(self)->AbstractModifications::invert(cpp_arg0)
  110.         );
  111.     } else goto SbkAbstractModifications_invert_TypeError;
  112.  
  113.     if (PyErr_Occurred() || !py_result) {
  114.         Py_XDECREF(py_result);
  115.         return 0;
  116.     }
  117.     return py_result;
  118.  
  119.     SbkAbstractModifications_invert_TypeError:
  120.         PyErr_SetString(PyExc_TypeError, "'invert()' called with wrong parameters.");
  121.         return 0;
  122. }
  123.  
  124. static PyObject*
  125. SbkAbstractModifications_pointlessPureVirtualMethod(PyObject* self)
  126. {
  127.     PyErr_SetString(PyExc_NotImplementedError, "pure virtual method 'AbstractModifications.pointlessPureVirtualMethod()' not implemented.");
  128.     return 0;
  129. }
  130.  
  131. static PyMethodDef SbkAbstractModifications_methods[] = {
  132.     {"invert", (PyCFunction)SbkAbstractModifications_invert, METH_O},
  133.     {"pointlessPureVirtualMethod", (PyCFunction)SbkAbstractModifications_pointlessPureVirtualMethod, METH_NOARGS},
  134.     {0} // Sentinel
  135. };
  136.  
  137. extern "C"
  138. {
  139.  
  140. // Class Definition -----------------------------------------------
  141. Shiboken::SbkBaseWrapperType SbkAbstractModifications_Type = { { {
  142.     PyObject_HEAD_INIT(&Shiboken::SbkBaseWrapperType_Type)
  143.     /*ob_size*/             0,
  144.     /*tp_name*/             "AbstractModifications",
  145.     /*tp_basicsize*/        sizeof(Shiboken::SbkBaseWrapper),
  146.     /*tp_itemsize*/         0,
  147.     /*tp_dealloc*/          (destructor)&(Shiboken::SbkBaseWrapper_Dealloc< AbstractModificationsWrapper >),
  148.     /*tp_print*/            0,
  149.     /*tp_getattr*/          0,
  150.     /*tp_setattr*/          0,
  151.     /*tp_compare*/          0,
  152.     /*tp_repr*/             0,
  153.     /*tp_as_number*/        0,
  154.     /*tp_as_sequence*/      0,
  155.     /*tp_as_mapping*/       0,
  156.     /*tp_hash*/             0,
  157.     /*tp_call*/             0,
  158.     /*tp_str*/              0,
  159.     /*tp_getattro*/         0,
  160.     /*tp_setattro*/         0,
  161.     /*tp_as_buffer*/        0,
  162.     /*tp_flags*/            Py_TPFLAGS_DEFAULT|Py_TPFLAGS_BASETYPE|Py_TPFLAGS_CHECKTYPES,
  163.     /*tp_doc*/              0,
  164.     /*tp_traverse*/         0,
  165.     /*tp_clear*/            0,
  166.     /*tp_richcompare*/      0,
  167.     /*tp_weaklistoffset*/   0,
  168.     /*tp_iter*/             0,
  169.     /*tp_iternext*/         0,
  170.     /*tp_methods*/          SbkAbstractModifications_methods,
  171.     /*tp_members*/          0,
  172.     /*tp_getset*/           0,
  173.     /*tp_base*/             (PyTypeObject*)&SbkModifications_Type,
  174.     /*tp_dict*/             0,
  175.     /*tp_descr_get*/        0,
  176.     /*tp_descr_set*/        0,
  177.     /*tp_dictoffset*/       0,
  178.     /*tp_init*/             0,
  179.     /*tp_alloc*/            0,
  180.     /*tp_new*/              (newfunc)SbkAbstractModifications_New,
  181.     /*tp_free*/             0,
  182.     /*tp_is_gc*/            0,
  183.     /*tp_bases*/            0,
  184.     /*tp_mro*/              0,
  185.     /*tp_cache*/            0,
  186.     /*tp_subclasses*/       0,
  187.     /*tp_weaklist*/         0
  188. }, },
  189.     /*mi_offsets*/          0,
  190.     /*mi_init*/             0,
  191.     /*mi_specialcast*/      0
  192. };
  193.  
  194.  
  195. PyAPI_FUNC(void)
  196. init_abstractmodifications(PyObject* module)
  197. {
  198.     if (PyType_Ready((PyTypeObject*)&SbkAbstractModifications_Type) < 0)
  199.         return;
  200.  
  201.     Py_INCREF(&SbkAbstractModifications_Type);
  202.     PyModule_AddObject(module, "AbstractModifications",
  203.         ((PyObject*)&SbkAbstractModifications_Type));
  204.  
  205. }
  206.  
  207.  
  208. } // extern "C"
  209.  
  210. namespace Shiboken
  211. {
  212. // Copy C++ object implementation
  213. // Converter implementations
  214. } // namespace Shiboken
  215.  
  216.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement