Blender V2.61 - r43446
|
00001 /* 00002 ----------------------------------------------------------------------------- 00003 This source file is part of VideoTexture library 00004 00005 Copyright (c) 2006 The Zdeno Ash Miklas 00006 00007 This program is free software; you can redistribute it and/or modify it under 00008 the terms of the GNU Lesser General Public License as published by the Free Software 00009 Foundation; either version 2 of the License, or (at your option) any later 00010 version. 00011 00012 This program is distributed in the hope that it will be useful, but WITHOUT 00013 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 00014 FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. 00015 00016 You should have received a copy of the GNU Lesser General Public License along with 00017 this program; if not, write to the Free Software Foundation, Inc., 59 Temple 00018 Place - Suite 330, Boston, MA 02111-1307, USA, or go to 00019 http://www.gnu.org/copyleft/lesser.txt. 00020 ----------------------------------------------------------------------------- 00021 */ 00022 00027 #if !defined BLENDTYPE_H 00028 #define BLENDTYPE_H 00029 00030 00033 template <class PyObj> class BlendType 00034 { 00035 public: 00037 BlendType (const char * name) : m_name(name) {} 00038 00040 PyObj * checkType (PyObject * obj) 00041 { 00042 // if pointer to type isn't set 00043 if (m_objType == NULL) 00044 { 00045 // compare names of type 00046 if (strcmp(Py_TYPE(obj)->tp_name, m_name) == 0) 00047 // if name of type match, save pointer to type 00048 m_objType = Py_TYPE(obj); 00049 else 00050 // if names of type don't match, return NULL 00051 return NULL; 00052 } 00053 // if pointer to type is set and don't match to type of provided object, return NULL 00054 else if (Py_TYPE(obj) != m_objType) 00055 return NULL; 00056 // return pointer to object, this class can only be used for KX object => 00057 // the Py object is actually a proxy 00058 return (PyObj*)BGE_PROXY_REF(obj); 00059 } 00060 00062 PyObj * parseArg (PyObject * args) 00063 { 00064 // parse arguments 00065 PyObject * obj; 00066 if (PyArg_ParseTuple(args, "O", &obj)) 00067 // if successfully parsed, return pointer to object 00068 return checkType(obj); 00069 // otherwise return NULL 00070 return NULL; 00071 } 00072 00073 protected: 00075 const char * m_name; 00077 PyTypeObject * m_objType; 00078 }; 00079 00080 00081 #endif