Panda3D
physxObjectCollection.I
1 // Filename: physxObjectCollection.I
2 // Created by: enn0x (08Nov09)
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 // Function: PhysxObjectCollection<T>::size
17 // Access: Public
18 // Description:
19 ////////////////////////////////////////////////////////////////////
20 template <class T>
21 INLINE unsigned int PhysxObjectCollection<T>::
22 size() const {
23 
24  return _objects.size();
25 }
26 
27 ////////////////////////////////////////////////////////////////////
28 // Function: PhysxObjectCollection<T>::add
29 // Access: Public
30 // Description:
31 ////////////////////////////////////////////////////////////////////
32 template <class T>
34 add(PT(T) object) {
35 
36  _objects.push_back(object);
37 }
38 
39 ////////////////////////////////////////////////////////////////////
40 // Function: PhysxObjectCollection<T>::remove
41 // Access: Public
42 // Description:
43 ////////////////////////////////////////////////////////////////////
44 template <class T>
46 remove(PT(T) object) {
47 
48  typename pvector<PT(T)>::iterator it;
49 
50  it = find(_objects.begin(), _objects.end(), object);
51  if (it != _objects.end()) {
52  _objects.erase(it);
53  }
54  else
55  {
56  physx_cat.warning() << "object not found in collection" << endl;
57  }
58 }
59 
60 ////////////////////////////////////////////////////////////////////
61 // Function: PhysxObjectCollection<T>::get
62 // Access: Public
63 // Description: Returns the n-th PhysxObject in the collection.
64 // The operator [] is maybe a more convenient way to
65 // access objects from the collection.
66 ////////////////////////////////////////////////////////////////////
67 template <class T>
69 get(unsigned int index) const {
70 
71  nassertr(index < _objects.size(), NULL);
72  return _objects[index];
73 }
74 
75 ////////////////////////////////////////////////////////////////////
76 // Function: PhysxObjectCollection<T>::operator []
77 // Access: Public
78 // Description: Returns the n-th PhysxObject in the collection.
79 // This is the same as the get() method.
80 ////////////////////////////////////////////////////////////////////
81 template <class T>
83 operator [] (unsigned int index) const {
84 
85  nassertr(index < _objects.size(), NULL);
86  return _objects[index];
87 }
88 
89 ////////////////////////////////////////////////////////////////////
90 // Function: PhysxObjectCollection::ls
91 // Access: Public
92 // Description:
93 ////////////////////////////////////////////////////////////////////
94 template <class T>
96 ls() const {
97 
98  ls(nout);
99 }
100 
101 ////////////////////////////////////////////////////////////////////
102 // Function: PhysxObjectCollection::ls
103 // Access: Public
104 // Description:
105 ////////////////////////////////////////////////////////////////////
106 template <class T>
107 INLINE void PhysxObjectCollection<T>::
108 ls(ostream &out, int indent_level) const {
109 
110  for (unsigned int i=0; i < size(); i++) {
111  get(i)->ls(out, indent_level + 2);
112  }
113 }
114 
T * get(unsigned int index) const
Returns the n-th PhysxObject in the collection.
This is our own Panda specialization on the default STL vector.
Definition: pvector.h:39
T * operator[](unsigned int index) const
Returns the n-th PhysxObject in the collection.