pointerToArrayBase.h 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. // Filename: pointerToArrayBase.h
  2. // Created by: drose (30Oct06)
  3. //
  4. ////////////////////////////////////////////////////////////////////
  5. //
  6. // PANDA 3D SOFTWARE
  7. // Copyright (c) 2001 - 2004, Disney Enterprises, Inc. All rights reserved
  8. //
  9. // All use of this software is subject to the terms of the Panda 3d
  10. // Software license. You should have received a copy of this license
  11. // along with this source code; you will also find a current copy of
  12. // the license at http://etc.cmu.edu/panda3d/docs/license/ .
  13. //
  14. // To contact the maintainers of this program write to
  15. // [email protected] .
  16. //
  17. ////////////////////////////////////////////////////////////////////
  18. #ifndef POINTERTOARRAYBASE_H
  19. #define POINTERTOARRAYBASE_H
  20. #include "pandabase.h"
  21. #include "pStatCollectorForwardBase.h"
  22. #include "nodeReferenceCount.h"
  23. #include "pointerTo.h"
  24. #include "pvector.h"
  25. #include "memoryBase.h"
  26. ////////////////////////////////////////////////////////////////////
  27. // Class : PointerToArrayElement
  28. // Description : This defines the object that is actually stored and
  29. // reference-counted internally by a PointerToArray. It
  30. // is basically a NodeReferenceCount-capable STL vector.
  31. //
  32. // We use NodeReferenceCount (instead of just
  33. // ReferenceCount), which adds node_ref() and
  34. // node_unref() to the standard ref() and unref(). This
  35. // is particularly useful for GeomVertexArrayData; other
  36. // classes may or may not find this additional counter
  37. // useful, but since it adds relatively little overhead
  38. // (compared with what is presumably a largish array),
  39. // we go ahead and add it here, even though it is
  40. // inherited by many different parts of the system that
  41. // may not use it.
  42. ////////////////////////////////////////////////////////////////////
  43. template <class Element>
  44. class PointerToArrayElement : public NodeReferenceCount, public pvector<Element> {
  45. public:
  46. typedef TYPENAME pvector<Element>::iterator iterator;
  47. typedef TYPENAME pvector<Element>::size_type size_type;
  48. INLINE PointerToArrayElement();
  49. INLINE PointerToArrayElement(const PointerToArrayElement<Element> &copy);
  50. INLINE ~PointerToArrayElement();
  51. ALLOC_DELETED_CHAIN(PointerToArrayElement<Element>);
  52. INLINE PStatCollectorForwardBase *get_col() const;
  53. INLINE void set_col(PStatCollectorForwardBase *col);
  54. INLINE size_type size() const;
  55. INLINE iterator insert(iterator position, const Element &x);
  56. INLINE void insert(iterator position, size_type n, const Element &x);
  57. INLINE void erase(iterator position);
  58. INLINE void erase(iterator first, iterator last);
  59. INLINE void pop_back();
  60. INLINE void clear();
  61. private:
  62. INLINE void adjust_size(size_t orig_size, size_t new_size);
  63. #ifdef DO_PSTATS
  64. PT(PStatCollectorForwardBase) _col;
  65. #endif
  66. };
  67. ////////////////////////////////////////////////////////////////////
  68. // Class : PointerToArrayBase
  69. // Description : This is the base class for PointerToArray and
  70. // ConstPointerToArray. Don't try to use it directly;
  71. // use either derived class instead.
  72. //
  73. // This extends PointerToBase to be a pointer to a
  74. // PointerToArrayElement, above, which is essentially a
  75. // reference-counted STL vector.
  76. ////////////////////////////////////////////////////////////////////
  77. template <class Element>
  78. class PointerToArrayBase : public PointerToBase<PointerToArrayElement<Element> > {
  79. public:
  80. typedef TYPENAME PointerToBase<PointerToArrayElement<Element> >::To To;
  81. protected:
  82. INLINE PointerToArrayBase(PointerToArrayElement<Element> *ptr);
  83. INLINE PointerToArrayBase(const PointerToArrayBase<Element> &copy);
  84. PUBLISHED:
  85. INLINE ~PointerToArrayBase();
  86. };
  87. #include "pointerToArrayBase.I"
  88. #endif