Panda3D
 All Classes Functions Variables Enumerations
physxObjectCollection.I
00001 // Filename: physxObjectCollection.I
00002 // Created by:  enn0x (08Nov09)
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 //     Function: PhysxObjectCollection<T>::size
00017 //       Access: Public
00018 //  Description:
00019 ////////////////////////////////////////////////////////////////////
00020 template <class T>
00021 INLINE unsigned int PhysxObjectCollection<T>::
00022 size() const {
00023 
00024   return _objects.size();
00025 }
00026 
00027 ////////////////////////////////////////////////////////////////////
00028 //     Function: PhysxObjectCollection<T>::add
00029 //       Access: Public
00030 //  Description:
00031 ////////////////////////////////////////////////////////////////////
00032 template <class T>
00033 INLINE void PhysxObjectCollection<T>::
00034 add(PT(T) object) {
00035 
00036   _objects.push_back(object);
00037 }
00038 
00039 ////////////////////////////////////////////////////////////////////
00040 //     Function: PhysxObjectCollection<T>::remove
00041 //       Access: Public
00042 //  Description:
00043 ////////////////////////////////////////////////////////////////////
00044 template <class T>
00045 INLINE void PhysxObjectCollection<T>::
00046 remove(PT(T) object) {
00047 
00048   typename pvector<PT(T)>::iterator it;
00049 
00050   it = find(_objects.begin(), _objects.end(), object);
00051   if (it != _objects.end()) {
00052     _objects.erase(it);
00053   }
00054   else
00055   {
00056     physx_cat.warning() << "object not found in collection" << endl;
00057   }
00058 }
00059 
00060 ////////////////////////////////////////////////////////////////////
00061 //     Function: PhysxObjectCollection<T>::get
00062 //       Access: Public
00063 //  Description: Returns the n-th PhysxObject in the collection.
00064 //               The operator [] is maybe a more convenient way to
00065 //               access objects from the collection.
00066 ////////////////////////////////////////////////////////////////////
00067 template <class T>
00068 INLINE T *PhysxObjectCollection<T>::
00069 get(unsigned int index) const {
00070 
00071   nassertr(index < _objects.size(), NULL);
00072   return _objects[index];
00073 }
00074 
00075 ////////////////////////////////////////////////////////////////////
00076 //     Function: PhysxObjectCollection<T>::operator []
00077 //       Access: Public
00078 //  Description: Returns the n-th PhysxObject in the collection.
00079 //               This is the same as the get() method.
00080 ////////////////////////////////////////////////////////////////////
00081 template <class T>
00082 INLINE T *PhysxObjectCollection<T>::
00083 operator [] (unsigned int index) const {
00084 
00085   nassertr(index < _objects.size(), NULL);
00086   return _objects[index];
00087 }
00088 
00089 ////////////////////////////////////////////////////////////////////
00090 //     Function: PhysxObjectCollection::ls
00091 //       Access: Public
00092 //  Description:
00093 ////////////////////////////////////////////////////////////////////
00094 template <class T>
00095 INLINE void PhysxObjectCollection<T>::
00096 ls() const {
00097 
00098   ls(nout);
00099 }
00100 
00101 ////////////////////////////////////////////////////////////////////
00102 //     Function: PhysxObjectCollection::ls
00103 //       Access: Public
00104 //  Description:
00105 ////////////////////////////////////////////////////////////////////
00106 template <class T>
00107 INLINE void PhysxObjectCollection<T>::
00108 ls(ostream &out, int indent_level) const {
00109 
00110   for (unsigned int i=0; i < size(); i++) {
00111     get(i)->ls(out, indent_level + 2);
00112   }
00113 }
00114 
 All Classes Functions Variables Enumerations