From a9c791a0347d2a60ca79a35e9d7c3d1690f67f19 Mon Sep 17 00:00:00 2001 From: Josh Yelon Date: Wed, 7 Feb 2007 22:06:57 +0000 Subject: [PATCH] Renamed PointerToArrayElement to ReferenceCountedArray --- panda/src/express/pointerToArray.I | 70 ++++++++++++++------------ panda/src/express/pointerToArray.h | 4 +- panda/src/express/pointerToArrayBase.I | 64 +++++++++++------------ panda/src/express/pointerToArrayBase.h | 20 ++++---- 4 files changed, 81 insertions(+), 77 deletions(-) diff --git a/panda/src/express/pointerToArray.I b/panda/src/express/pointerToArray.I index f235293ab7..221097badc 100644 --- a/panda/src/express/pointerToArray.I +++ b/panda/src/express/pointerToArray.I @@ -30,7 +30,7 @@ pvector ConstPointerToArray::_empty_array; template INLINE PointerToArray:: PointerToArray() : - PointerToArrayBase((PointerToArrayElement *)NULL) + PointerToArrayBase((ReferenceCountedVector *)NULL) { } @@ -56,7 +56,7 @@ PointerToArray::empty_array(size_type n) { template INLINE PointerToArray:: PointerToArray(size_type n, const Element &value) : - PointerToArrayBase(new PointerToArrayElement) { + PointerToArrayBase(new ReferenceCountedVector) { ((To *)(this->_void_ptr))->reserve(n); insert(begin(), n, value); } @@ -101,7 +101,7 @@ INLINE void PointerToArray:: set_col(PStatCollectorForwardBase *col) { #ifdef DO_PSTATS if ((this->_void_ptr) == NULL) { - reassign(new PointerToArrayElement); + reassign(new ReferenceCountedVector); } ((To *)(this->_void_ptr))->set_col(col); #endif // DO_PSTATS @@ -183,7 +183,7 @@ template INLINE TYPENAME PointerToArray::size_type PointerToArray:: max_size() const { nassertd((this->_void_ptr) != NULL) { - ((PointerToArray *)this)->reassign(new PointerToArrayElement); + ((PointerToArray *)this)->reassign(new ReferenceCountedVector); } return ((To *)(this->_void_ptr))->max_size(); } @@ -208,7 +208,7 @@ template INLINE void PointerToArray:: reserve(TYPENAME PointerToArray::size_type n) { if ((this->_void_ptr) == NULL) { - reassign(new PointerToArrayElement); + reassign(new ReferenceCountedVector); } ((To *)(this->_void_ptr))->reserve(n); } @@ -234,7 +234,7 @@ template INLINE TYPENAME PointerToArray::reference PointerToArray:: front() const { nassertd((this->_void_ptr) != NULL) { - ((PointerToArray *)this)->reassign(new PointerToArrayElement); + ((PointerToArray *)this)->reassign(new ReferenceCountedVector); } nassertd(!((To *)(this->_void_ptr))->empty()) { ((To *)(this->_void_ptr))->push_back(Element()); @@ -251,7 +251,7 @@ template INLINE TYPENAME PointerToArray::reference PointerToArray:: back() const { nassertd((this->_void_ptr) != NULL) { - ((PointerToArray *)this)->reassign(new PointerToArrayElement); + ((PointerToArray *)this)->reassign(new ReferenceCountedVector); } nassertd(!((To *)(this->_void_ptr))->empty()) { ((To *)(this->_void_ptr))->push_back(Element()); @@ -268,7 +268,7 @@ template INLINE TYPENAME PointerToArray::iterator PointerToArray:: insert(iterator position, const Element &x) { if ((this->_void_ptr) == NULL) { - reassign(new PointerToArrayElement); + reassign(new ReferenceCountedVector); position = end(); } nassertr(position >= ((To *)(this->_void_ptr))->begin() && @@ -285,7 +285,7 @@ template INLINE void PointerToArray:: insert(iterator position, size_type n, const Element &x) { if ((this->_void_ptr) == NULL) { - reassign(new PointerToArrayElement); + reassign(new ReferenceCountedVector); position = end(); } nassertv(position >= ((To *)(this->_void_ptr))->begin() && @@ -331,7 +331,7 @@ template INLINE TYPENAME PointerToArray::reference PointerToArray:: operator [](size_type n) const { nassertd((this->_void_ptr) != NULL) { - ((PointerToArray *)this)->reassign(new PointerToArrayElement); + ((PointerToArray *)this)->reassign(new ReferenceCountedVector); } nassertd(!((To *)(this->_void_ptr))->empty()) { ((To *)(this->_void_ptr))->push_back(Element()); @@ -392,7 +392,7 @@ template INLINE void PointerToArray:: push_back(const Element &x) { if ((this->_void_ptr) == NULL) { - reassign(new PointerToArrayElement); + reassign(new ReferenceCountedVector); } ((To *)(this->_void_ptr))->push_back(x); } @@ -406,7 +406,7 @@ template INLINE void PointerToArray:: pop_back() { nassertd((this->_void_ptr) != NULL) { - ((PointerToArray *)this)->reassign(new PointerToArrayElement); + ((PointerToArray *)this)->reassign(new ReferenceCountedVector); } nassertv(!((To *)(this->_void_ptr))->empty()); ((To *)(this->_void_ptr))->pop_back(); @@ -423,7 +423,7 @@ template INLINE void PointerToArray:: make_empty() { nassertd((this->_void_ptr) != NULL) { - ((PointerToArray *)this)->reassign(new PointerToArrayElement); + ((PointerToArray *)this)->reassign(new ReferenceCountedVector); } nassertv(!((To *)(this->_void_ptr))->empty()); ((To *)(this->_void_ptr))->clear(); @@ -441,7 +441,8 @@ make_empty() { template INLINE PointerToArray:: operator Element *() const { - return ((this->_void_ptr) == NULL) ? (Element *)NULL : &(((To *)(this->_void_ptr))->front()); + To *vec = (To *)(this->_void_ptr); + return ((vec == NULL)||(vec->empty())) ? (Element *)NULL : &(vec->front()); } //////////////////////////////////////////////////////////////////// @@ -454,7 +455,8 @@ operator Element *() const { template INLINE Element *PointerToArray:: p() const { - return ((this->_void_ptr) == NULL) ? (Element *)NULL : &(((To *)(this->_void_ptr))->front()); + To *vec = (To *)(this->_void_ptr); + return ((vec == NULL)||(vec->empty())) ? (Element *)NULL : &(vec->front()); } //////////////////////////////////////////////////////////////////// @@ -467,7 +469,7 @@ template INLINE pvector &PointerToArray:: v() const { if ((this->_void_ptr) == NULL) { - ((PointerToArray *)this)->reassign(new PointerToArrayElement); + ((PointerToArray *)this)->reassign(new ReferenceCountedVector); } return *((To *)(this->_void_ptr)); } @@ -526,7 +528,7 @@ template INLINE void PointerToArray:: node_ref() const { if ((this->_void_ptr) == NULL) { - ((PointerToArray *)this)->reassign(new PointerToArrayElement); + ((PointerToArray *)this)->reassign(new ReferenceCountedVector); } ((To *)(this->_void_ptr))->node_ref(); } @@ -550,7 +552,7 @@ node_unref() const { //////////////////////////////////////////////////////////////////// template INLINE PointerToArray &PointerToArray:: -operator = (PointerToArrayElement *ptr) { +operator = (ReferenceCountedVector *ptr) { reassign(ptr); return *this; } @@ -582,14 +584,14 @@ clear() { PT(PStatCollectorForwardBase) col = ((To *)(this->_void_ptr))->get_col(); if (col != (PStatCollectorForwardBase *)NULL) { // If we have a PStat counter, preserve it. - reassign(new PointerToArrayElement); + reassign(new ReferenceCountedVector); ((To *)(this->_void_ptr))->set_col(col); return; } } #endif // DO_PSTATS - reassign((PointerToArrayElement *)NULL); + reassign((ReferenceCountedVector *)NULL); } @@ -602,7 +604,7 @@ clear() { template INLINE ConstPointerToArray:: ConstPointerToArray() : - PointerToArrayBase((PointerToArrayElement *)NULL) + PointerToArrayBase((ReferenceCountedVector *)NULL) { } @@ -723,7 +725,7 @@ template INLINE TYPENAME ConstPointerToArray::size_type ConstPointerToArray:: max_size() const { nassertd((this->_void_ptr) != NULL) { - ((ConstPointerToArray *)this)->reassign(new PointerToArrayElement); + ((ConstPointerToArray *)this)->reassign(new ReferenceCountedVector); } return ((To *)(this->_void_ptr))->max_size(); } @@ -748,7 +750,7 @@ template INLINE TYPENAME ConstPointerToArray::size_type ConstPointerToArray:: capacity() const { nassertd((this->_void_ptr) != NULL) { - ((ConstPointerToArray *)this)->reassign(new PointerToArrayElement); + ((ConstPointerToArray *)this)->reassign(new ReferenceCountedVector); } return ((To *)(this->_void_ptr))->capacity(); } @@ -762,7 +764,7 @@ template INLINE TYPENAME ConstPointerToArray::reference ConstPointerToArray:: front() const { nassertd((this->_void_ptr) != NULL) { - ((ConstPointerToArray *)this)->reassign(new PointerToArrayElement); + ((ConstPointerToArray *)this)->reassign(new ReferenceCountedVector); } nassertd(!((To *)(this->_void_ptr))->empty()) { ((To *)(this->_void_ptr))->push_back(Element()); @@ -779,7 +781,7 @@ template INLINE TYPENAME ConstPointerToArray::reference ConstPointerToArray:: back() const { nassertd((this->_void_ptr) != NULL) { - ((ConstPointerToArray *)this)->reassign(new PointerToArrayElement); + ((ConstPointerToArray *)this)->reassign(new ReferenceCountedVector); } nassertd(!((To *)(this->_void_ptr))->empty()) { ((To *)(this->_void_ptr))->push_back(Element()); @@ -797,7 +799,7 @@ template INLINE TYPENAME ConstPointerToArray::reference ConstPointerToArray:: operator [](size_type n) const { nassertd((this->_void_ptr) != NULL) { - ((ConstPointerToArray *)this)->reassign(new PointerToArrayElement); + ((ConstPointerToArray *)this)->reassign(new ReferenceCountedVector); } nassertd(!((To *)(this->_void_ptr))->empty()) { ((To *)(this->_void_ptr))->push_back(Element()); @@ -845,7 +847,8 @@ get_element(size_type n) const { template INLINE ConstPointerToArray:: operator const Element *() const { - return ((this->_void_ptr) == NULL) ? (const Element *)NULL : &(((To *)(this->_void_ptr))->front()); + To *vec = (To *)(this->_void_ptr); + return ((vec == NULL)||(vec->empty())) ? (const Element *)NULL : &(vec->front()); } //////////////////////////////////////////////////////////////////// @@ -858,7 +861,8 @@ operator const Element *() const { template INLINE const Element *ConstPointerToArray:: p() const { - return ((this->_void_ptr) == NULL) ? (const Element *)NULL : &(((To *)(this->_void_ptr))->front()); + To *vec = (To *)(this->_void_ptr); + return ((vec == NULL)||(vec->empty())) ? (const Element *)NULL : &(vec->front()); } //////////////////////////////////////////////////////////////////// @@ -871,7 +875,7 @@ template INLINE const pvector &ConstPointerToArray:: v() const { nassertd((this->_void_ptr) != NULL) { - ((ConstPointerToArray *)this)->reassign(new PointerToArrayElement); + ((ConstPointerToArray *)this)->reassign(new ReferenceCountedVector); } return *(To *)(this->_void_ptr); } @@ -907,7 +911,7 @@ template INLINE void ConstPointerToArray:: node_ref() const { if ((this->_void_ptr) == NULL) { - ((ConstPointerToArray *)this)->reassign(new PointerToArrayElement); + ((ConstPointerToArray *)this)->reassign(new ReferenceCountedVector); } ((To *)(this->_void_ptr))->node_ref(); } @@ -931,7 +935,7 @@ node_unref() const { //////////////////////////////////////////////////////////////////// template INLINE ConstPointerToArray &ConstPointerToArray:: -operator = (PointerToArrayElement *ptr) { +operator = (ReferenceCountedVector *ptr) { reassign(ptr); return *this; } @@ -975,14 +979,14 @@ clear() { PT(PStatCollectorForwardBase) col = ((To *)(this->_void_ptr))->get_col(); if (col != (PStatCollectorForwardBase *)NULL) { // If we have a PStat counter, preserve it. - reassign(new PointerToArrayElement); + reassign(new ReferenceCountedVector); ((To *)(this->_void_ptr))->set_col(col); return; } } #else // DO_PSTATS - reassign((PointerToArrayElement *)NULL); + reassign((ReferenceCountedVector *)NULL); #endif // DO_PSTATS } diff --git a/panda/src/express/pointerToArray.h b/panda/src/express/pointerToArray.h index 3d5a5c507d..34032cee89 100644 --- a/panda/src/express/pointerToArray.h +++ b/panda/src/express/pointerToArray.h @@ -193,7 +193,7 @@ public: // Reassignment is by pointer, not memberwise as with a vector. INLINE PointerToArray & - operator = (PointerToArrayElement *ptr); + operator = (ReferenceCountedVector *ptr); INLINE PointerToArray & operator = (const PointerToArray ©); INLINE void clear(); @@ -281,7 +281,7 @@ public: // Reassignment is by pointer, not memberwise as with a vector. INLINE ConstPointerToArray & - operator = (PointerToArrayElement *ptr); + operator = (ReferenceCountedVector *ptr); INLINE ConstPointerToArray & operator = (const PointerToArray ©); INLINE ConstPointerToArray & diff --git a/panda/src/express/pointerToArrayBase.I b/panda/src/express/pointerToArrayBase.I index f12ec780cc..73ac0eb4c3 100644 --- a/panda/src/express/pointerToArrayBase.I +++ b/panda/src/express/pointerToArrayBase.I @@ -18,23 +18,23 @@ //////////////////////////////////////////////////////////////////// -// Function: PointerToArrayElement::Constructor +// Function: ReferenceCountedVector::Constructor // Access: Public // Description: //////////////////////////////////////////////////////////////////// template -INLINE PointerToArrayElement:: -PointerToArrayElement() { +INLINE ReferenceCountedVector:: +ReferenceCountedVector() { } //////////////////////////////////////////////////////////////////// -// Function: PointerToArrayElement::Copy Constructor +// Function: ReferenceCountedVector::Copy Constructor // Access: Public // Description: //////////////////////////////////////////////////////////////////// template -INLINE PointerToArrayElement:: -PointerToArrayElement(const PointerToArrayElement ©) : +INLINE ReferenceCountedVector:: +ReferenceCountedVector(const ReferenceCountedVector ©) : NodeReferenceCount(copy), pvector(copy) { @@ -44,24 +44,24 @@ PointerToArrayElement(const PointerToArrayElement ©) : } //////////////////////////////////////////////////////////////////// -// Function: PointerToArrayElement::Destructor +// Function: ReferenceCountedVector::Destructor // Access: Public // Description: //////////////////////////////////////////////////////////////////// template -INLINE PointerToArrayElement:: -~PointerToArrayElement() { +INLINE ReferenceCountedVector:: +~ReferenceCountedVector() { adjust_size(size(), 0); } //////////////////////////////////////////////////////////////////// -// Function: PointerToArrayElement::get_col +// Function: ReferenceCountedVector::get_col // Access: Public // Description: Returns the pointer to the PStatCollector object that // tracks the total allocated size of this buffer. //////////////////////////////////////////////////////////////////// template -INLINE PStatCollectorForwardBase *PointerToArrayElement:: +INLINE PStatCollectorForwardBase *ReferenceCountedVector:: get_col() const { #ifdef DO_PSTATS return _col; @@ -71,13 +71,13 @@ get_col() const { } //////////////////////////////////////////////////////////////////// -// Function: PointerToArrayElement::set_col +// Function: ReferenceCountedVector::set_col // Access: Public // Description: Changes the pointer to the PStatCollector object that // tracks the total allocated size of this buffer. //////////////////////////////////////////////////////////////////// template -INLINE void PointerToArrayElement:: +INLINE void ReferenceCountedVector:: set_col(PStatCollectorForwardBase *col) { #ifdef DO_PSTATS if (_col != col) { @@ -89,97 +89,97 @@ set_col(PStatCollectorForwardBase *col) { } //////////////////////////////////////////////////////////////////// -// Function: PointerToArrayElement::size +// Function: ReferenceCountedVector::size // Access: Public // Description: //////////////////////////////////////////////////////////////////// template -INLINE TYPENAME PointerToArrayElement::size_type PointerToArrayElement:: +INLINE TYPENAME ReferenceCountedVector::size_type ReferenceCountedVector:: size() const { return pvector::size(); } //////////////////////////////////////////////////////////////////// -// Function: PointerToArrayElement::insert +// Function: ReferenceCountedVector::insert // Access: Public // Description: //////////////////////////////////////////////////////////////////// template -INLINE TYPENAME PointerToArrayElement::iterator PointerToArrayElement:: +INLINE TYPENAME ReferenceCountedVector::iterator ReferenceCountedVector:: insert(iterator position, const Element &x) { adjust_size(0, 1); return pvector::insert(position, x); } //////////////////////////////////////////////////////////////////// -// Function: PointerToArrayElement::insert +// Function: ReferenceCountedVector::insert // Access: Public // Description: //////////////////////////////////////////////////////////////////// template -INLINE void PointerToArrayElement:: +INLINE void ReferenceCountedVector:: insert(iterator position, size_type n, const Element &x) { adjust_size(0, n); pvector::insert(position, n, x); } //////////////////////////////////////////////////////////////////// -// Function: PointerToArrayElement::erase +// Function: ReferenceCountedVector::erase // Access: Public // Description: //////////////////////////////////////////////////////////////////// template -INLINE void PointerToArrayElement:: +INLINE void ReferenceCountedVector:: erase(iterator position) { adjust_size(1, 0); pvector::erase(position); } //////////////////////////////////////////////////////////////////// -// Function: PointerToArrayElement::erase +// Function: ReferenceCountedVector::erase // Access: Public // Description: //////////////////////////////////////////////////////////////////// template -INLINE void PointerToArrayElement:: +INLINE void ReferenceCountedVector:: erase(iterator first, iterator last) { adjust_size(last - first, 0); pvector::erase(first, last); } //////////////////////////////////////////////////////////////////// -// Function: PointerToArrayElement::pop_back +// Function: ReferenceCountedVector::pop_back // Access: Public // Description: //////////////////////////////////////////////////////////////////// template -INLINE void PointerToArrayElement:: +INLINE void ReferenceCountedVector:: pop_back() { adjust_size(1, 0); pvector::pop_back(); } //////////////////////////////////////////////////////////////////// -// Function: PointerToArrayElement::clear +// Function: ReferenceCountedVector::clear // Access: Public // Description: //////////////////////////////////////////////////////////////////// template -INLINE void PointerToArrayElement:: +INLINE void ReferenceCountedVector:: clear() { adjust_size(size(), 0); pvector::clear(); } //////////////////////////////////////////////////////////////////// -// Function: PointerToArrayElement::adjust_size +// Function: ReferenceCountedVector::adjust_size // Access: Private // Description: This internal function is used to update the // connected PStatCollector (if any) with the change in // size. //////////////////////////////////////////////////////////////////// template -INLINE void PointerToArrayElement:: +INLINE void ReferenceCountedVector:: adjust_size(size_t orig_size, size_t new_size) { #ifdef DO_PSTATS if (_col != (PStatCollectorForwardBase *)NULL) { @@ -195,8 +195,8 @@ adjust_size(size_t orig_size, size_t new_size) { //////////////////////////////////////////////////////////////////// template INLINE PointerToArrayBase:: -PointerToArrayBase(PointerToArrayElement *ptr) : - PointerToBase >(ptr) +PointerToArrayBase(ReferenceCountedVector *ptr) : + PointerToBase >(ptr) { } @@ -208,7 +208,7 @@ PointerToArrayBase(PointerToArrayElement *ptr) : template INLINE PointerToArrayBase:: PointerToArrayBase(const PointerToArrayBase ©) : - PointerToBase >(copy) + PointerToBase >(copy) { } diff --git a/panda/src/express/pointerToArrayBase.h b/panda/src/express/pointerToArrayBase.h index 5ae08eeb89..16a8379a9c 100644 --- a/panda/src/express/pointerToArrayBase.h +++ b/panda/src/express/pointerToArrayBase.h @@ -27,7 +27,7 @@ #include "memoryBase.h" //////////////////////////////////////////////////////////////////// -// Class : PointerToArrayElement +// Class : ReferenceCountedVector // Description : This defines the object that is actually stored and // reference-counted internally by a PointerToArray. It // is basically a NodeReferenceCount-capable STL vector. @@ -44,15 +44,15 @@ // may not use it. //////////////////////////////////////////////////////////////////// template -class PointerToArrayElement : public NodeReferenceCount, public pvector { +class ReferenceCountedVector : public NodeReferenceCount, public pvector { public: typedef TYPENAME pvector::iterator iterator; typedef TYPENAME pvector::size_type size_type; - INLINE PointerToArrayElement(); - INLINE PointerToArrayElement(const PointerToArrayElement ©); - INLINE ~PointerToArrayElement(); - ALLOC_DELETED_CHAIN(PointerToArrayElement); + INLINE ReferenceCountedVector(); + INLINE ReferenceCountedVector(const ReferenceCountedVector ©); + INLINE ~ReferenceCountedVector(); + ALLOC_DELETED_CHAIN(ReferenceCountedVector); INLINE PStatCollectorForwardBase *get_col() const; INLINE void set_col(PStatCollectorForwardBase *col); @@ -83,16 +83,16 @@ private: // use either derived class instead. // // This extends PointerToBase to be a pointer to a -// PointerToArrayElement, above, which is essentially a +// ReferenceCountedVector, above, which is essentially a // reference-counted STL vector. //////////////////////////////////////////////////////////////////// template -class PointerToArrayBase : public PointerToBase > { +class PointerToArrayBase : public PointerToBase > { public: - typedef TYPENAME PointerToBase >::To To; + typedef TYPENAME PointerToBase >::To To; protected: - INLINE PointerToArrayBase(PointerToArrayElement *ptr); + INLINE PointerToArrayBase(ReferenceCountedVector *ptr); INLINE PointerToArrayBase(const PointerToArrayBase ©); PUBLISHED: