Panda3D
 All Classes Functions Variables Enumerations
pointerToArrayBase.h
1 // Filename: pointerToArrayBase.h
2 // Created by: drose (30Oct06)
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 #ifndef POINTERTOARRAYBASE_H
16 #define POINTERTOARRAYBASE_H
17 
18 #include "pandabase.h"
19 #include "pStatCollectorForwardBase.h"
20 #include "nodeReferenceCount.h"
21 #include "pointerTo.h"
22 #include "pvector.h"
23 #include "memoryBase.h"
24 
25 ////////////////////////////////////////////////////////////////////
26 // Class : ReferenceCountedVector
27 // Description : This defines the object that is actually stored and
28 // reference-counted internally by a PointerToArray. It
29 // is basically a NodeReferenceCount-capable STL vector.
30 //
31 // We use NodeReferenceCount (instead of just
32 // ReferenceCount), which adds node_ref() and
33 // node_unref() to the standard ref() and unref(). This
34 // is particularly useful for GeomVertexArrayData; other
35 // classes may or may not find this additional counter
36 // useful, but since it adds relatively little overhead
37 // (compared with what is presumably a largish array),
38 // we go ahead and add it here, even though it is
39 // inherited by many different parts of the system that
40 // may not use it.
41 ////////////////////////////////////////////////////////////////////
42 template <class Element>
43 class ReferenceCountedVector : public NodeReferenceCount, public pvector<Element> {
44 public:
45  typedef TYPENAME pvector<Element>::iterator iterator;
46  typedef TYPENAME pvector<Element>::size_type size_type;
47 
48  INLINE ReferenceCountedVector(TypeHandle type_handle);
49  INLINE ReferenceCountedVector(const ReferenceCountedVector<Element> &copy);
50  INLINE ReferenceCountedVector(size_type initial_size, TypeHandle type_handle);
51  INLINE ~ReferenceCountedVector();
52  ALLOC_DELETED_CHAIN(ReferenceCountedVector<Element>);
53 
54  INLINE size_type size() const;
55 
56  INLINE iterator insert(iterator position, const Element &x);
57  INLINE void insert(iterator position, size_type n, const Element &x);
58 
59  INLINE void erase(iterator position);
60  INLINE void erase(iterator first, iterator last);
61 
62  INLINE void pop_back();
63  INLINE void clear();
64 };
65 
66 ////////////////////////////////////////////////////////////////////
67 // Class : PointerToArrayBase
68 // Description : This is the base class for PointerToArray and
69 // ConstPointerToArray. Don't try to use it directly;
70 // use either derived class instead.
71 //
72 // This extends PointerToBase to be a pointer to a
73 // ReferenceCountedVector, above, which is essentially a
74 // reference-counted STL vector.
75 ////////////////////////////////////////////////////////////////////
76 template <class Element>
77 class PointerToArrayBase : public PointerToBase<ReferenceCountedVector<Element> > {
78 public:
79  typedef TYPENAME PointerToBase<ReferenceCountedVector<Element> >::To To;
80 
81 protected:
83  INLINE PointerToArrayBase(const PointerToArrayBase<Element> &copy);
84 
85 #ifdef USE_MOVE_SEMANTICS
86  INLINE PointerToArrayBase(PointerToArrayBase<Element> &&from) NOEXCEPT;
87 #endif
88 
89 PUBLISHED:
90  INLINE ~PointerToArrayBase();
91 };
92 
93 #include "pointerToArrayBase.I"
94 
95 #endif
96 
This is the base class for PointerTo and ConstPointerTo.
Definition: pointerToBase.h:32
This class specializes ReferenceCount to add an additional counter, called node_ref_count, for the purposes of counting the number of times the object is referenced by a &quot;node&quot;, whatever that may mean in context.
This is our own Panda specialization on the default STL vector.
Definition: pvector.h:39
This is the base class for PointerToArray and ConstPointerToArray.
TypeHandle is the identifier used to differentiate C++ class types.
Definition: typeHandle.h:85
This defines the object that is actually stored and reference-counted internally by a PointerToArray...