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

PyObjectPlus.cpp

Go to the documentation of this file.
00001 /*------------------------------

00002  * PyObjectPlus cpp

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

00005  *
00006  * Derived from work by

00007  * David Redish

00008  * graduate student

00009  * Computer Science Department 

00010  * Carnegie Mellon University (CMU)

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

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

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

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

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

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

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

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

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

00057  * PyObjectPlus attributes      -- attributes

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

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

00068 {
00069   //cerr << "Unknown attribute" << endl;
00070   return 1;
00071 }
00072 
00073 /*------------------------------

00074  * PyObjectPlus repr            -- representations

00075 ------------------------------*/
00076 PyObject *PyObjectPlus::_repr(void)

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

00082  * PyObjectPlus isA             -- the isA functions

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

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