Main Page   Namespace List   Class Hierarchy   Compound List   File List   Compound Members   File Members  

PyObjectPlus.cpp

Go to the documentation of this file.
00001 #ifndef NO_EXP_PYTHON_EMBEDDING
00002 /*------------------------------

00003  * PyObjectPlus cpp

00004  *
00005  * C++ library routines for Crawl 3.2

00006  *
00007  * Derived from work by

00008  * David Redish

00009  * graduate student

00010  * Computer Science Department 

00011  * Carnegie Mellon University (CMU)

00012  * Center for the Neural Basis of Cognition (CNBC) 

00013  * http://www.python.org/doc/PyCPP.html

00014  *
00015 ------------------------------*/
00016 
00017 #include "stdlib.h"
00018 #include "PyObjectPlus.h"
00019 
00020 /*------------------------------

00021  * PyObjectPlus Type            -- Every class, even the abstract one should have a Type

00022 ------------------------------*/
00023 
00024 PyTypeObject PyObjectPlus::Type = {
00025         PyObject_HEAD_INIT(&PyType_Type)
00026         0,                              /*ob_size*/
00027         "PyObjectPlus",                 /*tp_name*/
00028         sizeof(PyObjectPlus),           /*tp_basicsize*/
00029         0,                              /*tp_itemsize*/
00030         /* methods */
00031         PyDestructor,                   /*tp_dealloc*/
00032         0,                              /*tp_print*/
00033         __getattr,                      /*tp_getattr*/
00034         __setattr,                      /*tp_setattr*/
00035         0,                              /*tp_compare*/
00036         __repr,                         /*tp_repr*/
00037         0,                              /*tp_as_number*/
00038         0,                              /*tp_as_sequence*/
00039         0,                              /*tp_as_mapping*/
00040         0,                              /*tp_hash*/
00041         0,                              /*tp_call */
00042 };
00043 
00044 /*------------------------------

00045  * PyObjectPlus Methods         -- Every class, even the abstract one should have a Methods

00046 ------------------------------*/
00047 PyMethodDef PyObjectPlus::Methods[] = {
00048   {"isA",                (PyCFunction) sPy_isA,                 Py_NEWARGS},
00049   {NULL, NULL}          /* Sentinel */
00050 };
00051 
00052 /*------------------------------

00053  * PyObjectPlus Parents         -- Every class, even the abstract one should have parents

00054 ------------------------------*/
00055 PyParentObject PyObjectPlus::Parents[] = {&PyObjectPlus::Type, NULL};
00056 
00057 /*------------------------------

00058  * PyObjectPlus attributes      -- attributes

00059 ------------------------------*/
00060 PyObject *PyObjectPlus::_getattr(char *attr)

00061 {
00062   //if (streq(attr, "type"))
00063   //  return Py_BuildValue("s", (*(GetParents()))->tp_name);
00064 
00065   return Py_FindMethod(Methods, this, attr);    
00066 }
00067 
00068 int PyObjectPlus::_setattr(char *attr, PyObject *value)

00069 {
00070         //return PyObject::_setattr(attr,value);
00071         //cerr << "Unknown attribute" << endl;
00072   return 1;
00073 }
00074 
00075 /*------------------------------

00076  * PyObjectPlus repr            -- representations

00077 ------------------------------*/
00078 PyObject *PyObjectPlus::_repr(void)

00079 {
00080   Py_Error(PyExc_SystemError, "Representation not overridden by object.");  
00081 }
00082 
00083 /*------------------------------

00084  * PyObjectPlus isA             -- the isA functions

00085 ------------------------------*/
00086 bool PyObjectPlus::isA(PyTypeObject *T)         // if called with a Type, use "typename"
00087 {
00088   return isA(T->tp_name);
00089 }
00090 
00091 
00092 bool PyObjectPlus::isA(const char *mytypename)          // check typename of each parent
00093 {
00094   int i;
00095   PyParentObject  P;
00096   PyParentObject *Ps = GetParents();
00097 
00098   //for (P = Ps[i=0]; P != NULL; P = Ps[i++])
00099   //    if (streq(P->tp_name, mytypename))
00100 //      return true;
00101   return false;
00102 }
00103 
00104 PyObject *PyObjectPlus::Py_isA(PyObject *args)          // Python wrapper for isA
00105 {
00106   char *mytypename;
00107   Py_Try(PyArg_ParseTuple(args, "s", &mytypename));
00108   if(isA(mytypename))
00109     {Py_INCREF(Py_True); return Py_True;}
00110   else
00111     {Py_INCREF(Py_False); return Py_False;};
00112 }
00113 
00114 #endif //NO_EXP_PYTHON_EMBEDDING
00115 

Generated at Thu Feb 1 13:03:08 2001 for Ketsji Game Engine by doxygen1.2.3 written by Dimitri van Heesch, © 1997-2000