Changed Python _getattr/_setattr methods to use const STR_String& instead of char...
[blender.git] / source / gameengine / Ketsji / KX_ConstraintWrapper.cpp
1 /**
2  * $Id$
3  *
4  * ***** BEGIN GPL/BL DUAL LICENSE BLOCK *****
5  *
6  * This program is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License
8  * as published by the Free Software Foundation; either version 2
9  * of the License, or (at your option) any later version. The Blender
10  * Foundation also sells licenses for use in proprietary software under
11  * the Blender License.  See http://www.blender.org/BL/ for information
12  * about this.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with this program; if not, write to the Free Software Foundation,
21  * Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
22  *
23  * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
24  * All rights reserved.
25  *
26  * The Original Code is: all of this file.
27  *
28  * Contributor(s): none yet.
29  *
30  * ***** END GPL/BL DUAL LICENSE BLOCK *****
31  */
32 #include <Python.h>
33 #include "KX_ConstraintWrapper.h"
34 #include "PHY_IPhysicsEnvironment.h"
35
36 #ifdef HAVE_CONFIG_H
37 #include <config.h>
38 #endif
39
40 KX_ConstraintWrapper::KX_ConstraintWrapper(
41                                                 PHY_ConstraintType ctype,
42                                                 int constraintId,
43                                                 PHY_IPhysicsEnvironment* physenv,PyTypeObject *T) :
44                 PyObjectPlus(T),
45                 m_constraintId(constraintId),
46                 m_constraintType(ctype),
47                 m_physenv(physenv)
48 {
49 }
50 KX_ConstraintWrapper::~KX_ConstraintWrapper()
51 {
52 }
53 //python integration methods
54 PyObject* KX_ConstraintWrapper::PyTestMethod(PyObject* self, 
55                                                                                         PyObject* args, 
56                                                                                         PyObject* kwds)
57 {
58         
59         Py_INCREF(Py_None);
60         return Py_None;
61 }
62
63 PyObject* KX_ConstraintWrapper::PyGetConstraintId(PyObject* self, 
64                                                                                         PyObject* args, 
65                                                                                         PyObject* kwds)
66 {
67         return PyInt_FromLong(m_constraintId);
68 }
69
70
71
72
73 //python specific stuff
74 PyTypeObject KX_ConstraintWrapper::Type = {
75         PyObject_HEAD_INIT(&PyType_Type)
76                 0,
77                 "KX_ConstraintWrapper",
78                 sizeof(KX_ConstraintWrapper),
79                 0,
80                 PyDestructor,
81                 0,
82                 __getattr,
83                 __setattr,
84                 0, //&MyPyCompare,
85                 __repr,
86                 0, //&cvalue_as_number,
87                 0,
88                 0,
89                 0,
90                 0
91 };
92
93 PyParentObject KX_ConstraintWrapper::Parents[] = {
94         &KX_ConstraintWrapper::Type,
95         NULL
96 };
97
98 PyObject*       KX_ConstraintWrapper::_getattr(const STR_String& attr)
99 {
100         //here you can search for existing data members (like mass,friction etc.)
101         _getattr_up(PyObjectPlus);
102 }
103
104 int     KX_ConstraintWrapper::_setattr(const STR_String& attr,PyObject* pyobj)
105 {
106         
107         PyTypeObject* type = pyobj->ob_type;
108         int result = 1;
109
110         if (type == &PyList_Type)
111         {
112                 result = 0;
113         }
114         if (type == &PyFloat_Type)
115         {
116                 result = 0;
117
118         }
119         if (type == &PyInt_Type)
120         {
121                 result = 0;
122         }
123         if (type == &PyString_Type)
124         {
125                 result = 0;
126         }
127         if (result)
128                 result = PyObjectPlus::_setattr(attr,pyobj);
129         return result;
130 };
131
132
133 PyMethodDef KX_ConstraintWrapper::Methods[] = {
134         {"testMethod",(PyCFunction) KX_ConstraintWrapper::sPyTestMethod, METH_VARARGS},
135         {"getConstraintId",(PyCFunction) KX_ConstraintWrapper::sPyGetConstraintId, METH_VARARGS},
136         {NULL,NULL} //Sentinel
137 };