Panda3D
pointerToArrayBase.h
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 pointerToArrayBase.h
10  * @author drose
11  * @date 2006-10-30
12  */
13 
14 #ifndef POINTERTOARRAYBASE_H
15 #define POINTERTOARRAYBASE_H
16 
17 #include "pandabase.h"
19 #include "nodeReferenceCount.h"
20 #include "pointerTo.h"
21 #include "pvector.h"
22 #include "memoryBase.h"
23 
24 /**
25  * This defines the object that is actually stored and reference-counted
26  * internally by a PointerToArray. It is basically a NodeReferenceCount-
27  * capable STL vector.
28  *
29  * We use NodeReferenceCount (instead of just ReferenceCount), which adds
30  * node_ref() and node_unref() to the standard ref() and unref(). This is
31  * particularly useful for GeomVertexArrayData; other classes may or may not
32  * find this additional counter useful, but since it adds relatively little
33  * overhead (compared with what is presumably a largish array), we go ahead
34  * and add it here, even though it is inherited by many different parts of the
35  * system that may not use it.
36  */
37 template <class Element>
38 class ReferenceCountedVector : public NodeReferenceCount, public pvector<Element> {
39 public:
40  typedef typename pvector<Element>::iterator iterator;
41  typedef typename pvector<Element>::size_type size_type;
42 
43  INLINE ReferenceCountedVector(TypeHandle type_handle);
44  INLINE ReferenceCountedVector(size_type initial_size, TypeHandle type_handle);
45  INLINE ReferenceCountedVector(const Element *begin, const Element *end, TypeHandle type_handle);
47  ALLOC_DELETED_CHAIN(ReferenceCountedVector<Element>);
48 
49  INLINE size_type size() const;
50 
51  INLINE iterator insert(iterator position, const Element &x);
52  INLINE void insert(iterator position, size_type n, const Element &x);
53 
54  INLINE void erase(iterator position);
55  INLINE void erase(iterator first, iterator last);
56 
57  INLINE void pop_back();
58  INLINE void clear();
59 };
60 
61 /**
62  * This is the base class for PointerToArray and ConstPointerToArray. Don't
63  * try to use it directly; use either derived class instead.
64  *
65  * This extends PointerToBase to be a pointer to a ReferenceCountedVector,
66  * above, which is essentially a reference-counted STL vector.
67  */
68 template <class Element>
69 class PointerToArrayBase : public PointerToBase<ReferenceCountedVector<Element> > {
70 public:
71  typedef typename PointerToBase<ReferenceCountedVector<Element> >::To To;
72 
73 protected:
76  INLINE PointerToArrayBase(PointerToArrayBase<Element> &&from) noexcept;
77 
78 PUBLISHED:
79  INLINE ~PointerToArrayBase();
80 };
81 
82 #include "pointerToArrayBase.I"
83 
84 #endif
This is the base class for PointerTo and ConstPointerTo.
Definition: pointerToBase.h:29
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
This class specializes ReferenceCount to add an additional counter, called node_ref_count,...
This is our own Panda specialization on the default STL vector.
Definition: pvector.h:42
This is the base class for PointerToArray and ConstPointerToArray.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
TypeHandle is the identifier used to differentiate C++ class types.
Definition: typeHandle.h:81
This defines the object that is actually stored and reference-counted internally by a PointerToArray.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.