Panda3D

pointerToArrayBase.h

00001 // Filename: pointerToArrayBase.h
00002 // Created by:  drose (30Oct06)
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 #ifndef POINTERTOARRAYBASE_H
00016 #define POINTERTOARRAYBASE_H
00017 
00018 #include "pandabase.h"
00019 #include "pStatCollectorForwardBase.h"
00020 #include "nodeReferenceCount.h"
00021 #include "pointerTo.h"
00022 #include "pvector.h"
00023 #include "memoryBase.h"
00024 
00025 ////////////////////////////////////////////////////////////////////
00026 //       Class : ReferenceCountedVector
00027 // Description : This defines the object that is actually stored and
00028 //               reference-counted internally by a PointerToArray.  It
00029 //               is basically a NodeReferenceCount-capable STL vector.
00030 //
00031 //               We use NodeReferenceCount (instead of just
00032 //               ReferenceCount), which adds node_ref() and
00033 //               node_unref() to the standard ref() and unref().  This
00034 //               is particularly useful for GeomVertexArrayData; other
00035 //               classes may or may not find this additional counter
00036 //               useful, but since it adds relatively little overhead
00037 //               (compared with what is presumably a largish array),
00038 //               we go ahead and add it here, even though it is
00039 //               inherited by many different parts of the system that
00040 //               may not use it.
00041 ////////////////////////////////////////////////////////////////////
00042 template <class Element>
00043 class ReferenceCountedVector : public NodeReferenceCount, public pvector<Element> {
00044 public:
00045   typedef TYPENAME pvector<Element>::iterator iterator;
00046   typedef TYPENAME pvector<Element>::size_type size_type;
00047 
00048   INLINE ReferenceCountedVector(TypeHandle type_handle);
00049   INLINE ReferenceCountedVector(const ReferenceCountedVector<Element> &copy);
00050   INLINE ReferenceCountedVector(size_type initial_size, TypeHandle type_handle);
00051   INLINE ~ReferenceCountedVector();
00052   ALLOC_DELETED_CHAIN(ReferenceCountedVector<Element>);
00053 
00054   INLINE size_type size() const;
00055 
00056   INLINE iterator insert(iterator position, const Element &x);
00057   INLINE void insert(iterator position, size_type n, const Element &x);
00058 
00059   INLINE void erase(iterator position);
00060   INLINE void erase(iterator first, iterator last);
00061 
00062   INLINE void pop_back();
00063   INLINE void clear();
00064 };
00065 
00066 ////////////////////////////////////////////////////////////////////
00067 //       Class : PointerToArrayBase
00068 // Description : This is the base class for PointerToArray and
00069 //               ConstPointerToArray.  Don't try to use it directly;
00070 //               use either derived class instead.
00071 //
00072 //               This extends PointerToBase to be a pointer to a
00073 //               ReferenceCountedVector, above, which is essentially a
00074 //               reference-counted STL vector.
00075 ////////////////////////////////////////////////////////////////////
00076 template <class Element>
00077 class PointerToArrayBase : public PointerToBase<ReferenceCountedVector<Element> > {
00078 public:
00079   typedef TYPENAME PointerToBase<ReferenceCountedVector<Element> >::To To;
00080 
00081 protected:
00082   INLINE PointerToArrayBase(ReferenceCountedVector<Element> *ptr);
00083   INLINE PointerToArrayBase(const PointerToArrayBase<Element> &copy);
00084 
00085 PUBLISHED:
00086   INLINE ~PointerToArrayBase();
00087 };
00088 
00089 #include "pointerToArrayBase.I"
00090 
00091 #endif
00092 
 All Classes Functions Variables Enumerations