// Filename: pointerToArray.I // Created by: drose (07Jan00) // //////////////////////////////////////////////////////////////////// template vector PointerToArray::_empty_array; template vector ConstPointerToArray::_empty_array; //////////////////////////////////////////////////////////////////// // Function: PointerToArray::Constructor // Access: Public // Description: //////////////////////////////////////////////////////////////////// template INLINE PointerToArray:: PointerToArray() : PointerToBase > >((RefCountObj > *)NULL) { } //////////////////////////////////////////////////////////////////// // Function: PointerToArray::Constructor // Access: Public // Description: //////////////////////////////////////////////////////////////////// template INLINE PointerToArray:: PointerToArray(size_type n) : PointerToBase > >(new RefCountObj >) { _ptr->reserve(n); insert(begin(), n, Element()); } //////////////////////////////////////////////////////////////////// // Function: PointerToArray::Constructor // Access: Public // Description: //////////////////////////////////////////////////////////////////// template INLINE PointerToArray:: PointerToArray(size_type n, const Element &value) : PointerToBase > >(new RefCountObj >) { _ptr->reserve(n); insert(begin(), n, value); } //////////////////////////////////////////////////////////////////// // Function: PointerToArray::Copy Constructor // Access: Public // Description: //////////////////////////////////////////////////////////////////// template INLINE PointerToArray:: PointerToArray(const PointerToArray ©) : PointerToBase > >(copy) { } //////////////////////////////////////////////////////////////////// // Function: PointerToArray::begin // Access: Public // Description: //////////////////////////////////////////////////////////////////// template INLINE PointerToArray::iterator PointerToArray:: begin() const { if (_ptr == NULL) { return _empty_array.begin(); } return _ptr->begin(); } //////////////////////////////////////////////////////////////////// // Function: PointerToArray::end // Access: Public // Description: //////////////////////////////////////////////////////////////////// template INLINE PointerToArray::iterator PointerToArray:: end() const { if (_ptr == NULL) { return _empty_array.begin(); } return _ptr->end(); } //////////////////////////////////////////////////////////////////// // Function: PointerToArray::rbegin // Access: Public // Description: //////////////////////////////////////////////////////////////////// template INLINE PointerToArray::reverse_iterator PointerToArray:: rbegin() const { if (_ptr == NULL) { return _empty_array.rbegin(); } return _ptr->rbegin(); } //////////////////////////////////////////////////////////////////// // Function: PointerToArray::rend // Access: Public // Description: //////////////////////////////////////////////////////////////////// template INLINE PointerToArray::reverse_iterator PointerToArray:: rend() const { if (_ptr == NULL) { return _empty_array.rbegin(); } return _ptr->rend(); } //////////////////////////////////////////////////////////////////// // Function: PointerToArray::size // Access: Public // Description: //////////////////////////////////////////////////////////////////// template INLINE PointerToArray::size_type PointerToArray:: size() const { return (_ptr == NULL) ? 0 : _ptr->size(); } //////////////////////////////////////////////////////////////////// // Function: PointerToArray::max_size // Access: Public // Description: //////////////////////////////////////////////////////////////////// template INLINE PointerToArray::size_type PointerToArray:: max_size() const { nassertd(_ptr != NULL) { ((PointerToArray *)this)->reassign(new RefCountObj >); } return _ptr->max_size(); } //////////////////////////////////////////////////////////////////// // Function: PointerToArray::empty // Access: Public // Description: //////////////////////////////////////////////////////////////////// template INLINE bool PointerToArray:: empty() const { return (_ptr == NULL) ? true : _ptr->empty(); } //////////////////////////////////////////////////////////////////// // Function: PointerToArray::reserve // Access: Public // Description: //////////////////////////////////////////////////////////////////// template INLINE void PointerToArray:: reserve(PointerToArray::size_type n) { if (_ptr == NULL) { reassign(new RefCountObj >); } _ptr->reserve(n); } //////////////////////////////////////////////////////////////////// // Function: PointerToArray::capacity // Access: Public // Description: //////////////////////////////////////////////////////////////////// template INLINE PointerToArray::size_type PointerToArray:: capacity() const { nassertr(_ptr != NULL, 0); return _ptr->capacity(); } #ifndef WIN32_VC //////////////////////////////////////////////////////////////////// // Function: PointerToArray::Indexing operator // Access: Public // Description: //////////////////////////////////////////////////////////////////// template INLINE PointerToArray::reference PointerToArray:: operator[](size_type n) const { nassertd(_ptr != NULL) { ((PointerToArray *)this)->reassign(new RefCountObj >); } nassertd(!_ptr->empty()) { _ptr->push_back(Element()); } nassertr(n < _ptr->size(), _ptr->operator[](0)); return _ptr->operator[](n); } #endif //////////////////////////////////////////////////////////////////// // Function: PointerToArray::front // Access: Public // Description: //////////////////////////////////////////////////////////////////// template INLINE PointerToArray::reference PointerToArray:: front() const { nassertd(_ptr != NULL) { ((PointerToArray *)this)->reassign(new RefCountObj >); } nassertd(!_ptr->empty()) { _ptr->push_back(Element()); } return _ptr->front(); } //////////////////////////////////////////////////////////////////// // Function: PointerToArray::back // Access: Public // Description: //////////////////////////////////////////////////////////////////// template INLINE PointerToArray::reference PointerToArray:: back() const { nassertd(_ptr != NULL) { ((PointerToArray *)this)->reassign(new RefCountObj >); } nassertd(!_ptr->empty()) { _ptr->push_back(Element()); } return _ptr->back(); } //////////////////////////////////////////////////////////////////// // Function: PointerToArray::push_back // Access: Public // Description: //////////////////////////////////////////////////////////////////// template INLINE void PointerToArray:: push_back(const Element &x) { if (_ptr == NULL) { reassign(new RefCountObj >); } _ptr->push_back(x); } //////////////////////////////////////////////////////////////////// // Function: PointerToArray::insert // Access: Public // Description: //////////////////////////////////////////////////////////////////// template INLINE PointerToArray::iterator PointerToArray:: insert(iterator position) const { nassertr(_ptr != NULL, position); nassertr(position >= _ptr->begin() && position <= _ptr->end(), position); return _ptr->insert(position); } //////////////////////////////////////////////////////////////////// // Function: PointerToArray::insert // Access: Public // Description: //////////////////////////////////////////////////////////////////// template INLINE PointerToArray::iterator PointerToArray:: insert(iterator position, const Element &x) const { nassertr(_ptr != NULL, position); nassertr(position >= _ptr->begin() && position <= _ptr->end(), position); return _ptr->insert(position, x); } //////////////////////////////////////////////////////////////////// // Function: PointerToArray::insert // Access: Public // Description: //////////////////////////////////////////////////////////////////// template INLINE void PointerToArray:: insert(iterator position, size_type n, const Element &x) const { nassertv(_ptr != NULL); nassertv(position >= _ptr->begin() && position <= _ptr->end()); _ptr->insert(position, n, x); } #ifdef HAVE_MEMBER_TEMPLATES //////////////////////////////////////////////////////////////////// // Function: PointerToArray::insert // Access: Public // Description: //////////////////////////////////////////////////////////////////// template template INLINE void PointerToArray:: insert(iterator position, InputIterator first, InputIterator last) const { nassertv(_ptr != NULL); nassertv(position >= _ptr->begin() && position <= _ptr->end()); _ptr->insert(position, first, last); } #else //////////////////////////////////////////////////////////////////// // Function: PointerToArray::insert // Access: Public // Description: //////////////////////////////////////////////////////////////////// template INLINE void PointerToArray:: insert(iterator position, const Element *first, const Element *last) const { nassertv(_ptr != NULL); nassertv(position >= _ptr->begin() && position <= _ptr->end()); _ptr->insert(position, first, last); } #endif //////////////////////////////////////////////////////////////////// // Function: PointerToArray::pop_back // Access: Public // Description: //////////////////////////////////////////////////////////////////// template INLINE void PointerToArray:: pop_back() const { nassertd(_ptr != NULL) { ((PointerToArray *)this)->reassign(new RefCountObj >); } nassertv(!_ptr->empty()); _ptr->pop_back(); } //////////////////////////////////////////////////////////////////// // Function: PointerToArray::erase // Access: Public // Description: //////////////////////////////////////////////////////////////////// template INLINE void PointerToArray:: erase(iterator position) const { nassertd(_ptr != NULL) { ((PointerToArray *)this)->reassign(new RefCountObj >); } nassertv(position >= _ptr->begin() && position <= _ptr->end()); _ptr->erase(position); } //////////////////////////////////////////////////////////////////// // Function: PointerToArray::erase // Access: Public // Description: //////////////////////////////////////////////////////////////////// template INLINE void PointerToArray:: erase(iterator first, iterator last) const { nassertd(_ptr != NULL) { ((PointerToArray *)this)->reassign(new RefCountObj >); } nassertv(first >= _ptr->begin() && first <= _ptr->end()); nassertv(last >= _ptr->begin() && last <= _ptr->end()); _ptr->erase(first, last); } //////////////////////////////////////////////////////////////////// // Function: PointerToArray::Typecast operator // Access: Public // Description: The pointer typecast operator is convenient for // maintaining the fiction that we actually have a // C-style array. It returns the address of the first // element in the array, unless the pointer is // unassigned, in which case it returns NULL. //////////////////////////////////////////////////////////////////// template INLINE PointerToArray:: operator Element *() const { return (_ptr == NULL) ? (Element *)NULL : &(_ptr->front()); } //////////////////////////////////////////////////////////////////// // Function: PointerToArray::p // Access: Public // Description: Function p() is similar to the function from // PointerTo. It does the same thing: it returns the // same thing as the typecast operator, above. //////////////////////////////////////////////////////////////////// template INLINE Element *PointerToArray:: p() const { return (_ptr == NULL) ? (Element *)NULL : &(_ptr->front()); } //////////////////////////////////////////////////////////////////// // Function: PointerToArray::v // Access: Public // Description: To access the vector itself, for more direct fiddling // with some of the vector's esoteric functionality. //////////////////////////////////////////////////////////////////// template INLINE vector &PointerToArray:: v() const { nassertd(_ptr != NULL) { ((PointerToArray *)this)->reassign(new RefCountObj >); } return *_ptr; } //////////////////////////////////////////////////////////////////// // Function: PointerToArray::get_void_ptr // Access: Public // Description: Returns the reference to memory where the vector // is stored. To be used only with get_void_ptr //////////////////////////////////////////////////////////////////// template INLINE void* PointerToArray:: get_void_ptr() const { return PointerToBase > >::_ptr; } //////////////////////////////////////////////////////////////////// // Function: PointerToArray::set_void_ptr // Access: Public // Description: Sets this PTA to point to the pointer passed in //////////////////////////////////////////////////////////////////// template INLINE void PointerToArray:: set_void_ptr(void* p) { reassign((RefCountObj > *)p); } //////////////////////////////////////////////////////////////////// // Function: PointerToArray::get_ref_count // Access: Public // Description: Returns the reference count of the underlying vector. //////////////////////////////////////////////////////////////////// template INLINE int PointerToArray:: get_ref_count() const { return (_ptr == NULL) ? 0 : _ptr->get_ref_count(); } //////////////////////////////////////////////////////////////////// // Function: PointerToArray::Assignment operator // Access: Public // Description: //////////////////////////////////////////////////////////////////// template INLINE PointerToArray &PointerToArray:: operator = (RefCountObj > *ptr) { reassign(ptr); return *this; } //////////////////////////////////////////////////////////////////// // Function: PointerToArray::Assignment operator // Access: Public // Description: //////////////////////////////////////////////////////////////////// template INLINE PointerToArray &PointerToArray:: operator = (const PointerToArray ©) { reassign(copy); return *this; } //////////////////////////////////////////////////////////////////// // Function: PointerToArray::clear // Access: Public // Description: To empty the PTA, use the clear() method, since // assignment to NULL is problematic (given the // ambiguity of the pointer type of NULL). //////////////////////////////////////////////////////////////////// template INLINE void PointerToArray:: clear() { reassign((RefCountObj > *)NULL); } //////////////////////////////////////////////////////////////////// // Function: ConstPointerToArray::Constructor // Access: Public // Description: //////////////////////////////////////////////////////////////////// template INLINE ConstPointerToArray:: ConstPointerToArray() : PointerToBase > >((RefCountObj > *)NULL) { } //////////////////////////////////////////////////////////////////// // Function: ConstPointerToArray::Copy Constructor // Access: Public // Description: //////////////////////////////////////////////////////////////////// template INLINE ConstPointerToArray:: ConstPointerToArray(const PointerToArray ©) : PointerToBase > >(copy) { } //////////////////////////////////////////////////////////////////// // Function: ConstPointerToArray::Copy Constructor // Access: Public // Description: //////////////////////////////////////////////////////////////////// template INLINE ConstPointerToArray:: ConstPointerToArray(const ConstPointerToArray ©) : PointerToBase > >(copy) { } //////////////////////////////////////////////////////////////////// // Function: ConstPointerToArray::begin // Access: Public // Description: //////////////////////////////////////////////////////////////////// template INLINE ConstPointerToArray::iterator ConstPointerToArray:: begin() const { if (_ptr == NULL) { return _empty_array.begin(); } return _ptr->begin(); } //////////////////////////////////////////////////////////////////// // Function: ConstPointerToArray::end // Access: Public // Description: //////////////////////////////////////////////////////////////////// template INLINE ConstPointerToArray::iterator ConstPointerToArray:: end() const { if (_ptr == NULL) { return _empty_array.begin(); } return _ptr->end(); } //////////////////////////////////////////////////////////////////// // Function: ConstPointerToArray::rbegin // Access: Public // Description: //////////////////////////////////////////////////////////////////// template INLINE ConstPointerToArray::reverse_iterator ConstPointerToArray:: rbegin() const { if (_ptr == NULL) { return _empty_array.rbegin(); } return _ptr->rbegin(); } //////////////////////////////////////////////////////////////////// // Function: ConstPointerToArray::rend // Access: Public // Description: //////////////////////////////////////////////////////////////////// template INLINE ConstPointerToArray::reverse_iterator ConstPointerToArray:: rend() const { if (_ptr == NULL) { return _empty_array.rbegin(); } return _ptr->rend(); } //////////////////////////////////////////////////////////////////// // Function: ConstPointerToArray::size // Access: Public // Description: //////////////////////////////////////////////////////////////////// template INLINE ConstPointerToArray::size_type ConstPointerToArray:: size() const { return (_ptr == NULL) ? 0 : _ptr->size(); } //////////////////////////////////////////////////////////////////// // Function: ConstPointerToArray::max_size // Access: Public // Description: //////////////////////////////////////////////////////////////////// template INLINE ConstPointerToArray::size_type ConstPointerToArray:: max_size() const { nassertd(_ptr != NULL) { ((ConstPointerToArray *)this)->reassign(new RefCountObj >); } return _ptr->max_size(); } //////////////////////////////////////////////////////////////////// // Function: ConstPointerToArray::empty // Access: Public // Description: //////////////////////////////////////////////////////////////////// template INLINE bool ConstPointerToArray:: empty() const { return (_ptr == NULL) ? true : _ptr->empty(); } //////////////////////////////////////////////////////////////////// // Function: ConstPointerToArray::capacity // Access: Public // Description: //////////////////////////////////////////////////////////////////// template INLINE ConstPointerToArray::size_type ConstPointerToArray:: capacity() const { nassertd(_ptr != NULL) { ((ConstPointerToArray *)this)->reassign(new RefCountObj >); } return _ptr->capacity(); } #ifndef WIN32_VC //////////////////////////////////////////////////////////////////// // Function: ConstPointerToArray::Indexing operator // Access: Public // Description: //////////////////////////////////////////////////////////////////// template INLINE ConstPointerToArray::reference ConstPointerToArray:: operator[](size_type n) const { nassertd(_ptr != NULL) { ((ConstPointerToArray *)this)->reassign(new RefCountObj >); } nassertd(!_ptr->empty()) { _ptr->push_back(Element()); } nassertr(n < _ptr->size(), _ptr->operator[](0)); return _ptr->operator[](n); } #endif //////////////////////////////////////////////////////////////////// // Function: ConstPointerToArray::front // Access: Public // Description: //////////////////////////////////////////////////////////////////// template INLINE ConstPointerToArray::reference ConstPointerToArray:: front() const { nassertd(_ptr != NULL) { ((ConstPointerToArray *)this)->reassign(new RefCountObj >); } nassertd(!_ptr->empty()) { _ptr->push_back(Element()); } return _ptr->front(); } //////////////////////////////////////////////////////////////////// // Function: ConstPointerToArray::back // Access: Public // Description: //////////////////////////////////////////////////////////////////// template INLINE ConstPointerToArray::reference ConstPointerToArray:: back() const { nassertd(_ptr != NULL) { ((ConstPointerToArray *)this)->reassign(new RefCountObj >); } nassertd(!_ptr->empty()) { _ptr->push_back(Element()); } return _ptr->back(); } //////////////////////////////////////////////////////////////////// // Function: ConstPointerToArray::Typecast operator // Access: Public // Description: The pointer typecast operator is convenient for // maintaining the fiction that we actually have a // C-style array. It returns the address of the first // element in the array, unless the pointer is // unassigned, in which case it returns NULL. //////////////////////////////////////////////////////////////////// template INLINE ConstPointerToArray:: operator const Element *() const { return (_ptr == NULL) ? (const Element *)NULL : &(_ptr->front()); } //////////////////////////////////////////////////////////////////// // Function: ConstPointerToArray::p // Access: Public // Description: Function p() is similar to the function from // ConstPointerTo. It does the same thing: it returns the // same thing as the typecast operator, above. //////////////////////////////////////////////////////////////////// template INLINE const Element *ConstPointerToArray:: p() const { return (_ptr == NULL) ? (const Element *)NULL : &(_ptr->front()); } //////////////////////////////////////////////////////////////////// // Function: ConstPointerToArray::v // Access: Public // Description: To access the vector itself, for more direct fiddling // with some of the vector's esoteric functionality. //////////////////////////////////////////////////////////////////// template INLINE const vector &ConstPointerToArray:: v() const { nassertd(_ptr != NULL) { ((ConstPointerToArray *)this)->reassign(new RefCountObj >); } return *_ptr; } //////////////////////////////////////////////////////////////////// // Function: ConstPointerToArray::get_ref_count // Access: Public // Description: Returns the reference count of the underlying vector. //////////////////////////////////////////////////////////////////// template INLINE int ConstPointerToArray:: get_ref_count() const { return (_ptr == NULL) ? 0 : _ptr->get_ref_count(); } //////////////////////////////////////////////////////////////////// // Function: ConstPointerToArray::Assignment operator // Access: Public // Description: //////////////////////////////////////////////////////////////////// template INLINE ConstPointerToArray &ConstPointerToArray:: operator = (RefCountObj > *ptr) { reassign(ptr); return *this; } //////////////////////////////////////////////////////////////////// // Function: ConstPointerToArray::Assignment operator // Access: Public // Description: //////////////////////////////////////////////////////////////////// template INLINE ConstPointerToArray &ConstPointerToArray:: operator = (const PointerToArray ©) { reassign(copy); return *this; } //////////////////////////////////////////////////////////////////// // Function: ConstPointerToArray::Assignment operator // Access: Public // Description: //////////////////////////////////////////////////////////////////// template INLINE ConstPointerToArray &ConstPointerToArray:: operator = (const ConstPointerToArray ©) { reassign(copy); return *this; } //////////////////////////////////////////////////////////////////// // Function: ConstPointerToArray::clear // Access: Public // Description: To empty the PTA, use the clear() method, since // assignment to NULL is problematic (given the // ambiguity of the pointer type of NULL). //////////////////////////////////////////////////////////////////// template INLINE void ConstPointerToArray:: clear() { reassign((RefCountObj > *)NULL); }