Panda3D
physxObject.I
1 // Filename: physxObject.I
2 // Created by: enn0x (11Sep09)
3 //
4 ////////////////////////////////////////////////////////////////////
5 //
6 // PANDA 3D SOFTWARE
7 // Copyright (c) Carnegie Mellon University. All rights reserved.
8 //
9 // All use of this software is subject to the terms of the revised BSD
10 // license. You should have received a copy of this license along
11 // with this source code in a file named "LICENSE."
12 //
13 ////////////////////////////////////////////////////////////////////
14 
15 
16 
17 ////////////////////////////////////////////////////////////////////
18 // Function: PhysxObject::Constructor
19 // Access: Published
20 // Description:
21 ////////////////////////////////////////////////////////////////////
22 INLINE PhysxObject::
23 PhysxObject() {
24 
25  _error_type = ET_empty;
26 }
27 
28 ////////////////////////////////////////////////////////////////////
29 // Function: PhysxObject::Destructor
30 // Access: Published
31 // Description:
32 ////////////////////////////////////////////////////////////////////
33 INLINE PhysxObject::
34 ~PhysxObject() {
35 
36 #ifdef HAVE_PYTHON
37  // Decrement the reference count of all
38  // held Python objects.
39  PythonTagData::const_iterator ti;
40  for (ti = _python_tag_data.begin(); ti != _python_tag_data.end(); ++ti) {
41  PyObject *value = (*ti).second;
42  Py_XDECREF(value);
43  }
44 #endif // HAVE_PYTHON
45 }
46 
47 #ifdef HAVE_PYTHON
48 ////////////////////////////////////////////////////////////////////
49 // Function: PhysxObject::has_python_tags
50 // Access: Published
51 // Description:
52 ////////////////////////////////////////////////////////////////////
53 INLINE bool PhysxObject::
54 has_python_tags() const {
55 
56  return _python_tag_data.empty() ? false : true;
57 }
58 
59 ////////////////////////////////////////////////////////////////////
60 // Function: PhysxObject::set_python_tag
61 // Access: Published
62 // Description:
63 ////////////////////////////////////////////////////////////////////
64 INLINE void PhysxObject::
65 set_python_tag(const string &key, PyObject *value) {
66 
67  Py_XINCREF(value);
68 
69  pair<PythonTagData::iterator, bool> result;
70  result = _python_tag_data.insert(PythonTagData::value_type(key, value));
71 
72  if (!result.second) {
73  // The insert was unsuccessful; that means the key was already
74  // present in the map. In this case, we should decrement the
75  // original value's reference count and replace it with the new
76  // object.
77  PythonTagData::iterator ti = result.first;
78  PyObject *old_value = (*ti).second;
79  Py_XDECREF(old_value);
80  (*ti).second = value;
81  }
82 }
83 
84 ////////////////////////////////////////////////////////////////////
85 // Function: PhysxObject::get_python_tag
86 // Access: Published
87 // Description:
88 ////////////////////////////////////////////////////////////////////
89 INLINE PyObject *PhysxObject::
90 get_python_tag(const string &key) const {
91 
92  PythonTagData::const_iterator ti;
93  ti = _python_tag_data.find(key);
94 
95  if (ti != _python_tag_data.end()) {
96  PyObject *result = (*ti).second;
97  Py_XINCREF(result);
98  return result;
99  }
100 
101  Py_INCREF(Py_None);
102  return Py_None;
103 }
104 
105 ////////////////////////////////////////////////////////////////////
106 // Function: PhysxObject::has_python_tag
107 // Access: Published
108 // Description:
109 ////////////////////////////////////////////////////////////////////
110 INLINE bool PhysxObject::
111 has_python_tag(const string &key) const {
112 
113  PythonTagData::const_iterator ti;
114  ti = _python_tag_data.find(key);
115  return (ti != _python_tag_data.end());
116 }
117 
118 ////////////////////////////////////////////////////////////////////
119 // Function: PhysxObject::clear_python_tag
120 // Access: Published
121 // Description:
122 ////////////////////////////////////////////////////////////////////
123 INLINE void PhysxObject::
124 clear_python_tag(const string &key) {
125 
126  PythonTagData::iterator ti;
127  ti = _python_tag_data.find(key);
128 
129  if (ti != _python_tag_data.end()) {
130  PyObject *value = (*ti).second;
131  Py_XDECREF(value);
132  _python_tag_data.erase(ti);
133  }
134 }
135 #endif // HAVE_PYTHON
136