Renamed PointerToArrayElement to ReferenceCountedArray

This commit is contained in:
Josh Yelon 2007-02-07 22:06:57 +00:00
parent 759767f9ce
commit a9c791a034
4 changed files with 81 additions and 77 deletions

View File

@ -30,7 +30,7 @@ pvector<Element> ConstPointerToArray<Element>::_empty_array;
template<class Element> template<class Element>
INLINE PointerToArray<Element>:: INLINE PointerToArray<Element>::
PointerToArray() : PointerToArray() :
PointerToArrayBase<Element>((PointerToArrayElement<Element> *)NULL) PointerToArrayBase<Element>((ReferenceCountedVector<Element> *)NULL)
{ {
} }
@ -56,7 +56,7 @@ PointerToArray<Element>::empty_array(size_type n) {
template<class Element> template<class Element>
INLINE PointerToArray<Element>:: INLINE PointerToArray<Element>::
PointerToArray(size_type n, const Element &value) : PointerToArray(size_type n, const Element &value) :
PointerToArrayBase<Element>(new PointerToArrayElement<Element>) { PointerToArrayBase<Element>(new ReferenceCountedVector<Element>) {
((To *)(this->_void_ptr))->reserve(n); ((To *)(this->_void_ptr))->reserve(n);
insert(begin(), n, value); insert(begin(), n, value);
} }
@ -101,7 +101,7 @@ INLINE void PointerToArray<Element>::
set_col(PStatCollectorForwardBase *col) { set_col(PStatCollectorForwardBase *col) {
#ifdef DO_PSTATS #ifdef DO_PSTATS
if ((this->_void_ptr) == NULL) { if ((this->_void_ptr) == NULL) {
reassign(new PointerToArrayElement<Element>); reassign(new ReferenceCountedVector<Element>);
} }
((To *)(this->_void_ptr))->set_col(col); ((To *)(this->_void_ptr))->set_col(col);
#endif // DO_PSTATS #endif // DO_PSTATS
@ -183,7 +183,7 @@ template<class Element>
INLINE TYPENAME PointerToArray<Element>::size_type PointerToArray<Element>:: INLINE TYPENAME PointerToArray<Element>::size_type PointerToArray<Element>::
max_size() const { max_size() const {
nassertd((this->_void_ptr) != NULL) { nassertd((this->_void_ptr) != NULL) {
((PointerToArray<Element> *)this)->reassign(new PointerToArrayElement<Element>); ((PointerToArray<Element> *)this)->reassign(new ReferenceCountedVector<Element>);
} }
return ((To *)(this->_void_ptr))->max_size(); return ((To *)(this->_void_ptr))->max_size();
} }
@ -208,7 +208,7 @@ template<class Element>
INLINE void PointerToArray<Element>:: INLINE void PointerToArray<Element>::
reserve(TYPENAME PointerToArray<Element>::size_type n) { reserve(TYPENAME PointerToArray<Element>::size_type n) {
if ((this->_void_ptr) == NULL) { if ((this->_void_ptr) == NULL) {
reassign(new PointerToArrayElement<Element>); reassign(new ReferenceCountedVector<Element>);
} }
((To *)(this->_void_ptr))->reserve(n); ((To *)(this->_void_ptr))->reserve(n);
} }
@ -234,7 +234,7 @@ template<class Element>
INLINE TYPENAME PointerToArray<Element>::reference PointerToArray<Element>:: INLINE TYPENAME PointerToArray<Element>::reference PointerToArray<Element>::
front() const { front() const {
nassertd((this->_void_ptr) != NULL) { nassertd((this->_void_ptr) != NULL) {
((PointerToArray<Element> *)this)->reassign(new PointerToArrayElement<Element>); ((PointerToArray<Element> *)this)->reassign(new ReferenceCountedVector<Element>);
} }
nassertd(!((To *)(this->_void_ptr))->empty()) { nassertd(!((To *)(this->_void_ptr))->empty()) {
((To *)(this->_void_ptr))->push_back(Element()); ((To *)(this->_void_ptr))->push_back(Element());
@ -251,7 +251,7 @@ template<class Element>
INLINE TYPENAME PointerToArray<Element>::reference PointerToArray<Element>:: INLINE TYPENAME PointerToArray<Element>::reference PointerToArray<Element>::
back() const { back() const {
nassertd((this->_void_ptr) != NULL) { nassertd((this->_void_ptr) != NULL) {
((PointerToArray<Element> *)this)->reassign(new PointerToArrayElement<Element>); ((PointerToArray<Element> *)this)->reassign(new ReferenceCountedVector<Element>);
} }
nassertd(!((To *)(this->_void_ptr))->empty()) { nassertd(!((To *)(this->_void_ptr))->empty()) {
((To *)(this->_void_ptr))->push_back(Element()); ((To *)(this->_void_ptr))->push_back(Element());
@ -268,7 +268,7 @@ template<class Element>
INLINE TYPENAME PointerToArray<Element>::iterator PointerToArray<Element>:: INLINE TYPENAME PointerToArray<Element>::iterator PointerToArray<Element>::
insert(iterator position, const Element &x) { insert(iterator position, const Element &x) {
if ((this->_void_ptr) == NULL) { if ((this->_void_ptr) == NULL) {
reassign(new PointerToArrayElement<Element>); reassign(new ReferenceCountedVector<Element>);
position = end(); position = end();
} }
nassertr(position >= ((To *)(this->_void_ptr))->begin() && nassertr(position >= ((To *)(this->_void_ptr))->begin() &&
@ -285,7 +285,7 @@ template<class Element>
INLINE void PointerToArray<Element>:: INLINE void PointerToArray<Element>::
insert(iterator position, size_type n, const Element &x) { insert(iterator position, size_type n, const Element &x) {
if ((this->_void_ptr) == NULL) { if ((this->_void_ptr) == NULL) {
reassign(new PointerToArrayElement<Element>); reassign(new ReferenceCountedVector<Element>);
position = end(); position = end();
} }
nassertv(position >= ((To *)(this->_void_ptr))->begin() && nassertv(position >= ((To *)(this->_void_ptr))->begin() &&
@ -331,7 +331,7 @@ template<class Element>
INLINE TYPENAME PointerToArray<Element>::reference PointerToArray<Element>:: INLINE TYPENAME PointerToArray<Element>::reference PointerToArray<Element>::
operator [](size_type n) const { operator [](size_type n) const {
nassertd((this->_void_ptr) != NULL) { nassertd((this->_void_ptr) != NULL) {
((PointerToArray<Element> *)this)->reassign(new PointerToArrayElement<Element>); ((PointerToArray<Element> *)this)->reassign(new ReferenceCountedVector<Element>);
} }
nassertd(!((To *)(this->_void_ptr))->empty()) { nassertd(!((To *)(this->_void_ptr))->empty()) {
((To *)(this->_void_ptr))->push_back(Element()); ((To *)(this->_void_ptr))->push_back(Element());
@ -392,7 +392,7 @@ template<class Element>
INLINE void PointerToArray<Element>:: INLINE void PointerToArray<Element>::
push_back(const Element &x) { push_back(const Element &x) {
if ((this->_void_ptr) == NULL) { if ((this->_void_ptr) == NULL) {
reassign(new PointerToArrayElement<Element>); reassign(new ReferenceCountedVector<Element>);
} }
((To *)(this->_void_ptr))->push_back(x); ((To *)(this->_void_ptr))->push_back(x);
} }
@ -406,7 +406,7 @@ template<class Element>
INLINE void PointerToArray<Element>:: INLINE void PointerToArray<Element>::
pop_back() { pop_back() {
nassertd((this->_void_ptr) != NULL) { nassertd((this->_void_ptr) != NULL) {
((PointerToArray<Element> *)this)->reassign(new PointerToArrayElement<Element>); ((PointerToArray<Element> *)this)->reassign(new ReferenceCountedVector<Element>);
} }
nassertv(!((To *)(this->_void_ptr))->empty()); nassertv(!((To *)(this->_void_ptr))->empty());
((To *)(this->_void_ptr))->pop_back(); ((To *)(this->_void_ptr))->pop_back();
@ -423,7 +423,7 @@ template<class Element>
INLINE void PointerToArray<Element>:: INLINE void PointerToArray<Element>::
make_empty() { make_empty() {
nassertd((this->_void_ptr) != NULL) { nassertd((this->_void_ptr) != NULL) {
((PointerToArray<Element> *)this)->reassign(new PointerToArrayElement<Element>); ((PointerToArray<Element> *)this)->reassign(new ReferenceCountedVector<Element>);
} }
nassertv(!((To *)(this->_void_ptr))->empty()); nassertv(!((To *)(this->_void_ptr))->empty());
((To *)(this->_void_ptr))->clear(); ((To *)(this->_void_ptr))->clear();
@ -441,7 +441,8 @@ make_empty() {
template<class Element> template<class Element>
INLINE PointerToArray<Element>:: INLINE PointerToArray<Element>::
operator Element *() const { 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<class Element> template<class Element>
INLINE Element *PointerToArray<Element>:: INLINE Element *PointerToArray<Element>::
p() const { 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<class Element>
INLINE pvector<Element> &PointerToArray<Element>:: INLINE pvector<Element> &PointerToArray<Element>::
v() const { v() const {
if ((this->_void_ptr) == NULL) { if ((this->_void_ptr) == NULL) {
((PointerToArray<Element> *)this)->reassign(new PointerToArrayElement<Element>); ((PointerToArray<Element> *)this)->reassign(new ReferenceCountedVector<Element>);
} }
return *((To *)(this->_void_ptr)); return *((To *)(this->_void_ptr));
} }
@ -526,7 +528,7 @@ template<class Element>
INLINE void PointerToArray<Element>:: INLINE void PointerToArray<Element>::
node_ref() const { node_ref() const {
if ((this->_void_ptr) == NULL) { if ((this->_void_ptr) == NULL) {
((PointerToArray<Element> *)this)->reassign(new PointerToArrayElement<Element>); ((PointerToArray<Element> *)this)->reassign(new ReferenceCountedVector<Element>);
} }
((To *)(this->_void_ptr))->node_ref(); ((To *)(this->_void_ptr))->node_ref();
} }
@ -550,7 +552,7 @@ node_unref() const {
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
template<class Element> template<class Element>
INLINE PointerToArray<Element> &PointerToArray<Element>:: INLINE PointerToArray<Element> &PointerToArray<Element>::
operator = (PointerToArrayElement<Element> *ptr) { operator = (ReferenceCountedVector<Element> *ptr) {
reassign(ptr); reassign(ptr);
return *this; return *this;
} }
@ -582,14 +584,14 @@ clear() {
PT(PStatCollectorForwardBase) col = ((To *)(this->_void_ptr))->get_col(); PT(PStatCollectorForwardBase) col = ((To *)(this->_void_ptr))->get_col();
if (col != (PStatCollectorForwardBase *)NULL) { if (col != (PStatCollectorForwardBase *)NULL) {
// If we have a PStat counter, preserve it. // If we have a PStat counter, preserve it.
reassign(new PointerToArrayElement<Element>); reassign(new ReferenceCountedVector<Element>);
((To *)(this->_void_ptr))->set_col(col); ((To *)(this->_void_ptr))->set_col(col);
return; return;
} }
} }
#endif // DO_PSTATS #endif // DO_PSTATS
reassign((PointerToArrayElement<Element> *)NULL); reassign((ReferenceCountedVector<Element> *)NULL);
} }
@ -602,7 +604,7 @@ clear() {
template<class Element> template<class Element>
INLINE ConstPointerToArray<Element>:: INLINE ConstPointerToArray<Element>::
ConstPointerToArray() : ConstPointerToArray() :
PointerToArrayBase<Element>((PointerToArrayElement<Element> *)NULL) PointerToArrayBase<Element>((ReferenceCountedVector<Element> *)NULL)
{ {
} }
@ -723,7 +725,7 @@ template<class Element>
INLINE TYPENAME ConstPointerToArray<Element>::size_type ConstPointerToArray<Element>:: INLINE TYPENAME ConstPointerToArray<Element>::size_type ConstPointerToArray<Element>::
max_size() const { max_size() const {
nassertd((this->_void_ptr) != NULL) { nassertd((this->_void_ptr) != NULL) {
((ConstPointerToArray<Element> *)this)->reassign(new PointerToArrayElement<Element>); ((ConstPointerToArray<Element> *)this)->reassign(new ReferenceCountedVector<Element>);
} }
return ((To *)(this->_void_ptr))->max_size(); return ((To *)(this->_void_ptr))->max_size();
} }
@ -748,7 +750,7 @@ template<class Element>
INLINE TYPENAME ConstPointerToArray<Element>::size_type ConstPointerToArray<Element>:: INLINE TYPENAME ConstPointerToArray<Element>::size_type ConstPointerToArray<Element>::
capacity() const { capacity() const {
nassertd((this->_void_ptr) != NULL) { nassertd((this->_void_ptr) != NULL) {
((ConstPointerToArray<Element> *)this)->reassign(new PointerToArrayElement<Element>); ((ConstPointerToArray<Element> *)this)->reassign(new ReferenceCountedVector<Element>);
} }
return ((To *)(this->_void_ptr))->capacity(); return ((To *)(this->_void_ptr))->capacity();
} }
@ -762,7 +764,7 @@ template<class Element>
INLINE TYPENAME ConstPointerToArray<Element>::reference ConstPointerToArray<Element>:: INLINE TYPENAME ConstPointerToArray<Element>::reference ConstPointerToArray<Element>::
front() const { front() const {
nassertd((this->_void_ptr) != NULL) { nassertd((this->_void_ptr) != NULL) {
((ConstPointerToArray<Element> *)this)->reassign(new PointerToArrayElement<Element>); ((ConstPointerToArray<Element> *)this)->reassign(new ReferenceCountedVector<Element>);
} }
nassertd(!((To *)(this->_void_ptr))->empty()) { nassertd(!((To *)(this->_void_ptr))->empty()) {
((To *)(this->_void_ptr))->push_back(Element()); ((To *)(this->_void_ptr))->push_back(Element());
@ -779,7 +781,7 @@ template<class Element>
INLINE TYPENAME ConstPointerToArray<Element>::reference ConstPointerToArray<Element>:: INLINE TYPENAME ConstPointerToArray<Element>::reference ConstPointerToArray<Element>::
back() const { back() const {
nassertd((this->_void_ptr) != NULL) { nassertd((this->_void_ptr) != NULL) {
((ConstPointerToArray<Element> *)this)->reassign(new PointerToArrayElement<Element>); ((ConstPointerToArray<Element> *)this)->reassign(new ReferenceCountedVector<Element>);
} }
nassertd(!((To *)(this->_void_ptr))->empty()) { nassertd(!((To *)(this->_void_ptr))->empty()) {
((To *)(this->_void_ptr))->push_back(Element()); ((To *)(this->_void_ptr))->push_back(Element());
@ -797,7 +799,7 @@ template<class Element>
INLINE TYPENAME ConstPointerToArray<Element>::reference ConstPointerToArray<Element>:: INLINE TYPENAME ConstPointerToArray<Element>::reference ConstPointerToArray<Element>::
operator [](size_type n) const { operator [](size_type n) const {
nassertd((this->_void_ptr) != NULL) { nassertd((this->_void_ptr) != NULL) {
((ConstPointerToArray<Element> *)this)->reassign(new PointerToArrayElement<Element>); ((ConstPointerToArray<Element> *)this)->reassign(new ReferenceCountedVector<Element>);
} }
nassertd(!((To *)(this->_void_ptr))->empty()) { nassertd(!((To *)(this->_void_ptr))->empty()) {
((To *)(this->_void_ptr))->push_back(Element()); ((To *)(this->_void_ptr))->push_back(Element());
@ -845,7 +847,8 @@ get_element(size_type n) const {
template<class Element> template<class Element>
INLINE ConstPointerToArray<Element>:: INLINE ConstPointerToArray<Element>::
operator const Element *() const { 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<class Element> template<class Element>
INLINE const Element *ConstPointerToArray<Element>:: INLINE const Element *ConstPointerToArray<Element>::
p() const { 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<class Element>
INLINE const pvector<Element> &ConstPointerToArray<Element>:: INLINE const pvector<Element> &ConstPointerToArray<Element>::
v() const { v() const {
nassertd((this->_void_ptr) != NULL) { nassertd((this->_void_ptr) != NULL) {
((ConstPointerToArray<Element> *)this)->reassign(new PointerToArrayElement<Element>); ((ConstPointerToArray<Element> *)this)->reassign(new ReferenceCountedVector<Element>);
} }
return *(To *)(this->_void_ptr); return *(To *)(this->_void_ptr);
} }
@ -907,7 +911,7 @@ template<class Element>
INLINE void ConstPointerToArray<Element>:: INLINE void ConstPointerToArray<Element>::
node_ref() const { node_ref() const {
if ((this->_void_ptr) == NULL) { if ((this->_void_ptr) == NULL) {
((ConstPointerToArray<Element> *)this)->reassign(new PointerToArrayElement<Element>); ((ConstPointerToArray<Element> *)this)->reassign(new ReferenceCountedVector<Element>);
} }
((To *)(this->_void_ptr))->node_ref(); ((To *)(this->_void_ptr))->node_ref();
} }
@ -931,7 +935,7 @@ node_unref() const {
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
template<class Element> template<class Element>
INLINE ConstPointerToArray<Element> &ConstPointerToArray<Element>:: INLINE ConstPointerToArray<Element> &ConstPointerToArray<Element>::
operator = (PointerToArrayElement<Element> *ptr) { operator = (ReferenceCountedVector<Element> *ptr) {
reassign(ptr); reassign(ptr);
return *this; return *this;
} }
@ -975,14 +979,14 @@ clear() {
PT(PStatCollectorForwardBase) col = ((To *)(this->_void_ptr))->get_col(); PT(PStatCollectorForwardBase) col = ((To *)(this->_void_ptr))->get_col();
if (col != (PStatCollectorForwardBase *)NULL) { if (col != (PStatCollectorForwardBase *)NULL) {
// If we have a PStat counter, preserve it. // If we have a PStat counter, preserve it.
reassign(new PointerToArrayElement<Element>); reassign(new ReferenceCountedVector<Element>);
((To *)(this->_void_ptr))->set_col(col); ((To *)(this->_void_ptr))->set_col(col);
return; return;
} }
} }
#else // DO_PSTATS #else // DO_PSTATS
reassign((PointerToArrayElement<Element> *)NULL); reassign((ReferenceCountedVector<Element> *)NULL);
#endif // DO_PSTATS #endif // DO_PSTATS
} }

View File

@ -193,7 +193,7 @@ public:
// Reassignment is by pointer, not memberwise as with a vector. // Reassignment is by pointer, not memberwise as with a vector.
INLINE PointerToArray<Element> & INLINE PointerToArray<Element> &
operator = (PointerToArrayElement<Element> *ptr); operator = (ReferenceCountedVector<Element> *ptr);
INLINE PointerToArray<Element> & INLINE PointerToArray<Element> &
operator = (const PointerToArray<Element> &copy); operator = (const PointerToArray<Element> &copy);
INLINE void clear(); INLINE void clear();
@ -281,7 +281,7 @@ public:
// Reassignment is by pointer, not memberwise as with a vector. // Reassignment is by pointer, not memberwise as with a vector.
INLINE ConstPointerToArray<Element> & INLINE ConstPointerToArray<Element> &
operator = (PointerToArrayElement<Element> *ptr); operator = (ReferenceCountedVector<Element> *ptr);
INLINE ConstPointerToArray<Element> & INLINE ConstPointerToArray<Element> &
operator = (const PointerToArray<Element> &copy); operator = (const PointerToArray<Element> &copy);
INLINE ConstPointerToArray<Element> & INLINE ConstPointerToArray<Element> &

View File

@ -18,23 +18,23 @@
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
// Function: PointerToArrayElement::Constructor // Function: ReferenceCountedVector::Constructor
// Access: Public // Access: Public
// Description: // Description:
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
template<class Element> template<class Element>
INLINE PointerToArrayElement<Element>:: INLINE ReferenceCountedVector<Element>::
PointerToArrayElement() { ReferenceCountedVector() {
} }
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
// Function: PointerToArrayElement::Copy Constructor // Function: ReferenceCountedVector::Copy Constructor
// Access: Public // Access: Public
// Description: // Description:
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
template<class Element> template<class Element>
INLINE PointerToArrayElement<Element>:: INLINE ReferenceCountedVector<Element>::
PointerToArrayElement(const PointerToArrayElement<Element> &copy) : ReferenceCountedVector(const ReferenceCountedVector<Element> &copy) :
NodeReferenceCount(copy), NodeReferenceCount(copy),
pvector<Element>(copy) pvector<Element>(copy)
{ {
@ -44,24 +44,24 @@ PointerToArrayElement(const PointerToArrayElement<Element> &copy) :
} }
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
// Function: PointerToArrayElement::Destructor // Function: ReferenceCountedVector::Destructor
// Access: Public // Access: Public
// Description: // Description:
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
template<class Element> template<class Element>
INLINE PointerToArrayElement<Element>:: INLINE ReferenceCountedVector<Element>::
~PointerToArrayElement() { ~ReferenceCountedVector() {
adjust_size(size(), 0); adjust_size(size(), 0);
} }
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
// Function: PointerToArrayElement::get_col // Function: ReferenceCountedVector::get_col
// Access: Public // Access: Public
// Description: Returns the pointer to the PStatCollector object that // Description: Returns the pointer to the PStatCollector object that
// tracks the total allocated size of this buffer. // tracks the total allocated size of this buffer.
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
template<class Element> template<class Element>
INLINE PStatCollectorForwardBase *PointerToArrayElement<Element>:: INLINE PStatCollectorForwardBase *ReferenceCountedVector<Element>::
get_col() const { get_col() const {
#ifdef DO_PSTATS #ifdef DO_PSTATS
return _col; return _col;
@ -71,13 +71,13 @@ get_col() const {
} }
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
// Function: PointerToArrayElement::set_col // Function: ReferenceCountedVector::set_col
// Access: Public // Access: Public
// Description: Changes the pointer to the PStatCollector object that // Description: Changes the pointer to the PStatCollector object that
// tracks the total allocated size of this buffer. // tracks the total allocated size of this buffer.
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
template<class Element> template<class Element>
INLINE void PointerToArrayElement<Element>:: INLINE void ReferenceCountedVector<Element>::
set_col(PStatCollectorForwardBase *col) { set_col(PStatCollectorForwardBase *col) {
#ifdef DO_PSTATS #ifdef DO_PSTATS
if (_col != col) { if (_col != col) {
@ -89,97 +89,97 @@ set_col(PStatCollectorForwardBase *col) {
} }
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
// Function: PointerToArrayElement::size // Function: ReferenceCountedVector::size
// Access: Public // Access: Public
// Description: // Description:
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
template<class Element> template<class Element>
INLINE TYPENAME PointerToArrayElement<Element>::size_type PointerToArrayElement<Element>:: INLINE TYPENAME ReferenceCountedVector<Element>::size_type ReferenceCountedVector<Element>::
size() const { size() const {
return pvector<Element>::size(); return pvector<Element>::size();
} }
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
// Function: PointerToArrayElement::insert // Function: ReferenceCountedVector::insert
// Access: Public // Access: Public
// Description: // Description:
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
template<class Element> template<class Element>
INLINE TYPENAME PointerToArrayElement<Element>::iterator PointerToArrayElement<Element>:: INLINE TYPENAME ReferenceCountedVector<Element>::iterator ReferenceCountedVector<Element>::
insert(iterator position, const Element &x) { insert(iterator position, const Element &x) {
adjust_size(0, 1); adjust_size(0, 1);
return pvector<Element>::insert(position, x); return pvector<Element>::insert(position, x);
} }
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
// Function: PointerToArrayElement::insert // Function: ReferenceCountedVector::insert
// Access: Public // Access: Public
// Description: // Description:
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
template<class Element> template<class Element>
INLINE void PointerToArrayElement<Element>:: INLINE void ReferenceCountedVector<Element>::
insert(iterator position, size_type n, const Element &x) { insert(iterator position, size_type n, const Element &x) {
adjust_size(0, n); adjust_size(0, n);
pvector<Element>::insert(position, n, x); pvector<Element>::insert(position, n, x);
} }
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
// Function: PointerToArrayElement::erase // Function: ReferenceCountedVector::erase
// Access: Public // Access: Public
// Description: // Description:
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
template<class Element> template<class Element>
INLINE void PointerToArrayElement<Element>:: INLINE void ReferenceCountedVector<Element>::
erase(iterator position) { erase(iterator position) {
adjust_size(1, 0); adjust_size(1, 0);
pvector<Element>::erase(position); pvector<Element>::erase(position);
} }
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
// Function: PointerToArrayElement::erase // Function: ReferenceCountedVector::erase
// Access: Public // Access: Public
// Description: // Description:
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
template<class Element> template<class Element>
INLINE void PointerToArrayElement<Element>:: INLINE void ReferenceCountedVector<Element>::
erase(iterator first, iterator last) { erase(iterator first, iterator last) {
adjust_size(last - first, 0); adjust_size(last - first, 0);
pvector<Element>::erase(first, last); pvector<Element>::erase(first, last);
} }
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
// Function: PointerToArrayElement::pop_back // Function: ReferenceCountedVector::pop_back
// Access: Public // Access: Public
// Description: // Description:
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
template<class Element> template<class Element>
INLINE void PointerToArrayElement<Element>:: INLINE void ReferenceCountedVector<Element>::
pop_back() { pop_back() {
adjust_size(1, 0); adjust_size(1, 0);
pvector<Element>::pop_back(); pvector<Element>::pop_back();
} }
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
// Function: PointerToArrayElement::clear // Function: ReferenceCountedVector::clear
// Access: Public // Access: Public
// Description: // Description:
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
template<class Element> template<class Element>
INLINE void PointerToArrayElement<Element>:: INLINE void ReferenceCountedVector<Element>::
clear() { clear() {
adjust_size(size(), 0); adjust_size(size(), 0);
pvector<Element>::clear(); pvector<Element>::clear();
} }
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
// Function: PointerToArrayElement::adjust_size // Function: ReferenceCountedVector::adjust_size
// Access: Private // Access: Private
// Description: This internal function is used to update the // Description: This internal function is used to update the
// connected PStatCollector (if any) with the change in // connected PStatCollector (if any) with the change in
// size. // size.
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
template<class Element> template<class Element>
INLINE void PointerToArrayElement<Element>:: INLINE void ReferenceCountedVector<Element>::
adjust_size(size_t orig_size, size_t new_size) { adjust_size(size_t orig_size, size_t new_size) {
#ifdef DO_PSTATS #ifdef DO_PSTATS
if (_col != (PStatCollectorForwardBase *)NULL) { if (_col != (PStatCollectorForwardBase *)NULL) {
@ -195,8 +195,8 @@ adjust_size(size_t orig_size, size_t new_size) {
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
template<class Element> template<class Element>
INLINE PointerToArrayBase<Element>:: INLINE PointerToArrayBase<Element>::
PointerToArrayBase(PointerToArrayElement<Element> *ptr) : PointerToArrayBase(ReferenceCountedVector<Element> *ptr) :
PointerToBase<PointerToArrayElement<Element> >(ptr) PointerToBase<ReferenceCountedVector<Element> >(ptr)
{ {
} }
@ -208,7 +208,7 @@ PointerToArrayBase(PointerToArrayElement<Element> *ptr) :
template<class Element> template<class Element>
INLINE PointerToArrayBase<Element>:: INLINE PointerToArrayBase<Element>::
PointerToArrayBase(const PointerToArrayBase<Element> &copy) : PointerToArrayBase(const PointerToArrayBase<Element> &copy) :
PointerToBase<PointerToArrayElement<Element> >(copy) PointerToBase<ReferenceCountedVector<Element> >(copy)
{ {
} }

View File

@ -27,7 +27,7 @@
#include "memoryBase.h" #include "memoryBase.h"
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
// Class : PointerToArrayElement // Class : ReferenceCountedVector
// Description : This defines the object that is actually stored and // Description : This defines the object that is actually stored and
// reference-counted internally by a PointerToArray. It // reference-counted internally by a PointerToArray. It
// is basically a NodeReferenceCount-capable STL vector. // is basically a NodeReferenceCount-capable STL vector.
@ -44,15 +44,15 @@
// may not use it. // may not use it.
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
template <class Element> template <class Element>
class PointerToArrayElement : public NodeReferenceCount, public pvector<Element> { class ReferenceCountedVector : public NodeReferenceCount, public pvector<Element> {
public: public:
typedef TYPENAME pvector<Element>::iterator iterator; typedef TYPENAME pvector<Element>::iterator iterator;
typedef TYPENAME pvector<Element>::size_type size_type; typedef TYPENAME pvector<Element>::size_type size_type;
INLINE PointerToArrayElement(); INLINE ReferenceCountedVector();
INLINE PointerToArrayElement(const PointerToArrayElement<Element> &copy); INLINE ReferenceCountedVector(const ReferenceCountedVector<Element> &copy);
INLINE ~PointerToArrayElement(); INLINE ~ReferenceCountedVector();
ALLOC_DELETED_CHAIN(PointerToArrayElement<Element>); ALLOC_DELETED_CHAIN(ReferenceCountedVector<Element>);
INLINE PStatCollectorForwardBase *get_col() const; INLINE PStatCollectorForwardBase *get_col() const;
INLINE void set_col(PStatCollectorForwardBase *col); INLINE void set_col(PStatCollectorForwardBase *col);
@ -83,16 +83,16 @@ private:
// use either derived class instead. // use either derived class instead.
// //
// This extends PointerToBase to be a pointer to a // 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. // reference-counted STL vector.
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
template <class Element> template <class Element>
class PointerToArrayBase : public PointerToBase<PointerToArrayElement<Element> > { class PointerToArrayBase : public PointerToBase<ReferenceCountedVector<Element> > {
public: public:
typedef TYPENAME PointerToBase<PointerToArrayElement<Element> >::To To; typedef TYPENAME PointerToBase<ReferenceCountedVector<Element> >::To To;
protected: protected:
INLINE PointerToArrayBase(PointerToArrayElement<Element> *ptr); INLINE PointerToArrayBase(ReferenceCountedVector<Element> *ptr);
INLINE PointerToArrayBase(const PointerToArrayBase<Element> &copy); INLINE PointerToArrayBase(const PointerToArrayBase<Element> &copy);
PUBLISHED: PUBLISHED: