Panda3D

physxObject.I

00001 // Filename: physxObject.I
00002 // Created by:  enn0x (11Sep09)
00003 //
00004 ////////////////////////////////////////////////////////////////////
00005 //
00006 // PANDA 3D SOFTWARE
00007 // Copyright (c) Carnegie Mellon University.  All rights reserved.
00008 //
00009 // All use of this software is subject to the terms of the revised BSD
00010 // license.  You should have received a copy of this license along
00011 // with this source code in a file named "LICENSE."
00012 //
00013 ////////////////////////////////////////////////////////////////////
00014 
00015 
00016 
00017 ////////////////////////////////////////////////////////////////////
00018 //     Function: PhysxObject::Constructor
00019 //       Access: Published
00020 //  Description:
00021 ////////////////////////////////////////////////////////////////////
00022 INLINE PhysxObject::
00023 PhysxObject() {
00024 
00025   _error_type = ET_empty;
00026 }
00027 
00028 ////////////////////////////////////////////////////////////////////
00029 //     Function: PhysxObject::Destructor
00030 //       Access: Published
00031 //  Description:
00032 ////////////////////////////////////////////////////////////////////
00033 INLINE PhysxObject::
00034 ~PhysxObject() {
00035 
00036 #ifdef HAVE_PYTHON
00037   // Decrement the reference count of all
00038   // held Python objects.
00039   PythonTagData::const_iterator ti;
00040   for (ti = _python_tag_data.begin(); ti != _python_tag_data.end(); ++ti) {
00041     PyObject *value = (*ti).second;
00042     Py_XDECREF(value);
00043   }
00044 #endif // HAVE_PYTHON
00045 }
00046 
00047 #ifdef HAVE_PYTHON
00048 ////////////////////////////////////////////////////////////////////
00049 //     Function: PhysxObject::has_python_tags
00050 //       Access: Published
00051 //  Description: 
00052 ////////////////////////////////////////////////////////////////////
00053 INLINE bool PhysxObject::
00054 has_python_tags() const {
00055 
00056   return _python_tag_data.empty() ? false : true;
00057 }
00058 
00059 ////////////////////////////////////////////////////////////////////
00060 //     Function: PhysxObject::set_python_tag
00061 //       Access: Published
00062 //  Description: 
00063 ////////////////////////////////////////////////////////////////////
00064 INLINE void PhysxObject::
00065 set_python_tag(const string &key, PyObject *value) {
00066 
00067   Py_XINCREF(value);
00068 
00069   pair<PythonTagData::iterator, bool> result;
00070   result = _python_tag_data.insert(PythonTagData::value_type(key, value));
00071 
00072   if (!result.second) {
00073     // The insert was unsuccessful; that means the key was already
00074     // present in the map.  In this case, we should decrement the
00075     // original value's reference count and replace it with the new
00076     // object.
00077     PythonTagData::iterator ti = result.first;
00078     PyObject *old_value = (*ti).second;
00079     Py_XDECREF(old_value);
00080     (*ti).second = value;
00081   }
00082 }
00083 
00084 ////////////////////////////////////////////////////////////////////
00085 //     Function: PhysxObject::get_python_tag
00086 //       Access: Published
00087 //  Description: 
00088 ////////////////////////////////////////////////////////////////////
00089 INLINE PyObject *PhysxObject::
00090 get_python_tag(const string &key) const {
00091 
00092   PythonTagData::const_iterator ti;
00093   ti = _python_tag_data.find(key);
00094 
00095   if (ti != _python_tag_data.end()) {
00096     PyObject *result = (*ti).second;
00097     Py_XINCREF(result);
00098     return result;
00099   }
00100 
00101   Py_INCREF(Py_None);
00102   return Py_None;
00103 }
00104 
00105 ////////////////////////////////////////////////////////////////////
00106 //     Function: PhysxObject::has_python_tag
00107 //       Access: Published
00108 //  Description: 
00109 ////////////////////////////////////////////////////////////////////
00110 INLINE bool PhysxObject::
00111 has_python_tag(const string &key) const {
00112 
00113   PythonTagData::const_iterator ti;
00114   ti = _python_tag_data.find(key);
00115   return (ti != _python_tag_data.end());
00116 }
00117 
00118 ////////////////////////////////////////////////////////////////////
00119 //     Function: PhysxObject::clear_python_tag
00120 //       Access: Published
00121 //  Description: 
00122 ////////////////////////////////////////////////////////////////////
00123 INLINE void PhysxObject::
00124 clear_python_tag(const string &key) {
00125 
00126   PythonTagData::iterator ti;
00127   ti = _python_tag_data.find(key);
00128 
00129   if (ti != _python_tag_data.end()) {
00130     PyObject *value = (*ti).second;
00131     Py_XDECREF(value);
00132     _python_tag_data.erase(ti);
00133   }
00134 }
00135 #endif // HAVE_PYTHON
00136 
 All Classes Functions Variables Enumerations