|
Blender
V2.59
|
00001 /* 00002 * $Id: PyObjectPlus.h 38602 2011-07-22 11:21:01Z campbellbarton $ 00003 * 00004 * ***** BEGIN GPL LICENSE BLOCK ***** 00005 * 00006 * This program is free software; you can redistribute it and/or 00007 * modify it under the terms of the GNU General Public License 00008 * as published by the Free Software Foundation; either version 2 00009 * of the License, or (at your option) any later version. 00010 * 00011 * This program is distributed in the hope that it will be useful, 00012 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00014 * GNU General Public License for more details. 00015 * 00016 * You should have received a copy of the GNU General Public License 00017 * along with this program; if not, write to the Free Software Foundation, 00018 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 00019 * 00020 * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV. 00021 * All rights reserved. 00022 * 00023 * The Original Code is: all of this file. 00024 * 00025 * Contributor(s): none yet. 00026 * 00027 * ***** END GPL LICENSE BLOCK ***** 00028 */ 00029 00034 /* for now keep weakrefs optional */ 00035 #define USE_WEAKREFS 00036 00037 #ifndef _adr_py_lib_h_ // only process once, 00038 #define _adr_py_lib_h_ // even if multiply included 00039 00040 #ifndef __cplusplus // c++ only 00041 #error Must be compiled with C++ 00042 #endif 00043 00044 #include "KX_Python.h" 00045 #include "STR_String.h" 00046 #include "MT_Vector3.h" 00047 #include "SG_QList.h" 00048 #include <stddef.h> 00049 00050 /*------------------------------ 00051 * Python defines 00052 ------------------------------*/ 00053 00054 #ifdef WITH_PYTHON 00055 #ifdef USE_MATHUTILS 00056 extern "C" { 00057 #include "../../blender/python/mathutils/mathutils.h" /* so we can have mathutils callbacks */ 00058 #include "../../blender/python/generic/py_capi_utils.h" /* for PyC_LineSpit only */ 00059 } 00060 #endif 00061 00062 static inline void Py_Fatal(const char *M) { 00063 fprintf(stderr, "%s\n", M); 00064 exit(-1); 00065 }; 00066 00067 00068 /* Use with ShowDeprecationWarning macro */ 00069 typedef struct { 00070 bool warn_done; 00071 void *link; 00072 } WarnLink; 00073 00074 #define ShowDeprecationWarning(old_way, new_way) \ 00075 { \ 00076 static WarnLink wlink = {false, NULL}; \ 00077 if ((m_ignore_deprecation_warnings || wlink.warn_done)==0) \ 00078 { \ 00079 ShowDeprecationWarning_func(old_way, new_way); \ 00080 \ 00081 WarnLink *wlink_last= GetDeprecationWarningLinkLast(); \ 00082 wlink.warn_done = true; \ 00083 wlink.link = NULL; \ 00084 \ 00085 if(wlink_last) { \ 00086 wlink_last->link= (void *)&(wlink); \ 00087 SetDeprecationWarningLinkLast(&(wlink)); \ 00088 } else { \ 00089 SetDeprecationWarningFirst(&(wlink)); \ 00090 SetDeprecationWarningLinkLast(&(wlink)); \ 00091 } \ 00092 } \ 00093 } \ 00094 00095 00096 00097 typedef struct PyObjectPlus_Proxy { 00098 PyObject_HEAD /* required python macro */ 00099 class PyObjectPlus *ref; // pointer to GE object, it holds a reference to this proxy 00100 void *ptr; // optional pointer to generic structure, the structure holds no reference to this proxy 00101 bool py_owns; // true if the object pointed by ref should be deleted when the proxy is deleted 00102 bool py_ref; // true if proxy is connected to a GE object (ref is used) 00103 #ifdef USE_WEAKREFS 00104 PyObject *in_weakreflist; // weak reference enabler 00105 #endif 00106 } PyObjectPlus_Proxy; 00107 00108 #define BGE_PROXY_ERROR_MSG "Blender Game Engine data has been freed, cannot use this python variable" 00109 #define BGE_PROXY_REF(_self) (((PyObjectPlus_Proxy *)_self)->ref) 00110 #define BGE_PROXY_PTR(_self) (((PyObjectPlus_Proxy *)_self)->ptr) 00111 #define BGE_PROXY_PYOWNS(_self) (((PyObjectPlus_Proxy *)_self)->py_owns) 00112 #define BGE_PROXY_PYREF(_self) (((PyObjectPlus_Proxy *)_self)->py_ref) 00113 #ifdef USE_WEAKREFS 00114 #define BGE_PROXY_WKREF(_self) (((PyObjectPlus_Proxy *)_self)->in_weakreflist) 00115 #endif 00116 00117 /* Note, sometimes we dont care what BGE type this is as long as its a proxy */ 00118 #define BGE_PROXY_CHECK_TYPE(_type) ((_type)->tp_dealloc == PyObjectPlus::py_base_dealloc) 00119 00120 /* Opposite of BGE_PROXY_REF */ 00121 #define BGE_PROXY_FROM_REF(_self) (((PyObjectPlus *)_self)->GetProxy()) 00122 00123 00124 // This must be the first line of each 00125 // PyC++ class 00126 // AttributesPtr correspond to attributes of proxy generic pointer 00127 // each PyC++ class must be registered in KX_PythonInitTypes.cpp 00128 #define __Py_Header \ 00129 public: \ 00130 static PyTypeObject Type; \ 00131 static PyMethodDef Methods[]; \ 00132 static PyAttributeDef Attributes[]; \ 00133 virtual PyTypeObject *GetType(void) {return &Type;}; \ 00134 virtual PyObject *GetProxy() {return GetProxyPlus_Ext(this, &Type, NULL);}; \ 00135 virtual PyObject *NewProxy(bool py_owns) {return NewProxyPlus_Ext(this, &Type, NULL, py_owns);}; \ 00136 00137 // leave above line empty (macro)! 00138 // use this macro for class that use generic pointer in proxy 00139 // GetProxy() and NewProxy() must be defined to set the correct pointer in the proxy 00140 #define __Py_HeaderPtr \ 00141 public: \ 00142 static PyTypeObject Type; \ 00143 static PyMethodDef Methods[]; \ 00144 static PyAttributeDef Attributes[]; \ 00145 static PyAttributeDef AttributesPtr[]; \ 00146 virtual PyTypeObject *GetType(void) {return &Type;}; \ 00147 virtual PyObject *GetProxy(); \ 00148 virtual PyObject *NewProxy(bool py_owns); \ 00149 00150 // leave above line empty (macro)! 00151 #ifdef WITH_CXX_GUARDEDALLOC 00152 #define Py_Header __Py_Header \ 00153 void *operator new(size_t num_bytes) { return MEM_mallocN(num_bytes, Type.tp_name); } \ 00154 void operator delete(void *mem) { MEM_freeN(mem); } \ 00155 00156 #else 00157 #define Py_Header __Py_Header 00158 #endif 00159 00160 #ifdef WITH_CXX_GUARDEDALLOC 00161 #define Py_HeaderPtr __Py_HeaderPtr \ 00162 void *operator new(size_t num_bytes) { return MEM_mallocN(num_bytes, Type.tp_name); } \ 00163 void operator delete( void *mem ) { MEM_freeN(mem); } \ 00164 00165 #else 00166 #define Py_HeaderPtr __Py_HeaderPtr 00167 #endif 00168 00169 /* 00170 * nonzero values are an error for setattr 00171 * however because of the nested lookups we need to know if the errors 00172 * was because the attribute didnt exits of if there was some problem setting the value 00173 */ 00174 00175 #define PY_SET_ATTR_COERCE_FAIL 2 00176 #define PY_SET_ATTR_FAIL 1 00177 #define PY_SET_ATTR_MISSING -1 00178 #define PY_SET_ATTR_SUCCESS 0 00179 00184 #define KX_PYMETHOD(class_name, method_name) \ 00185 PyObject* Py##method_name(PyObject* args, PyObject* kwds); \ 00186 static PyObject* sPy##method_name( PyObject* self, PyObject* args, PyObject* kwds) { \ 00187 if(BGE_PROXY_REF(self)==NULL) { PyErr_SetString(PyExc_RuntimeError, #class_name "." #method_name "() - " BGE_PROXY_ERROR_MSG); return NULL; } \ 00188 return ((class_name*)BGE_PROXY_REF(self))->Py##method_name(args, kwds); \ 00189 }; \ 00190 00191 #define KX_PYMETHOD_VARARGS(class_name, method_name) \ 00192 PyObject* Py##method_name(PyObject* args); \ 00193 static PyObject* sPy##method_name( PyObject* self, PyObject* args) { \ 00194 if(BGE_PROXY_REF(self)==NULL) { PyErr_SetString(PyExc_RuntimeError, #class_name "." #method_name "() - " BGE_PROXY_ERROR_MSG); return NULL; } \ 00195 return ((class_name*)BGE_PROXY_REF(self))->Py##method_name(args); \ 00196 }; \ 00197 00198 #define KX_PYMETHOD_NOARGS(class_name, method_name) \ 00199 PyObject* Py##method_name(); \ 00200 static PyObject* sPy##method_name( PyObject* self) { \ 00201 if(BGE_PROXY_REF(self)==NULL) { PyErr_SetString(PyExc_RuntimeError, #class_name "." #method_name "() - " BGE_PROXY_ERROR_MSG); return NULL; } \ 00202 return ((class_name*)BGE_PROXY_REF(self))->Py##method_name(); \ 00203 }; \ 00204 00205 #define KX_PYMETHOD_O(class_name, method_name) \ 00206 PyObject* Py##method_name(PyObject* value); \ 00207 static PyObject* sPy##method_name( PyObject* self, PyObject* value) { \ 00208 if(BGE_PROXY_REF(self)==NULL) { PyErr_SetString(PyExc_RuntimeError, #class_name "." #method_name "(value) - " BGE_PROXY_ERROR_MSG); return NULL; } \ 00209 return ((class_name*)BGE_PROXY_REF(self))->Py##method_name(value); \ 00210 }; \ 00211 00212 #define KX_PYMETHOD_DOC(class_name, method_name) \ 00213 PyObject* Py##method_name(PyObject* args, PyObject* kwds); \ 00214 static PyObject* sPy##method_name( PyObject* self, PyObject* args, PyObject* kwds) { \ 00215 if(BGE_PROXY_REF(self)==NULL) { PyErr_SetString(PyExc_RuntimeError, #class_name "." #method_name "(...) - " BGE_PROXY_ERROR_MSG); return NULL; } \ 00216 return ((class_name*)BGE_PROXY_REF(self))->Py##method_name(args, kwds); \ 00217 }; \ 00218 static const char method_name##_doc[]; \ 00219 00220 #define KX_PYMETHOD_DOC_VARARGS(class_name, method_name) \ 00221 PyObject* Py##method_name(PyObject* args); \ 00222 static PyObject* sPy##method_name( PyObject* self, PyObject* args) { \ 00223 if(BGE_PROXY_REF(self)==NULL) { PyErr_SetString(PyExc_RuntimeError, #class_name "." #method_name "(...) - " BGE_PROXY_ERROR_MSG); return NULL; } \ 00224 return ((class_name*)BGE_PROXY_REF(self))->Py##method_name(args); \ 00225 }; \ 00226 static const char method_name##_doc[]; \ 00227 00228 #define KX_PYMETHOD_DOC_O(class_name, method_name) \ 00229 PyObject* Py##method_name(PyObject* value); \ 00230 static PyObject* sPy##method_name( PyObject* self, PyObject* value) { \ 00231 if(BGE_PROXY_REF(self)==NULL) { PyErr_SetString(PyExc_RuntimeError, #class_name "." #method_name "(value) - " BGE_PROXY_ERROR_MSG); return NULL; } \ 00232 return ((class_name*)BGE_PROXY_REF(self))->Py##method_name(value); \ 00233 }; \ 00234 static const char method_name##_doc[]; \ 00235 00236 #define KX_PYMETHOD_DOC_NOARGS(class_name, method_name) \ 00237 PyObject* Py##method_name(); \ 00238 static PyObject* sPy##method_name( PyObject* self) { \ 00239 if(BGE_PROXY_REF(self)==NULL) { PyErr_SetString(PyExc_RuntimeError, #class_name "." #method_name "() - " BGE_PROXY_ERROR_MSG); return NULL; } \ 00240 return ((class_name*)BGE_PROXY_REF(self))->Py##method_name(); \ 00241 }; \ 00242 static const char method_name##_doc[]; \ 00243 00244 00245 /* The line above should remain empty */ 00249 #define KX_PYMETHODTABLE(class_name, method_name) \ 00250 {#method_name , (PyCFunction) class_name::sPy##method_name, METH_VARARGS, (const char *)class_name::method_name##_doc} 00251 00252 #define KX_PYMETHODTABLE_O(class_name, method_name) \ 00253 {#method_name , (PyCFunction) class_name::sPy##method_name, METH_O, (const char *)class_name::method_name##_doc} 00254 00255 #define KX_PYMETHODTABLE_NOARGS(class_name, method_name) \ 00256 {#method_name , (PyCFunction) class_name::sPy##method_name, METH_NOARGS, (const char *)class_name::method_name##_doc} 00257 00261 #define KX_PYMETHODDEF_DOC(class_name, method_name, doc_string) \ 00262 const char class_name::method_name##_doc[] = doc_string; \ 00263 PyObject* class_name::Py##method_name(PyObject* args, PyObject*) 00264 00265 #define KX_PYMETHODDEF_DOC_VARARGS(class_name, method_name, doc_string) \ 00266 const char class_name::method_name##_doc[] = doc_string; \ 00267 PyObject* class_name::Py##method_name(PyObject* args) 00268 00269 #define KX_PYMETHODDEF_DOC_O(class_name, method_name, doc_string) \ 00270 const char class_name::method_name##_doc[] = doc_string; \ 00271 PyObject* class_name::Py##method_name(PyObject* value) 00272 00273 #define KX_PYMETHODDEF_DOC_NOARGS(class_name, method_name, doc_string) \ 00274 const char class_name::method_name##_doc[] = doc_string; \ 00275 PyObject* class_name::Py##method_name() 00276 00280 enum KX_PYATTRIBUTE_TYPE { 00281 KX_PYATTRIBUTE_TYPE_BOOL, 00282 KX_PYATTRIBUTE_TYPE_ENUM, 00283 KX_PYATTRIBUTE_TYPE_SHORT, 00284 KX_PYATTRIBUTE_TYPE_INT, 00285 KX_PYATTRIBUTE_TYPE_FLOAT, 00286 KX_PYATTRIBUTE_TYPE_STRING, 00287 KX_PYATTRIBUTE_TYPE_DUMMY, 00288 KX_PYATTRIBUTE_TYPE_FUNCTION, 00289 KX_PYATTRIBUTE_TYPE_VECTOR, 00290 KX_PYATTRIBUTE_TYPE_FLAG, 00291 KX_PYATTRIBUTE_TYPE_CHAR, 00292 }; 00293 00294 enum KX_PYATTRIBUTE_ACCESS { 00295 KX_PYATTRIBUTE_RW, 00296 KX_PYATTRIBUTE_RO 00297 }; 00298 00299 struct KX_PYATTRIBUTE_DEF; 00300 typedef int (*KX_PYATTRIBUTE_CHECK_FUNCTION)(void *self, const struct KX_PYATTRIBUTE_DEF *attrdef); 00301 typedef int (*KX_PYATTRIBUTE_SET_FUNCTION)(void *self, const struct KX_PYATTRIBUTE_DEF *attrdef, PyObject *value); 00302 typedef PyObject* (*KX_PYATTRIBUTE_GET_FUNCTION)(void *self, const struct KX_PYATTRIBUTE_DEF *attrdef); 00303 00304 typedef struct KX_PYATTRIBUTE_DEF { 00305 const char *m_name; // name of the python attribute 00306 KX_PYATTRIBUTE_TYPE m_type; // type of value 00307 KX_PYATTRIBUTE_ACCESS m_access; // read/write access or read-only 00308 int m_imin; // minimum value in case of integer attributes 00309 // (for string: minimum string length, for flag: mask value, for float: matrix row size) 00310 int m_imax; // maximum value in case of integer attributes 00311 // (for string: maximum string length, for flag: 1 if flag is negative, float: vector/matrix col size) 00312 float m_fmin; // minimum value in case of float attributes 00313 float m_fmax; // maximum value in case of float attributes 00314 bool m_clamp; // enforce min/max value by clamping 00315 bool m_usePtr; // the attribute uses the proxy generic pointer, set at runtime 00316 size_t m_offset; // position of field in structure 00317 size_t m_size; // size of field for runtime verification (enum only) 00318 size_t m_length; // length of array, 1=simple attribute 00319 KX_PYATTRIBUTE_CHECK_FUNCTION m_checkFunction; // static function to check the assignment, returns 0 if no error 00320 KX_PYATTRIBUTE_SET_FUNCTION m_setFunction; // static function to check the assignment, returns 0 if no error 00321 KX_PYATTRIBUTE_GET_FUNCTION m_getFunction; // static function to check the assignment, returns 0 if no error 00322 00323 // The following pointers are just used to have compile time check for attribute type. 00324 // It would have been good to use a union but that would require C99 compatibility 00325 // to initialize specific union fields through designated initializers. 00326 struct { 00327 bool *m_boolPtr; 00328 short int *m_shortPtr; 00329 int *m_intPtr; 00330 float *m_floatPtr; 00331 STR_String *m_stringPtr; 00332 MT_Vector3 *m_vectorPtr; 00333 char *m_charPtr; 00334 } m_typeCheck; 00335 } PyAttributeDef; 00336 00337 #define KX_PYATTRIBUTE_BOOL_RW(name,object,field) \ 00338 { name, KX_PYATTRIBUTE_TYPE_BOOL, KX_PYATTRIBUTE_RW, 0, 1, 0.f, 0.f, false, false, offsetof(object,field), 0, 1, NULL, NULL, NULL, {&((object *)0)->field, NULL, NULL, NULL, NULL, NULL, NULL} } 00339 #define KX_PYATTRIBUTE_BOOL_RW_CHECK(name,object,field,function) \ 00340 { name, KX_PYATTRIBUTE_TYPE_BOOL, KX_PYATTRIBUTE_RW, 0, 1, 0.f, 0.f, false, false, offsetof(object,field), 0, 1, &object::function, NULL, NULL, {&((object *)0)->field, NULL, NULL, NULL, NULL, NULL, NULL} } 00341 #define KX_PYATTRIBUTE_BOOL_RO(name,object,field) \ 00342 { name, KX_PYATTRIBUTE_TYPE_BOOL, KX_PYATTRIBUTE_RO, 0, 1, 0.f, 0.f, false, false, offsetof(object,field), 0, 1, NULL, NULL, NULL, {&((object *)0)->field, NULL, NULL, NULL, NULL, NULL, NULL} } 00343 00344 /* attribute points to a single bit of an integer field, attribute=true if bit is set */ 00345 #define KX_PYATTRIBUTE_FLAG_RW(name,object,field,bit) \ 00346 { name, KX_PYATTRIBUTE_TYPE_FLAG, KX_PYATTRIBUTE_RW, bit, 0, 0.f, 0.f, false, false, offsetof(object,field), sizeof(((object *)0)->field), 1, NULL, NULL, NULL, {NULL, NULL, NULL, NULL, NULL, NULL, NULL} } 00347 #define KX_PYATTRIBUTE_FLAG_RW_CHECK(name,object,field,bit,function) \ 00348 { name, KX_PYATTRIBUTE_TYPE_FLAG, KX_PYATTRIBUTE_RW, bit, 0, 0.f, 0.f, false, false, offsetof(object,field), sizeof(((object *)0)->field), 1, &object::function, NULL, NULL, {NULL, NULL, NULL, NULL, NULL, NULL, NULL} } 00349 #define KX_PYATTRIBUTE_FLAG_RO(name,object,field,bit) \ 00350 { name, KX_PYATTRIBUTE_TYPE_FLAG, KX_PYATTRIBUTE_RO, bit, 0, 0.f, 0.f, false, false, offsetof(object,field), sizeof(((object *)0)->field), 1, NULL, NULL, NULL, {NULL, NULL, NULL, NULL, NULL, NULL, NULL} } 00351 00352 /* attribute points to a single bit of an integer field, attribute=true if bit is set*/ 00353 #define KX_PYATTRIBUTE_FLAG_NEGATIVE_RW(name,object,field,bit) \ 00354 { name, KX_PYATTRIBUTE_TYPE_FLAG, KX_PYATTRIBUTE_RW, bit, 1, 0.f, 0.f, false, false, offsetof(object,field), sizeof(((object *)0)->field), 1, NULL, NULL, NULL, {NULL, NULL, NULL, NULL, NULL, NULL, NULL} } 00355 #define KX_PYATTRIBUTE_FLAG_NEGATIVE_RW_CHECK(name,object,field,bit,function) \ 00356 { name, KX_PYATTRIBUTE_TYPE_FLAG, KX_PYATTRIBUTE_RW, bit, 1, 0.f, 0.f, false, false, offsetof(object,field), sizeof(((object *)0)->field), 1, &object::function, NULL, NULL, {NULL, NULL, NULL, NULL, NULL, NULL, NULL} } 00357 #define KX_PYATTRIBUTE_FLAG_NEGATIVE_RO(name,object,field,bit) \ 00358 { name, KX_PYATTRIBUTE_TYPE_FLAG, KX_PYATTRIBUTE_RO, bit, 1, 0.f, 0.f, false, false, offsetof(object,field), sizeof(((object *)0)->field), 1, NULL, NULL, NULL, {NULL, NULL, NULL, NULL, NULL, NULL, NULL} } 00359 00360 // enum field cannot be mapped to pointer (because we would need a pointer for each enum) 00361 // use field size to verify mapping at runtime only, assuming enum size is equal to int size. 00362 #define KX_PYATTRIBUTE_ENUM_RW(name,min,max,clamp,object,field) \ 00363 { name, KX_PYATTRIBUTE_TYPE_ENUM, KX_PYATTRIBUTE_RW, min, max, 0.f, 0.f, clamp, false, offsetof(object,field), sizeof(((object *)0)->field), 1, NULL, NULL, NULL, {NULL, NULL, NULL, NULL, NULL, NULL, NULL} } 00364 #define KX_PYATTRIBUTE_ENUM_RW_CHECK(name,min,max,clamp,object,field,function) \ 00365 { name, KX_PYATTRIBUTE_TYPE_ENUM, KX_PYATTRIBUTE_RW, min, max, 0.f, 0.f, clamp, false, offsetof(object,field), sizeof(((object *)0)->field), 1, &object::function, NULL, NULL, {NULL, NULL, NULL, NULL, NULL, NULL, NULL} } 00366 #define KX_PYATTRIBUTE_ENUM_RO(name,object,field) \ 00367 { name, KX_PYATTRIBUTE_TYPE_ENUM, KX_PYATTRIBUTE_RO, 0, 0, 0.f, 0.f, false, false, offsetof(object,field), sizeof(((object *)0)->field), 1, NULL, NULL, NULL, {NULL, NULL, NULL, NULL, NULL, NULL, NULL} } 00368 00369 #define KX_PYATTRIBUTE_SHORT_RW(name,min,max,clamp,object,field) \ 00370 { name, KX_PYATTRIBUTE_TYPE_SHORT, KX_PYATTRIBUTE_RW, min, max, 0.f, 0.f, clamp, false, offsetof(object,field), 0, 1, NULL, NULL, NULL, {NULL, &((object *)0)->field, NULL, NULL, NULL, NULL, NULL} } 00371 #define KX_PYATTRIBUTE_SHORT_RW_CHECK(name,min,max,clamp,object,field,function) \ 00372 { name, KX_PYATTRIBUTE_TYPE_SHORT, KX_PYATTRIBUTE_RW, min, max, 0.f, 0.f, clamp, false, offsetof(object,field), 0, 1, &object::function, NULL, NULL, {NULL, &((object *)0)->field, NULL, NULL, NULL, NULL, NULL} } 00373 #define KX_PYATTRIBUTE_SHORT_RO(name,object,field) \ 00374 { name, KX_PYATTRIBUTE_TYPE_SHORT, KX_PYATTRIBUTE_RO, 0, 0, 0.f, 0.f, false, false, offsetof(object,field), 0, 1, NULL, NULL, NULL, {NULL, &((object *)0)->field, NULL, NULL, NULL, NULL, NULL} } 00375 #define KX_PYATTRIBUTE_SHORT_ARRAY_RW(name,min,max,clamp,object,field,length) \ 00376 { name, KX_PYATTRIBUTE_TYPE_SHORT, KX_PYATTRIBUTE_RW, min, max, 0.f, 0.f, clamp, false, offsetof(object,field), 0, length, NULL, NULL, NULL, {NULL, ((object *)0)->field, NULL, NULL, NULL, NULL, NULL} } 00377 #define KX_PYATTRIBUTE_SHORT_ARRAY_RW_CHECK(name,min,max,clamp,object,field,length,function) \ 00378 { name, KX_PYATTRIBUTE_TYPE_SHORT, KX_PYATTRIBUTE_RW, min, max, 0.f, 0.f, clamp, false, offsetof(object,field), 0, length, &object::function, NULL, NULL, {NULL, ((object *)0)->field, NULL, NULL, NULL, NULL, NULL} } 00379 #define KX_PYATTRIBUTE_SHORT_ARRAY_RO(name,object,field,length) \ 00380 { name, KX_PYATTRIBUTE_TYPE_SHORT, KX_PYATTRIBUTE_RO, 0, 0, 0.f, 0.f, false, false, offsetof(object,field), 0, length, NULL, NULL, NULL, {NULL, ((object *)0)->field, NULL, NULL, NULL, NULL, NULL} } 00381 // SHORT_LIST 00382 #define KX_PYATTRIBUTE_SHORT_LIST_RW(name,min,max,clamp,object,field,length) \ 00383 { name, KX_PYATTRIBUTE_TYPE_SHORT, KX_PYATTRIBUTE_RW, min, max, 0.f, 0.f, clamp, false, offsetof(object,field), 0, length, NULL, NULL, NULL, {NULL, &((object *)0)->field, NULL, NULL, NULL, NULL, NULL} } 00384 #define KX_PYATTRIBUTE_SHORT_LIST_RW_CHECK(name,min,max,clamp,object,field,length,function) \ 00385 { name, KX_PYATTRIBUTE_TYPE_SHORT, KX_PYATTRIBUTE_RW, min, max, 0.f, 0.f, clamp, false, offsetof(object,field), 0, length, &object::function, NULL, NULL, {NULL, &((object *)0)->field, NULL, NULL, NULL, NULL, NULL} } 00386 #define KX_PYATTRIBUTE_SHORT_LIST_RO(name,object,field,length) \ 00387 { name, KX_PYATTRIBUTE_TYPE_SHORT, KX_PYATTRIBUTE_RO, 0, 0, 0.f, 0.f, false, false, offsetof(object,field), 0, length, NULL, NULL, NULL, {NULL, &((object *)0)->field, NULL, NULL, NULL, NULL, NULL} } 00388 00389 #define KX_PYATTRIBUTE_INT_RW(name,min,max,clamp,object,field) \ 00390 { name, KX_PYATTRIBUTE_TYPE_INT, KX_PYATTRIBUTE_RW, min, max, 0.f, 0.f, clamp, false, offsetof(object,field), 0, 1, NULL, NULL, NULL, {NULL, NULL, &((object *)0)->field, NULL, NULL, NULL, NULL} } 00391 #define KX_PYATTRIBUTE_INT_RW_CHECK(name,min,max,clamp,object,field,function) \ 00392 { name, KX_PYATTRIBUTE_TYPE_INT, KX_PYATTRIBUTE_RW, min, max, 0.f, 0.f, clamp, false, offsetof(object,field), 0, 1, &object::function, NULL, NULL, {NULL, NULL, &((object *)0)->field, NULL, NULL, NULL, NULL} } 00393 #define KX_PYATTRIBUTE_INT_RO(name,object,field) \ 00394 { name, KX_PYATTRIBUTE_TYPE_INT, KX_PYATTRIBUTE_RO, 0, 0, 0.f, 0.f, false, false, offsetof(object,field), 0, 1, NULL, NULL, NULL, {NULL, NULL, &((object *)0)->field, NULL, NULL, NULL, NULL} } 00395 #define KX_PYATTRIBUTE_INT_ARRAY_RW(name,min,max,clamp,object,field,length) \ 00396 { name, KX_PYATTRIBUTE_TYPE_INT, KX_PYATTRIBUTE_RW, min, max, 0.f, 0.f, clamp, false, offsetof(object,field), 0, length, NULL, NULL, NULL, {NULL, NULL, ((object *)0)->field, NULL, NULL, NULL, NULL} } 00397 #define KX_PYATTRIBUTE_INT_ARRAY_RW_CHECK(name,min,max,clamp,object,field,length,function) \ 00398 { name, KX_PYATTRIBUTE_TYPE_INT, KX_PYATTRIBUTE_RW, min, max, 0.f, 0.f, clamp, false, offsetof(object,field), 0, length, &object::function, NULL, NULL, {NULL, NULL, ((object *)0)->field, NULL, NULL, NULL, NULL} } 00399 #define KX_PYATTRIBUTE_INT_ARRAY_RO(name,object,field,length) \ 00400 { name, KX_PYATTRIBUTE_TYPE_INT, KX_PYATTRIBUTE_RO, 0, 0, 0.f, 0.f, false, false, offsetof(object,field), 0, length, NULL, NULL, NULL, {NULL, NULL, ((object *)0)->field, NULL, NULL, NULL, NULL} } 00401 // INT_LIST 00402 #define KX_PYATTRIBUTE_INT_LIST_RW(name,min,max,clamp,object,field,length) \ 00403 { name, KX_PYATTRIBUTE_TYPE_INT, KX_PYATTRIBUTE_RW, min, max, 0.f, 0.f, clamp, false, offsetof(object,field), 0, length, NULL, NULL, NULL, {NULL, NULL, &((object *)0)->field, NULL, NULL, NULL, NULL} } 00404 #define KX_PYATTRIBUTE_INT_LIST_RW_CHECK(name,min,max,clamp,object,field,length,function) \ 00405 { name, KX_PYATTRIBUTE_TYPE_INT, KX_PYATTRIBUTE_RW, min, max, 0.f, 0.f, clamp, false, offsetof(object,field), 0, length, &object::function, NULL, NULL, {NULL, NULL, &((object *)0)->field, NULL, NULL, NULL, NULL} } 00406 #define KX_PYATTRIBUTE_INT_LIST_RO(name,object,field,length) \ 00407 { name, KX_PYATTRIBUTE_TYPE_INT, KX_PYATTRIBUTE_RO, 0, 0, 0.f, 0.f, false, false, offsetof(object,field), 0, length, NULL, NULL, NULL, {NULL, NULL, &((object *)0)->field, NULL, NULL, NULL, NULL} } 00408 00409 // always clamp for float 00410 #define KX_PYATTRIBUTE_FLOAT_RW(name,min,max,object,field) \ 00411 { name, KX_PYATTRIBUTE_TYPE_FLOAT, KX_PYATTRIBUTE_RW, 0, 0, min, max, true, false, offsetof(object,field), 0, 1, NULL, NULL, NULL, {NULL, NULL, NULL, &((object *)0)->field, NULL, NULL, NULL} } 00412 #define KX_PYATTRIBUTE_FLOAT_RW_CHECK(name,min,max,object,field,function) \ 00413 { name, KX_PYATTRIBUTE_TYPE_FLOAT, KX_PYATTRIBUTE_RW, 0, 0, min, max, true, false, offsetof(object,field), 0, 1, &object::function, NULL, NULL, {NULL, NULL, NULL, &((object *)0)->field, NULL, NULL, NULL} } 00414 #define KX_PYATTRIBUTE_FLOAT_RO(name,object,field) \ 00415 { name, KX_PYATTRIBUTE_TYPE_FLOAT, KX_PYATTRIBUTE_RO, 0, 0, 0.f, 0.f, false, false, offsetof(object,field), 0, 1, NULL, NULL, NULL, {NULL, NULL, NULL, &((object *)0)->field, NULL, NULL, NULL} } 00416 // field must be float[n], returns a sequence 00417 #define KX_PYATTRIBUTE_FLOAT_ARRAY_RW(name,min,max,object,field,length) \ 00418 { name, KX_PYATTRIBUTE_TYPE_FLOAT, KX_PYATTRIBUTE_RW, 0, 0, min, max, true, false, offsetof(object,field), 0, length, NULL, NULL, NULL, {NULL, NULL, NULL, ((object *)0)->field, NULL, NULL, NULL} } 00419 #define KX_PYATTRIBUTE_FLOAT_ARRAY_RW_CHECK(name,min,max,object,field,length,function) \ 00420 { name, KX_PYATTRIBUTE_TYPE_FLOAT, KX_PYATTRIBUTE_RW, 0, 0, min, max, true, false, offsetof(object,field), 0, length, &object::function, NULL, NULL, {NULL, NULL, NULL, ((object *)0)->field, NULL, NULL, NULL} } 00421 #define KX_PYATTRIBUTE_FLOAT_ARRAY_RO(name,object,field,length) \ 00422 { name, KX_PYATTRIBUTE_TYPE_FLOAT, KX_PYATTRIBUTE_RO, 0, 0, 0.f, 0.f, false, false, offsetof(object,field), 0, length, NULL, NULL, NULL, {NULL, NULL, NULL, ((object *)0)->field, NULL, NULL, NULL} } 00423 // field must be float[n], returns a vector 00424 #define KX_PYATTRIBUTE_FLOAT_VECTOR_RW(name,min,max,object,field,length) \ 00425 { name, KX_PYATTRIBUTE_TYPE_FLOAT, KX_PYATTRIBUTE_RW, 0, length, min, max, true, false, offsetof(object,field), sizeof(((object *)0)->field), 1, NULL, NULL, NULL, {NULL, NULL, NULL, ((object *)0)->field, NULL, NULL, NULL} } 00426 #define KX_PYATTRIBUTE_FLOAT_VECTOR_RW_CHECK(name,min,max,object,field,length,function) \ 00427 { name, KX_PYATTRIBUTE_TYPE_FLOAT, KX_PYATTRIBUTE_RW, 0, length, min, max, true, false, offsetof(object,field), sizeof(((object *)0)->field), 1, &object::function, NULL, NULL, {NULL, NULL, NULL, ((object *)0)->field, NULL, NULL, NULL} } 00428 #define KX_PYATTRIBUTE_FLOAT_VECTOR_RO(name,object,field,length) \ 00429 { name, KX_PYATTRIBUTE_TYPE_FLOAT, KX_PYATTRIBUTE_RO, 0, length, 0.f, 0.f, false, false, offsetof(object,field), sizeof(((object *)0)->field), 1, NULL, NULL, NULL, {NULL, NULL, NULL, ((object *)0)->field, NULL, NULL, NULL} } 00430 // field must be float[n][n], returns a matrix 00431 #define KX_PYATTRIBUTE_FLOAT_MATRIX_RW(name,min,max,object,field,length) \ 00432 { name, KX_PYATTRIBUTE_TYPE_FLOAT, KX_PYATTRIBUTE_RW, length, length, min, max, true, false, offsetof(object,field), sizeof(((object *)0)->field), 1, NULL, NULL, NULL, {NULL, NULL, NULL, ((object *)0)->field[0], NULL, NULL, NULL} } 00433 #define KX_PYATTRIBUTE_FLOAT_MATRIX_RW_CHECK(name,min,max,object,field,length,function) \ 00434 { name, KX_PYATTRIBUTE_TYPE_FLOAT, KX_PYATTRIBUTE_RW, length, length, min, max, true, false, offsetof(object,field), sizeof(((object *)0)->field), 1, &object::function, NULL, NULL, {NULL, NULL, NULL, ((object *)0)->field[0], NULL, NULL, NULL} } 00435 #define KX_PYATTRIBUTE_FLOAT_MATRIX_RO(name,object,field,length) \ 00436 { name, KX_PYATTRIBUTE_TYPE_FLOAT, KX_PYATTRIBUTE_RO, length, length, 0.f, 0.f, false, false, offsetof(object,field), sizeof(((object *)0)->field), 1, NULL, NULL, NULL, {NULL, NULL, NULL, ((object *)0)->field[0], NULL, NULL, NULL} } 00437 00438 // only for STR_String member 00439 #define KX_PYATTRIBUTE_STRING_RW(name,min,max,clamp,object,field) \ 00440 { name, KX_PYATTRIBUTE_TYPE_STRING, KX_PYATTRIBUTE_RW, min, max, 0.f, 0.f, clamp, false, offsetof(object,field), 0, 1, NULL, NULL, NULL, {NULL, NULL, NULL, NULL, &((object *)0)->field, NULL, NULL} } 00441 #define KX_PYATTRIBUTE_STRING_RW_CHECK(name,min,max,clamp,object,field,function) \ 00442 { name, KX_PYATTRIBUTE_TYPE_STRING, KX_PYATTRIBUTE_RW, min, max, 0.f, 0.f, clamp, false, offsetof(object,field), 0, 1, &object::function, NULL, NULL, {NULL, NULL, NULL, NULL, &((object *)0)->field, NULL, NULL} } 00443 #define KX_PYATTRIBUTE_STRING_RO(name,object,field) \ 00444 { name, KX_PYATTRIBUTE_TYPE_STRING, KX_PYATTRIBUTE_RO, 0, 0, 0.f, 0.f, false, false, offsetof(object,field), 0, 1 , NULL, NULL, NULL, {NULL, NULL, NULL, NULL, &((object *)0)->field, NULL, NULL} } 00445 00446 // only for char [] array 00447 #define KX_PYATTRIBUTE_CHAR_RW(name,object,field) \ 00448 { name, KX_PYATTRIBUTE_TYPE_CHAR, KX_PYATTRIBUTE_RW, 0, 0, 0.f, 0.f, true, false, offsetof(object,field), sizeof(((object *)0)->field), 1, NULL, NULL, NULL, {NULL, NULL, NULL, NULL, NULL, NULL, ((object *)0)->field} } 00449 #define KX_PYATTRIBUTE_CHAR_RW_CHECK(name,object,field,function) \ 00450 { name, KX_PYATTRIBUTE_TYPE_CHAR, KX_PYATTRIBUTE_RW, 0, 0, 0.f, 0.f, true, false, offsetof(object,field), sizeof(((object *)0)->field), 1, &object::function, NULL, NULL, {NULL, NULL, NULL, NULL, NULL, NULL, ((object *)0)->field} } 00451 #define KX_PYATTRIBUTE_CHAR_RO(name,object,field) \ 00452 { name, KX_PYATTRIBUTE_TYPE_CHAR, KX_PYATTRIBUTE_RO, 0, 0, 0.f, 0.f, false, false, offsetof(object,field), sizeof(((object *)0)->field), 1 , NULL, NULL, NULL, {NULL, NULL, NULL, NULL, NULL, NULL, ((object *)0)->field} } 00453 00454 // for MT_Vector3 member 00455 #define KX_PYATTRIBUTE_VECTOR_RW(name,min,max,object,field) \ 00456 { name, KX_PYATTRIBUTE_TYPE_VECTOR, KX_PYATTRIBUTE_RW, 0, 0, min, max, true, false, offsetof(object,field), 0, 1, NULL, NULL, NULL, {NULL, NULL, NULL, NULL, NULL, &((object *)0)->field, NULL} } 00457 #define KX_PYATTRIBUTE_VECTOR_RW_CHECK(name,min,max,clamp,object,field,function) \ 00458 { name, KX_PYATTRIBUTE_TYPE_VECTOR, KX_PYATTRIBUTE_RW, 0, 0, min, max, true, false, offsetof(object,field), 0, 1, &object::function, NULL, NULL, {NULL, NULL, NULL, NULL, NULL, &((object *)0)->field, NULL} } 00459 #define KX_PYATTRIBUTE_VECTOR_RO(name,object,field) \ 00460 { name, KX_PYATTRIBUTE_TYPE_VECTOR, KX_PYATTRIBUTE_RO, 0, 0, 0.f, 0.f, false, false, offsetof(object,field), 0, 1 , NULL, NULL, NULL, {NULL, NULL, NULL, NULL, NULL, &((object *)0)->field, NULL} } 00461 00462 #define KX_PYATTRIBUTE_RW_FUNCTION(name,object,getfunction,setfunction) \ 00463 { name, KX_PYATTRIBUTE_TYPE_FUNCTION, KX_PYATTRIBUTE_RW, 0, 0, 0.f, 0.f, false, false, 0, 0, 1, NULL, &object::setfunction, &object::getfunction, {NULL, NULL, NULL, NULL, NULL, NULL, NULL} } 00464 #define KX_PYATTRIBUTE_RO_FUNCTION(name,object,getfunction) \ 00465 { name, KX_PYATTRIBUTE_TYPE_FUNCTION, KX_PYATTRIBUTE_RO, 0, 0, 0.f, 0.f, false, false, 0, 0, 1, NULL, NULL, &object::getfunction, {NULL, NULL, NULL, NULL, NULL, NULL, NULL} } 00466 #define KX_PYATTRIBUTE_ARRAY_RW_FUNCTION(name,object,length,getfunction,setfunction) \ 00467 { name, KX_PYATTRIBUTE_TYPE_FUNCTION, KX_PYATTRIBUTE_RW, 0, 0, 0.f, 0,f, false, false, 0, 0, length, NULL, &object::setfunction, &object::getfunction, {NULL, NULL, NULL, NULL, NULL, NULL, NULL} } 00468 #define KX_PYATTRIBUTE_ARRAY_RO_FUNCTION(name,object,length,getfunction) \ 00469 { name, KX_PYATTRIBUTE_TYPE_FUNCTION, KX_PYATTRIBUTE_RO, 0, 0, 0.f, 0,f, false, false, 0, 0, length, NULL, NULL, &object::getfunction, {NULL, NULL, NULL, NULL, NULL, NULL, NULL} } 00470 00471 00472 /*------------------------------ 00473 * PyObjectPlus 00474 ------------------------------*/ 00475 typedef PyTypeObject * PyParentObject; // Define the PyParent Object 00476 00477 #else // WITH_PYTHON 00478 00479 #ifdef WITH_CXX_GUARDEDALLOC 00480 #define Py_Header \ 00481 public: \ 00482 void *operator new(size_t num_bytes) { return MEM_mallocN(num_bytes, "GE:PyObjectPlus"); } \ 00483 void operator delete( void *mem ) { MEM_freeN(mem); } \ 00484 00485 #define Py_HeaderPtr \ 00486 public: \ 00487 void *operator new(size_t num_bytes) { return MEM_mallocN(num_bytes, "GE:PyObjectPlusPtr"); } \ 00488 void operator delete( void *mem ) { MEM_freeN(mem); } \ 00489 00490 #else // WITH_CXX_GUARDEDALLOC 00491 00492 #define Py_Header \ 00493 public: \ 00494 00495 #define Py_HeaderPtr \ 00496 public: \ 00497 00498 #endif // WITH_CXX_GUARDEDALLOC 00499 00500 #endif 00501 00502 00503 // By making SG_QList the ultimate parent for PyObjectPlus objects, it 00504 // allows to put them in 2 different dynamic lists at the same time 00505 // The use of these links is interesting because they free of memory allocation 00506 // but it's very important not to mess up with them. If you decide that 00507 // the SG_QList or SG_DList component is used for something for a certain class, 00508 // they cannot can be used for anything else at a parent level! 00509 // What these lists are and what they are used for must be carefully documented 00510 // at the level where they are used. 00511 // DON'T MAKE ANY USE OF THESE LIST AT THIS LEVEL, they are already used 00512 // at SCA_IActuator, SCA_ISensor, SCA_IController level which rules out the 00513 // possibility to use them at SCA_ILogicBrick, CValue and PyObjectPlus level. 00514 class PyObjectPlus : public SG_QList 00515 { // The PyObjectPlus abstract class 00516 Py_Header; // Always start with Py_Header 00517 00518 public: 00519 PyObjectPlus(); 00520 00521 virtual ~PyObjectPlus(); // destructor 00522 00523 #ifdef WITH_PYTHON 00524 PyObject *m_proxy; /* actually a PyObjectPlus_Proxy */ 00525 00526 /* These static functions are referenced by ALL PyObjectPlus_Proxy types 00527 * they take the C++ reference from the PyObjectPlus_Proxy and call 00528 * its own virtual py_repr, py_base_dealloc ,etc. functions. 00529 */ 00530 00531 static PyObject* py_base_new(PyTypeObject *type, PyObject *args, PyObject *kwds); /* allows subclassing */ 00532 static void py_base_dealloc(PyObject *self); 00533 static PyObject* py_base_repr(PyObject *self); 00534 00535 /* These are all virtual python methods that are defined in each class 00536 * Our own fake subclassing calls these on each class, then calls the parent */ 00537 virtual PyObject* py_repr(void); 00538 /* subclass may overwrite this function to implement more sophisticated method of validating a proxy */ 00539 virtual bool py_is_valid(void) { return true; } 00540 00541 static PyObject* py_get_attrdef(PyObject *self_py, const PyAttributeDef *attrdef); 00542 static int py_set_attrdef(PyObject *self_py, PyObject *value, const PyAttributeDef *attrdef); 00543 00544 /* Kindof dumb, always returns True, the false case is checked for, before this function gets accessed */ 00545 static PyObject* pyattr_get_invalid(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef); 00546 00547 static PyObject *GetProxyPlus_Ext(PyObjectPlus *self, PyTypeObject *tp, void *ptr); 00548 /* self=NULL => proxy to generic pointer detached from GE object 00549 if py_owns is true, the memory pointed by ptr will be deleted automatially with MEM_freeN 00550 self!=NULL=> proxy attached to GE object, ptr is optional and point to a struct from which attributes can be defined 00551 if py_owns is true, the object will be deleted automatically, ptr will NOT be deleted 00552 (assume object destructor takes care of it) */ 00553 static PyObject *NewProxyPlus_Ext(PyObjectPlus *self, PyTypeObject *tp, void *ptr, bool py_owns); 00554 00555 static WarnLink* GetDeprecationWarningLinkFirst(void); 00556 static WarnLink* GetDeprecationWarningLinkLast(void); 00557 static void SetDeprecationWarningFirst(WarnLink* wlink); 00558 static void SetDeprecationWarningLinkLast(WarnLink* wlink); 00559 static void NullDeprecationWarning(); 00560 00562 static void SetDeprecationWarnings(bool ignoreDeprecationWarnings); 00564 static void ShowDeprecationWarning_func(const char* method,const char* prop); 00565 static void ClearDeprecationWarning(); 00566 00567 #endif 00568 00569 void InvalidateProxy(); 00570 00574 virtual void ProcessReplica(); 00575 00576 static bool m_ignore_deprecation_warnings; 00577 }; 00578 00579 #ifdef WITH_PYTHON 00580 PyObject *py_getattr_dict(PyObject *pydict, PyObject *tp_dict); 00581 #endif 00582 00583 #endif // _adr_py_lib_h_