2 -----------------------------------------------------------------------------
3 This source file is part of VideoTexture library
5 Copyright (c) 2006 The Zdeno Ash Miklas
7 This program is free software; you can redistribute it and/or modify it under
8 the terms of the GNU Lesser General Public License as published by the Free Software
9 Foundation; either version 2 of the License, or (at your option) any later
12 This program is distributed in the hope that it will be useful, but WITHOUT
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
14 FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
16 You should have received a copy of the GNU Lesser General Public License along with
17 this program; if not, write to the Free Software Foundation, Inc., 59 Temple
18 Place - Suite 330, Boston, MA 02111-1307, USA, or go to
19 http://www.gnu.org/copyleft/lesser.txt.
20 -----------------------------------------------------------------------------
23 #if !defined BLENDTYPE_H
27 /// class allows check type of blender python object and access its contained object
28 /// MUST ONLY BE USED FOR KX classes that are descendent of PyObjectPlus
29 template <class PyObj> class BlendType
33 BlendType (char * name) : m_name(name) {}
35 /// check blender type and return pointer to contained object or NULL (if type is not valid)
36 PyObj * checkType (PyObject * obj)
38 // if pointer to type isn't set
39 if (m_objType == NULL)
41 // compare names of type
42 if (strcmp(obj->ob_type->tp_name, m_name) == 0)
43 // if name of type match, save pointer to type
44 m_objType = obj->ob_type;
46 // if names of type don't match, return NULL
49 // if pointer to type is set and don't match to type of provided object, return NULL
50 else if (obj->ob_type != m_objType)
52 // return pointer to object, this class can only be used for KX object =>
53 // the Py object is actually a proxy
54 return (PyObj*)BGE_PROXY_REF(obj);
57 /// parse arguments to get object
58 PyObj * parseArg (PyObject * args)
62 if (PyArg_ParseTuple(args, "O", &obj))
63 // if successfully parsed, return pointer to object
64 return checkType(obj);
65 // otherwise return NULL
70 /// name of Python type
72 /// pointer to Python type
73 PyTypeObject * m_objType;