BaseClassPy.cpp

Go to the documentation of this file.
00001 
00002 // This file is generated by src/Tools/generateTemaplates/templateClassPyExport.py out of the .XML file
00003 // Every change you make here get lost at the next full rebuild!
00004 // This File is normaly build as an include in BaseClassPyImp.cpp! Its not intended to be in a project!
00005 
00006 #include <boost/filesystem/path.hpp>
00007 #include <boost/filesystem/operations.hpp>
00008 #include <boost/filesystem/exception.hpp>
00009 #include <Base/PyObjectBase.h>
00010 #include <Base/Console.h>
00011 #include <Base/Exception.h>
00012 #include <CXX/Objects.hxx>
00013 
00014 #define new DEBUG_CLIENTBLOCK
00015 
00016 using Base::streq;
00017 using namespace Base;
00018 
00020 PyTypeObject BaseClassPy::Type = {
00021     PyObject_HEAD_INIT(&PyType_Type)
00022     0,                                                /*ob_size*/
00023     "Base.BaseClass",     /*tp_name*/
00024     sizeof(BaseClassPy),                       /*tp_basicsize*/
00025     0,                                                /*tp_itemsize*/
00026     /* methods */
00027     PyDestructor,                                     /*tp_dealloc*/
00028     0,                                                /*tp_print*/
00029     __getattr,                                        /*tp_getattr*/
00030     __setattr,                                        /*tp_setattr*/
00031     0,                                                /*tp_compare*/
00032     __repr,                                           /*tp_repr*/
00033     0,                                                /*tp_as_number*/
00034     0,                                                /*tp_as_sequence*/
00035     0,                                                /*tp_as_mapping*/
00036     0,                                                /*tp_hash*/
00037     0,                                                /*tp_call */
00038     0,                                                /*tp_str  */
00039     0,                                                /*tp_getattro*/
00040     0,                                                /*tp_setattro*/
00041     /* --- Functions to access object as input/output buffer ---------*/
00042     0,                                                /* tp_as_buffer */
00043     /* --- Flags to define presence of optional/expanded features */
00044     Py_TPFLAGS_BASETYPE|Py_TPFLAGS_HAVE_CLASS,        /*tp_flags */
00045     "This is the base class",           /*tp_doc */
00046     0,                                                /*tp_traverse */
00047     0,                                                /*tp_clear */
00048     0,                                                /*tp_richcompare */
00049     0,                                                /*tp_weaklistoffset */
00050     0,                                                /*tp_iter */
00051     0,                                                /*tp_iternext */
00052     Base::BaseClassPy::Methods,                     /*tp_methods */
00053     0,                                                /*tp_members */
00054     Base::BaseClassPy::GetterSetter,                     /*tp_getset */
00055     &Base::PyObjectBase::Type,                        /*tp_base */
00056     0,                                                /*tp_dict */
00057     0,                                                /*tp_descr_get */
00058     0,                                                /*tp_descr_set */
00059     0,                                                /*tp_dictoffset */
00060     __PyInit,                                         /*tp_init */
00061     0,                                                /*tp_alloc */
00062     Base::BaseClassPy::PyMake,/*tp_new */
00063     0,                                                /*tp_free   Low-level free-memory routine */
00064     0,                                                /*tp_is_gc  For PyObject_IS_GC */
00065     0,                                                /*tp_bases */
00066     0,                                                /*tp_mro    method resolution order */
00067     0,                                                /*tp_cache */
00068     0,                                                /*tp_subclasses */
00069     0,                                                /*tp_weaklist */
00070     0                                                 /*tp_del */
00071 };
00072 
00074 PyMethodDef BaseClassPy::Methods[] = {
00075     {"isDerivedFrom",
00076         (PyCFunction) staticCallback_isDerivedFrom,
00077         METH_VARARGS,
00078         "Returns true if given type is a father"
00079     },
00080     {"getAllDerivedFrom",
00081         (PyCFunction) staticCallback_getAllDerivedFrom,
00082         METH_VARARGS,
00083         "Returns all descentences"
00084     },
00085     {NULL, NULL, 0, NULL}               /* Sentinel */
00086 };
00087 
00088 
00089 
00091 PyGetSetDef BaseClassPy::GetterSetter[] = {
00092     {"Type",
00093         (getter) staticCallback_getType,
00094         (setter) staticCallback_setType, 
00095         "Is the type of the FreeCAD object with module domain",
00096         NULL
00097     },
00098     {"Module",
00099         (getter) staticCallback_getModule,
00100         (setter) staticCallback_setModule, 
00101         "Module in which this class is defined",
00102         NULL
00103     },
00104     {NULL, NULL, NULL, NULL, NULL}              /* Sentinel */
00105 };
00106 
00107 // isDerivedFrom() callback and implementer
00108 // PyObject*  BaseClassPy::isDerivedFrom(PyObject *args){};
00109 // has to be implemented in BaseClassPyImp.cpp
00110 PyObject * BaseClassPy::staticCallback_isDerivedFrom (PyObject *self, PyObject *args)
00111 {
00112     // test if twin object not allready deleted
00113     if (!((PyObjectBase*) self)->isValid()){
00114         PyErr_SetString(PyExc_ReferenceError, "This object is already deleted most likely through closing a document. This reference is no longer valid!");
00115         return NULL;
00116     }
00117 
00118 
00119     try { // catches all exceptions coming up from c++ and generate a python exception
00120         PyObject* ret = ((BaseClassPy*)self)->isDerivedFrom(args);
00121         return ret;
00122     }
00123     catch(const Base::Exception& e) // catch the FreeCAD exceptions
00124     {
00125         std::string str;
00126         str += "FreeCAD exception thrown (";
00127         str += e.what();
00128         str += ")";
00129         e.ReportException();
00130         PyErr_SetString(PyExc_Exception,str.c_str());
00131         return NULL;
00132     }
00133     catch(const boost::filesystem::filesystem_error& e) // catch boost filesystem exception
00134     {
00135         std::string str;
00136         str += "File system exception thrown (";
00137         //str += e.who();
00138         //str += ", ";
00139         str += e.what();
00140         str += ")\n";
00141         Base::Console().Error(str.c_str());
00142         PyErr_SetString(PyExc_Exception,str.c_str());
00143         return NULL;
00144     }
00145     catch(const Py::Exception&)
00146     {
00147         // The exception text is already set
00148         return NULL;
00149     }
00150     catch(const char* e) // catch simple string exceptions
00151     {
00152         Base::Console().Error(e);
00153         PyErr_SetString(PyExc_Exception,e);
00154         return NULL;
00155     }
00156     // in debug not all exceptions will be catched to get the attention of the developer!
00157 #ifndef DONT_CATCH_CXX_EXCEPTIONS 
00158     catch(const std::exception& e) // catch other c++ exceptions
00159     {
00160         std::string str;
00161         str += "FC++ exception thrown (";
00162         str += e.what();
00163         str += ")";
00164         Base::Console().Error(str.c_str());
00165         PyErr_SetString(PyExc_Exception,str.c_str());
00166         return NULL;
00167     }
00168     catch(...)  // catch the rest!
00169     {
00170         PyErr_SetString(PyExc_Exception,"Unknown C++ exception");
00171         return NULL;
00172     }
00173 #endif
00174 }
00175 
00176 // getAllDerivedFrom() callback and implementer
00177 // PyObject*  BaseClassPy::getAllDerivedFrom(PyObject *args){};
00178 // has to be implemented in BaseClassPyImp.cpp
00179 PyObject * BaseClassPy::staticCallback_getAllDerivedFrom (PyObject *self, PyObject *args)
00180 {
00181     // test if twin object not allready deleted
00182     if (!((PyObjectBase*) self)->isValid()){
00183         PyErr_SetString(PyExc_ReferenceError, "This object is already deleted most likely through closing a document. This reference is no longer valid!");
00184         return NULL;
00185     }
00186 
00187 
00188     try { // catches all exceptions coming up from c++ and generate a python exception
00189         PyObject* ret = ((BaseClassPy*)self)->getAllDerivedFrom(args);
00190         return ret;
00191     }
00192     catch(const Base::Exception& e) // catch the FreeCAD exceptions
00193     {
00194         std::string str;
00195         str += "FreeCAD exception thrown (";
00196         str += e.what();
00197         str += ")";
00198         e.ReportException();
00199         PyErr_SetString(PyExc_Exception,str.c_str());
00200         return NULL;
00201     }
00202     catch(const boost::filesystem::filesystem_error& e) // catch boost filesystem exception
00203     {
00204         std::string str;
00205         str += "File system exception thrown (";
00206         //str += e.who();
00207         //str += ", ";
00208         str += e.what();
00209         str += ")\n";
00210         Base::Console().Error(str.c_str());
00211         PyErr_SetString(PyExc_Exception,str.c_str());
00212         return NULL;
00213     }
00214     catch(const Py::Exception&)
00215     {
00216         // The exception text is already set
00217         return NULL;
00218     }
00219     catch(const char* e) // catch simple string exceptions
00220     {
00221         Base::Console().Error(e);
00222         PyErr_SetString(PyExc_Exception,e);
00223         return NULL;
00224     }
00225     // in debug not all exceptions will be catched to get the attention of the developer!
00226 #ifndef DONT_CATCH_CXX_EXCEPTIONS 
00227     catch(const std::exception& e) // catch other c++ exceptions
00228     {
00229         std::string str;
00230         str += "FC++ exception thrown (";
00231         str += e.what();
00232         str += ")";
00233         Base::Console().Error(str.c_str());
00234         PyErr_SetString(PyExc_Exception,str.c_str());
00235         return NULL;
00236     }
00237     catch(...)  // catch the rest!
00238     {
00239         PyErr_SetString(PyExc_Exception,"Unknown C++ exception");
00240         return NULL;
00241     }
00242 #endif
00243 }
00244 
00245 // Type() callback and implementer
00246 // PyObject*  BaseClassPy::Type(PyObject *args){};
00247 // has to be implemented in BaseClassPyImp.cpp
00248 PyObject * BaseClassPy::staticCallback_getType (PyObject *self, void * /*closure*/)
00249 {
00250     if (!((PyObjectBase*) self)->isValid()){
00251         PyErr_SetString(PyExc_ReferenceError, "This object is already deleted most likely through closing a document. This reference is no longer valid!");
00252         return NULL;
00253     }
00254 
00255     try {
00256         return Py::new_reference_to(((BaseClassPy*)self)->getType());
00257     } catch (const Py::Exception&) {
00258         // The exception text is already set
00259         return NULL;
00260     } catch (...) {
00261         PyErr_SetString(PyExc_Exception, "Unknown exception while reading attribute 'Type' of object 'BaseClass'");
00262         return NULL;
00263     }
00264 }
00265 
00266 int BaseClassPy::staticCallback_setType (PyObject *self, PyObject * /*value*/, void * /*closure*/)
00267 {
00268     if (!((PyObjectBase*) self)->isValid()){
00269         PyErr_SetString(PyExc_ReferenceError, "This object is already deleted most likely through closing a document. This reference is no longer valid!");
00270         return -1;
00271     }
00272 
00273     PyErr_SetString(PyExc_AttributeError, "Attribute 'Type' of object 'BaseClass' is read-only");
00274     return -1;
00275 }
00276 
00277 // Module() callback and implementer
00278 // PyObject*  BaseClassPy::Module(PyObject *args){};
00279 // has to be implemented in BaseClassPyImp.cpp
00280 PyObject * BaseClassPy::staticCallback_getModule (PyObject *self, void * /*closure*/)
00281 {
00282     if (!((PyObjectBase*) self)->isValid()){
00283         PyErr_SetString(PyExc_ReferenceError, "This object is already deleted most likely through closing a document. This reference is no longer valid!");
00284         return NULL;
00285     }
00286 
00287     try {
00288         return Py::new_reference_to(((BaseClassPy*)self)->getModule());
00289     } catch (const Py::Exception&) {
00290         // The exception text is already set
00291         return NULL;
00292     } catch (...) {
00293         PyErr_SetString(PyExc_Exception, "Unknown exception while reading attribute 'Module' of object 'BaseClass'");
00294         return NULL;
00295     }
00296 }
00297 
00298 int BaseClassPy::staticCallback_setModule (PyObject *self, PyObject * /*value*/, void * /*closure*/)
00299 {
00300     if (!((PyObjectBase*) self)->isValid()){
00301         PyErr_SetString(PyExc_ReferenceError, "This object is already deleted most likely through closing a document. This reference is no longer valid!");
00302         return -1;
00303     }
00304 
00305     PyErr_SetString(PyExc_AttributeError, "Attribute 'Module' of object 'BaseClass' is read-only");
00306     return -1;
00307 }
00308 
00309 
00310 
00311 //--------------------------------------------------------------------------
00312 // Parents structure
00313 //--------------------------------------------------------------------------
00314 PyParentObject BaseClassPy::Parents[] = { PARENTSBaseBaseClassPy };
00315 
00316 //--------------------------------------------------------------------------
00317 // Constructor
00318 //--------------------------------------------------------------------------
00319 BaseClassPy::BaseClassPy(BaseClass *pcObject, PyTypeObject *T)
00320     : PyObjectBase(reinterpret_cast<PyObjectBase::PointerType>(pcObject), T)
00321 {
00322 }
00323 
00324 PyObject *BaseClassPy::PyMake(struct _typeobject *, PyObject *, PyObject *)  // Python wrapper
00325 {
00326     // never create such objects with the constructor
00327     PyErr_SetString(PyExc_RuntimeError, "You cannot create directly an instance of 'BaseClassPy'.");
00328  
00329     return 0;
00330 }
00331 
00332 int BaseClassPy::PyInit(PyObject* /*args*/, PyObject* /*kwd*/)
00333 {
00334     return 0;
00335 }
00336 
00337 //--------------------------------------------------------------------------
00338 // destructor
00339 //--------------------------------------------------------------------------
00340 BaseClassPy::~BaseClassPy()                                // Everything handled in parent
00341 {
00342 }
00343 
00344 //--------------------------------------------------------------------------
00345 // BaseClassPy representation
00346 //--------------------------------------------------------------------------
00347 PyObject *BaseClassPy::_repr(void)
00348 {
00349     return Py_BuildValue("s", representation().c_str());
00350 }
00351 
00352 //--------------------------------------------------------------------------
00353 // BaseClassPy Attributes
00354 //--------------------------------------------------------------------------
00355 PyObject *BaseClassPy::_getattr(char *attr)                             // __getattr__ function: note only need to handle new state
00356 {
00357     try {
00358         // getter method for special Attributes (e.g. dynamic ones)
00359         PyObject *r = getCustomAttributes(attr);
00360         if(r) return r;
00361     }
00362 #ifndef DONT_CATCH_CXX_EXCEPTIONS 
00363     catch(const Base::Exception& e) // catch the FreeCAD exceptions
00364     {
00365         std::string str;
00366         str += "FreeCAD exception thrown (";
00367         str += e.what();
00368         str += ")";
00369         e.ReportException();
00370         PyErr_SetString(PyExc_Exception,str.c_str());
00371         return NULL;
00372     }
00373     catch(const std::exception& e) // catch other c++ exceptions
00374     {
00375         std::string str;
00376         str += "FC++ exception thrown (";
00377         str += e.what();
00378         str += ")";
00379         Base::Console().Error(str.c_str());
00380         PyErr_SetString(PyExc_Exception,str.c_str());
00381         return NULL;
00382     }
00383     catch(const Py::Exception&)
00384     {
00385         // The exception text is already set
00386         return NULL;
00387     }
00388     catch(...)  // catch the rest!
00389     {
00390         PyErr_SetString(PyExc_Exception,"Unknown C++ exception");
00391         return NULL;
00392     }
00393 #else  // DONT_CATCH_CXX_EXCEPTIONS  
00394     catch(const Base::Exception& e) // catch the FreeCAD exceptions
00395     {
00396         std::string str;
00397         str += "FreeCAD exception thrown (";
00398         str += e.what();
00399         str += ")";
00400         e.ReportException();
00401         PyErr_SetString(PyExc_Exception,str.c_str());
00402         return NULL;
00403     }
00404     catch(const Py::Exception&)
00405     {
00406         // The exception text is already set
00407         return NULL;
00408     }
00409 #endif  // DONT_CATCH_CXX_EXCEPTIONS
00410 
00411     PyObject *rvalue = Py_FindMethod(Methods, this, attr);
00412     if (rvalue == NULL)
00413     {
00414         PyErr_Clear();
00415         return PyObjectBase::_getattr(attr);
00416     }
00417     else
00418     {
00419         return rvalue;
00420     }
00421 }
00422 
00423 int BaseClassPy::_setattr(char *attr, PyObject *value)  // __setattr__ function: note only need to handle new state
00424 {
00425     try {
00426         // setter for  special Attributes (e.g. dynamic ones)
00427         int r = setCustomAttributes(attr, value);
00428         if(r==1) return 0;
00429     }
00430 #ifndef DONT_CATCH_CXX_EXCEPTIONS 
00431     catch(const Base::Exception& e) // catch the FreeCAD exceptions
00432     {
00433         std::string str;
00434         str += "FreeCAD exception thrown (";
00435         str += e.what();
00436         str += ")";
00437         e.ReportException();
00438         PyErr_SetString(PyExc_Exception,str.c_str());
00439         return -1;
00440     }
00441     catch(const std::exception& e) // catch other c++ exceptions
00442     {
00443         std::string str;
00444         str += "FC++ exception thrown (";
00445         str += e.what();
00446         str += ")";
00447         Base::Console().Error(str.c_str());
00448         PyErr_SetString(PyExc_Exception,str.c_str());
00449         return -1;
00450     }
00451     catch(const Py::Exception&)
00452     {
00453         // The exception text is already set
00454         return -1;
00455     }
00456     catch(...)  // catch the rest!
00457     {
00458         PyErr_SetString(PyExc_Exception,"Unknown C++ exception");
00459         return -1;
00460     }
00461 #else  // DONT_CATCH_CXX_EXCEPTIONS  
00462     catch(const Base::Exception& e) // catch the FreeCAD exceptions
00463     {
00464         std::string str;
00465         str += "FreeCAD exception thrown (";
00466         str += e.what();
00467         str += ")";
00468         e.ReportException();
00469         PyErr_SetString(PyExc_Exception,str.c_str());
00470         return -1;
00471     }
00472     catch(const Py::Exception&)
00473     {
00474         // The exception text is already set
00475         return -1;
00476     }
00477 #endif  // DONT_CATCH_CXX_EXCEPTIONS
00478 
00479     return PyObjectBase::_setattr(attr, value);
00480 }
00481 
00482 BaseClass *BaseClassPy::getBaseClassPtr(void) const
00483 {
00484     return static_cast<BaseClass *>(_pcTwinPointer);
00485 }
00486 
00487 #if 0
00488 /* From here on come the methods you have to implement, but NOT in this module. Implement in BaseClassPyImp.cpp! This prototypes 
00489  * are just for convenience when you add a new method.
00490  */
00491 
00492 
00493 // returns a string which represents the object e.g. when printed in python
00494 std::string BaseClassPy::representation(void) const
00495 {
00496     return std::string("<BaseClass object>");
00497 }
00498 
00499 PyObject* BaseClassPy::isDerivedFrom(PyObject *args)
00500 {
00501     PyErr_SetString(PyExc_NotImplementedError, "Not yet implemented");
00502     return 0;
00503 }
00504 
00505 PyObject* BaseClassPy::getAllDerivedFrom(PyObject *args)
00506 {
00507     PyErr_SetString(PyExc_NotImplementedError, "Not yet implemented");
00508     return 0;
00509 }
00510 
00511 
00512 
00513 Py::String BaseClassPy::getType(void) const
00514 {
00515     //return Py::String();
00516     throw Py::AttributeError("Not yet implemented");
00517 }
00518 
00519 Py::Int BaseClassPy::getModule(void) const
00520 {
00521     //return Py::Int();
00522     throw Py::AttributeError("Not yet implemented");
00523 }
00524 
00525 PyObject *BaseClassPy::getCustomAttributes(const char* attr) const
00526 {
00527     return 0;
00528 }
00529 
00530 int BaseClassPy::setCustomAttributes(const char* attr, PyObject *obj)
00531 {
00532     return 0; 
00533 }
00534 #endif
00535 
00536 
00537 

Generated on Wed Nov 23 18:59:57 2011 for FreeCAD by  doxygen 1.6.1