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