mirror of
https://github.com/panda3d/panda3d.git
synced 2025-10-04 10:54:24 -04:00
robustify WeakPointerTo, publish ConstPointerTo
This commit is contained in:
parent
7f629a8662
commit
475196cbef
@ -79,7 +79,7 @@ operator TYPENAME PointerToBase<T>::To *() const {
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: PointerTo::p
|
||||
// Access: Public
|
||||
// Access: Published
|
||||
// Description: Returns an ordinary pointer instead of a PointerTo.
|
||||
// Useful to work around compiler problems, particularly
|
||||
// for implicit upcasts.
|
||||
@ -92,7 +92,7 @@ p() const {
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: PointerTo::Assignment operator
|
||||
// Access: Public
|
||||
// Access: Published
|
||||
// Description:
|
||||
////////////////////////////////////////////////////////////////////
|
||||
template<class T>
|
||||
@ -104,7 +104,7 @@ operator = (To *ptr) {
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: PointerTo::Assignment operator
|
||||
// Access: Public
|
||||
// Access: Published
|
||||
// Description:
|
||||
////////////////////////////////////////////////////////////////////
|
||||
template<class T>
|
||||
@ -191,7 +191,7 @@ operator const TYPENAME PointerToBase<T>::To *() const {
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: ConstPointerTo::p
|
||||
// Access: Public
|
||||
// Access: Published
|
||||
// Description: Returns an ordinary pointer instead of a ConstPointerTo.
|
||||
// Useful to work around compiler problems, particularly
|
||||
// for implicit upcasts.
|
||||
@ -204,7 +204,7 @@ p() const {
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: ConstPointerTo::Assignment operator
|
||||
// Access: Public
|
||||
// Access: Published
|
||||
// Description:
|
||||
////////////////////////////////////////////////////////////////////
|
||||
template<class T>
|
||||
@ -216,7 +216,7 @@ operator = (const To *ptr) {
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: ConstPointerTo::Assignment operator
|
||||
// Access: Public
|
||||
// Access: Published
|
||||
// Description:
|
||||
////////////////////////////////////////////////////////////////////
|
||||
template<class T>
|
||||
@ -228,7 +228,7 @@ operator = (const PointerTo<T> ©) {
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: ConstPointerTo::Assignment operator
|
||||
// Access: Public
|
||||
// Access: Published
|
||||
// Description:
|
||||
////////////////////////////////////////////////////////////////////
|
||||
template<class T>
|
||||
|
@ -155,11 +155,10 @@ PUBLISHED:
|
||||
INLINE ConstPointerTo<T> &operator = (const PointerTo<T> ©);
|
||||
INLINE ConstPointerTo<T> &operator = (const ConstPointerTo<T> ©);
|
||||
|
||||
// These functions normally wouldn't need to be redefined here, but
|
||||
// This functions normally wouldn't need to be redefined here, but
|
||||
// we do so anyway just to help out interrogate (which doesn't seem
|
||||
// to want to automatically export the PointerToBase class). When
|
||||
// this works again in interrogate, we can remove these.
|
||||
INLINE bool is_null() const { return PointerToBase<T>::is_null(); }
|
||||
// this works again in interrogate, we can remove this.
|
||||
INLINE void clear() { PointerToBase<T>::clear(); }
|
||||
};
|
||||
|
||||
|
@ -509,7 +509,7 @@ clear() {
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: ConstPointerToArray::Constructor
|
||||
// Access: Public
|
||||
// Access: Published
|
||||
// Description:
|
||||
////////////////////////////////////////////////////////////////////
|
||||
template<class Element>
|
||||
@ -521,7 +521,7 @@ ConstPointerToArray() :
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: ConstPointerToArray::Copy Constructor
|
||||
// Access: Public
|
||||
// Access: Published
|
||||
// Description:
|
||||
////////////////////////////////////////////////////////////////////
|
||||
template<class Element>
|
||||
@ -533,7 +533,7 @@ ConstPointerToArray(const PointerToArray<Element> ©) :
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: ConstPointerToArray::Copy Constructor
|
||||
// Access: Public
|
||||
// Access: Published
|
||||
// Description:
|
||||
////////////////////////////////////////////////////////////////////
|
||||
template<class Element>
|
||||
@ -601,7 +601,7 @@ rend() const {
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: ConstPointerToArray::size
|
||||
// Access: Public
|
||||
// Access: Published
|
||||
// Description:
|
||||
////////////////////////////////////////////////////////////////////
|
||||
template<class Element>
|
||||
@ -649,37 +649,6 @@ capacity() const {
|
||||
return ((To *)(this->_void_ptr))->capacity();
|
||||
}
|
||||
|
||||
#ifndef WIN32_VC
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: ConstPointerToArray::Indexing operator
|
||||
// Access: Public
|
||||
// Description:
|
||||
////////////////////////////////////////////////////////////////////
|
||||
template<class Element>
|
||||
INLINE TYPENAME ConstPointerToArray<Element>::reference ConstPointerToArray<Element>::
|
||||
operator [](size_type n) const {
|
||||
nassertd((this->_void_ptr) != NULL) {
|
||||
((ConstPointerToArray<Element> *)this)->reassign(new RefCountObj<pvector<Element> >);
|
||||
}
|
||||
nassertd(!((To *)(this->_void_ptr))->empty()) {
|
||||
((To *)(this->_void_ptr))->push_back(Element());
|
||||
}
|
||||
nassertr(n < ((To *)(this->_void_ptr))->size(), ((To *)(this->_void_ptr))->operator[](0));
|
||||
return ((To *)(this->_void_ptr))->operator[](n);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: ConstPointerToArray::Indexing operator
|
||||
// Access: Published
|
||||
// Description:
|
||||
////////////////////////////////////////////////////////////////////
|
||||
template<class Element>
|
||||
INLINE TYPENAME ConstPointerToArray<Element>::reference ConstPointerToArray<Element>::
|
||||
operator [](int n) const {
|
||||
return operator[]((size_type)n);
|
||||
}
|
||||
#endif
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: ConstPointerToArray::front
|
||||
// Access: Public
|
||||
@ -714,6 +683,52 @@ back() const {
|
||||
return ((To *)(this->_void_ptr))->back();
|
||||
}
|
||||
|
||||
#ifndef WIN32_VC
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: ConstPointerToArray::Indexing operator
|
||||
// Access: Published
|
||||
// Description:
|
||||
////////////////////////////////////////////////////////////////////
|
||||
template<class Element>
|
||||
INLINE TYPENAME ConstPointerToArray<Element>::reference ConstPointerToArray<Element>::
|
||||
operator [](size_type n) const {
|
||||
nassertd((this->_void_ptr) != NULL) {
|
||||
((ConstPointerToArray<Element> *)this)->reassign(new RefCountObj<pvector<Element> >);
|
||||
}
|
||||
nassertd(!((To *)(this->_void_ptr))->empty()) {
|
||||
((To *)(this->_void_ptr))->push_back(Element());
|
||||
}
|
||||
nassertr(n < ((To *)(this->_void_ptr))->size(), ((To *)(this->_void_ptr))->operator[](0));
|
||||
return ((To *)(this->_void_ptr))->operator[](n);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: ConstPointerToArray::Indexing operator
|
||||
// Access: Published
|
||||
// Description:
|
||||
////////////////////////////////////////////////////////////////////
|
||||
template<class Element>
|
||||
INLINE TYPENAME ConstPointerToArray<Element>::reference ConstPointerToArray<Element>::
|
||||
operator [](int n) const {
|
||||
return operator[]((size_type)n);
|
||||
}
|
||||
#endif
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: ConstPointerToArray::get_element
|
||||
// Access: Published
|
||||
// Description: This method exists mainly to access the elements of
|
||||
// the array easily from a high-level language such as
|
||||
// Python, especially on Windows, where the above index
|
||||
// element accessor methods can't be defined because of
|
||||
// a confusion with the pointer typecast operator.
|
||||
////////////////////////////////////////////////////////////////////
|
||||
template<class Element>
|
||||
INLINE const Element &ConstPointerToArray<Element>::
|
||||
get_element(size_type n) const {
|
||||
return (*this)[n];
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: ConstPointerToArray::Typecast operator
|
||||
// Access: Public
|
||||
|
@ -104,7 +104,6 @@ public:
|
||||
|
||||
PUBLISHED:
|
||||
INLINE PointerToArray();
|
||||
// INLINE PointerToArray(size_type n); this is too dangerous to use, since arrays created automatically for any const parameter, use empty_array instead
|
||||
INLINE static PointerToArray<Element> empty_array(size_type n);
|
||||
INLINE PointerToArray(size_type n, const Element &value);
|
||||
INLINE PointerToArray(const PointerToArray<Element> ©);
|
||||
@ -217,10 +216,12 @@ public:
|
||||
typedef TYPENAME pvector<Element>::difference_type difference_type;
|
||||
typedef TYPENAME pvector<Element>::size_type size_type;
|
||||
|
||||
PUBLISHED:
|
||||
INLINE ConstPointerToArray();
|
||||
INLINE ConstPointerToArray(const PointerToArray<Element> ©);
|
||||
INLINE ConstPointerToArray(const ConstPointerToArray<Element> ©);
|
||||
|
||||
public:
|
||||
// Duplicating the interface of vector.
|
||||
|
||||
INLINE iterator begin() const;
|
||||
@ -231,19 +232,26 @@ public:
|
||||
// Equality and comparison operators are pointerwise for
|
||||
// PointerToArrays, not elementwise as in vector.
|
||||
|
||||
PUBLISHED:
|
||||
INLINE size_type size() const;
|
||||
|
||||
public:
|
||||
INLINE size_type max_size() const;
|
||||
INLINE bool empty() const;
|
||||
|
||||
// Functions specific to vectors.
|
||||
INLINE size_type capacity() const;
|
||||
INLINE reference front() const;
|
||||
INLINE reference back() const;
|
||||
|
||||
PUBLISHED:
|
||||
#ifndef WIN32_VC
|
||||
INLINE reference operator [](size_type n) const;
|
||||
INLINE reference operator [](int n) const;
|
||||
#endif
|
||||
INLINE reference front() const;
|
||||
INLINE reference back() const;
|
||||
INLINE const Element &get_element(size_type n) const;
|
||||
|
||||
public:
|
||||
INLINE operator const Element *() const;
|
||||
INLINE const Element *p() const;
|
||||
INLINE const pvector<Element> &v() const;
|
||||
|
@ -309,22 +309,9 @@ get_hash() const {
|
||||
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: PointerToBase::is_null
|
||||
// Access: Public
|
||||
// Description: Returns true if the PointerTo is a NULL pointer,
|
||||
// false otherwise. (Direct comparison to a NULL
|
||||
// pointer also works.)
|
||||
////////////////////////////////////////////////////////////////////
|
||||
template<class T>
|
||||
INLINE bool PointerToBase<T>::
|
||||
is_null() const {
|
||||
return (_void_ptr == (void *)NULL);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: PointerToBase::clear
|
||||
// Access: Public
|
||||
// Access: Published
|
||||
// Description: A convenient way to set the PointerTo object to NULL.
|
||||
// (Assignment to a NULL pointer also works, of course.)
|
||||
////////////////////////////////////////////////////////////////////
|
||||
@ -336,7 +323,7 @@ clear() {
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: PointerToBase::output
|
||||
// Access: Public
|
||||
// Access: Published
|
||||
// Description: A handy function to output PointerTo's as a hex
|
||||
// pointer followed by a reference count.
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
@ -77,7 +77,6 @@ public:
|
||||
INLINE size_t get_hash() const;
|
||||
|
||||
PUBLISHED:
|
||||
INLINE bool is_null() const;
|
||||
INLINE void clear();
|
||||
|
||||
void output(ostream &out) const;
|
||||
|
@ -36,3 +36,15 @@ INLINE PointerToVoid::
|
||||
~PointerToVoid() {
|
||||
nassertv(_void_ptr == (void *)NULL);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: PointerToVoid::is_null
|
||||
// Access: Published
|
||||
// Description: Returns true if the PointerTo is a NULL pointer,
|
||||
// false otherwise. (Direct comparison to a NULL
|
||||
// pointer also works.)
|
||||
////////////////////////////////////////////////////////////////////
|
||||
INLINE bool PointerToVoid::
|
||||
is_null() const {
|
||||
return (_void_ptr == (void *)NULL);
|
||||
}
|
||||
|
@ -38,6 +38,10 @@ protected:
|
||||
INLINE PointerToVoid();
|
||||
INLINE ~PointerToVoid();
|
||||
|
||||
PUBLISHED:
|
||||
INLINE bool is_null() const;
|
||||
|
||||
protected:
|
||||
// Within the PointerToVoid class, we only store a void pointer.
|
||||
// This is actually the (To *) pointer that is typecast to (void *)
|
||||
// from the derived template classes.
|
||||
|
@ -59,8 +59,8 @@ WeakPointerTo(const WeakPointerTo<T> ©) :
|
||||
template<class T>
|
||||
INLINE TYPENAME WeakPointerTo<T>::To &WeakPointerTo<T>::
|
||||
operator *() const {
|
||||
nassertr(!is_null(), *((To *)NULL));
|
||||
return *((To *)(this->_void_ptr));
|
||||
nassertr(!this->was_deleted(), *((To *)NULL));
|
||||
return *((To *)_void_ptr);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
@ -71,8 +71,8 @@ operator *() const {
|
||||
template<class T>
|
||||
INLINE TYPENAME WeakPointerTo<T>::To *WeakPointerTo<T>::
|
||||
operator -> () const {
|
||||
nassertr(!is_null(), (To *)NULL);
|
||||
return (To *)(this->_void_ptr);
|
||||
nassertr(!this->was_deleted(), (To *)NULL);
|
||||
return (To *)_void_ptr;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
@ -88,8 +88,8 @@ operator -> () const {
|
||||
template<class T>
|
||||
INLINE WeakPointerTo<T>::
|
||||
operator TYPENAME WeakPointerToBase<T>::To *() const {
|
||||
nassertr(!is_null(), (To *)NULL);
|
||||
return (To *)(this->_void_ptr);
|
||||
nassertr(!this->was_deleted(), (To *)NULL);
|
||||
return (To *)_void_ptr;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
@ -102,8 +102,8 @@ operator TYPENAME WeakPointerToBase<T>::To *() const {
|
||||
template<class T>
|
||||
INLINE TYPENAME WeakPointerTo<T>::To *WeakPointerTo<T>::
|
||||
p() const {
|
||||
nassertr(!is_null(), (To *)NULL);
|
||||
return (To *)(this->_void_ptr);
|
||||
nassertr(!this->was_deleted(), (To *)NULL);
|
||||
return (To *)_void_ptr;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
@ -149,8 +149,8 @@ operator = (const WeakPointerTo<T> ©) {
|
||||
////////////////////////////////////////////////////////////////////
|
||||
template<class T>
|
||||
INLINE WeakConstPointerTo<T>::
|
||||
WeakConstPointerTo(const TYPENAME WeakConstPointerTo<T>::To *ptr) :
|
||||
WeakPointerToBase<T>((TYPENAME WeakConstPointerTo<T>::To *)ptr)
|
||||
WeakConstPointerTo(const To *ptr) :
|
||||
WeakPointerToBase<T>((WeakConstPointerTo<T>::To *)ptr)
|
||||
{
|
||||
}
|
||||
|
||||
@ -210,8 +210,8 @@ WeakConstPointerTo(const WeakConstPointerTo<T> ©) :
|
||||
template<class T>
|
||||
INLINE const TYPENAME WeakConstPointerTo<T>::To &WeakConstPointerTo<T>::
|
||||
operator *() const {
|
||||
nassertr(!is_null(), *((To *)NULL));
|
||||
return *((To *)(this->_void_ptr));
|
||||
nassertr(!this->was_deleted(), *((To *)NULL));
|
||||
return *((To *)_void_ptr);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
@ -222,8 +222,8 @@ operator *() const {
|
||||
template<class T>
|
||||
INLINE const TYPENAME WeakConstPointerTo<T>::To *WeakConstPointerTo<T>::
|
||||
operator -> () const {
|
||||
nassertr(!is_null(), (To *)NULL);
|
||||
return (To *)(this->_void_ptr);
|
||||
nassertr(!this->was_deleted(), (To *)NULL);
|
||||
return (To *)_void_ptr;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
@ -240,8 +240,8 @@ operator -> () const {
|
||||
template<class T>
|
||||
INLINE WeakConstPointerTo<T>::
|
||||
operator const TYPENAME WeakPointerToBase<T>::To *() const {
|
||||
nassertr(!is_null(), (To *)NULL);
|
||||
return (To *)(this->_void_ptr);
|
||||
nassertr(!this->was_deleted(), (To *)NULL);
|
||||
return (To *)_void_ptr;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
@ -254,8 +254,8 @@ operator const TYPENAME WeakPointerToBase<T>::To *() const {
|
||||
template<class T>
|
||||
INLINE const TYPENAME WeakConstPointerTo<T>::To *WeakConstPointerTo<T>::
|
||||
p() const {
|
||||
nassertr(!is_null(), (To *)NULL);
|
||||
return (To *)(this->_void_ptr);
|
||||
nassertr(!this->was_deleted(), (To *)NULL);
|
||||
return (To *)_void_ptr;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
@ -52,11 +52,10 @@ PUBLISHED:
|
||||
INLINE WeakPointerTo<T> &operator = (const PointerTo<T> ©);
|
||||
INLINE WeakPointerTo<T> &operator = (const WeakPointerTo<T> ©);
|
||||
|
||||
// These functions normally wouldn't need to be redefined here, but
|
||||
// This function normally wouldn't need to be redefined here, but
|
||||
// we do so anyway just to help out interrogate (which doesn't seem
|
||||
// to want to automatically export the WeakPointerToBase class). When
|
||||
// this works again in interrogate, we can remove these.
|
||||
INLINE bool is_null() const { return WeakPointerToBase<T>::is_null(); }
|
||||
// this works again in interrogate, we can remove this.
|
||||
INLINE void clear() { WeakPointerToBase<T>::clear(); }
|
||||
};
|
||||
|
||||
|
@ -387,22 +387,9 @@ operator < (const PointerToBase<To> &other) const {
|
||||
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: WeakPointerToBase::is_null
|
||||
// Access: Public
|
||||
// Description: Returns true if the PointerTo is a NULL pointer,
|
||||
// false otherwise. (Direct comparison to a NULL
|
||||
// pointer also works.)
|
||||
////////////////////////////////////////////////////////////////////
|
||||
template<class T>
|
||||
INLINE bool WeakPointerToBase<T>::
|
||||
is_null() const {
|
||||
return (_void_ptr == (void *)NULL);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: WeakPointerToBase::clear
|
||||
// Access: Public
|
||||
// Access: Published
|
||||
// Description: A convenient way to set the PointerTo object to NULL.
|
||||
// (Assignment to a NULL pointer also works, of course.)
|
||||
////////////////////////////////////////////////////////////////////
|
||||
@ -414,7 +401,7 @@ clear() {
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: WeakPointerToBase::output
|
||||
// Access: Public
|
||||
// Access: Published
|
||||
// Description: A handy function to output PointerTo's as a hex
|
||||
// pointer followed by a reference count.
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
@ -82,7 +82,6 @@ public:
|
||||
#endif // CPPPARSER
|
||||
|
||||
PUBLISHED:
|
||||
INLINE bool is_null() const;
|
||||
INLINE void clear();
|
||||
|
||||
void output(ostream &out) const;
|
||||
|
@ -43,7 +43,7 @@ mark_deleted() {
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: WeakPointerToVoid::was_deleted
|
||||
// Access: Public
|
||||
// Access: Published
|
||||
// Description: Returns true if the object we are pointing to has
|
||||
// been deleted, false otherwise.
|
||||
////////////////////////////////////////////////////////////////////
|
||||
@ -51,3 +51,14 @@ INLINE bool WeakPointerToVoid::
|
||||
was_deleted() const {
|
||||
return _ptr_was_deleted;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: WeakPointerToVoid::is_valid_pointer
|
||||
// Access: Published
|
||||
// Description: Returns true if the pointer is not null and the
|
||||
// object has not been deleted.
|
||||
////////////////////////////////////////////////////////////////////
|
||||
INLINE bool WeakPointerToVoid::
|
||||
is_valid_pointer() const {
|
||||
return (_void_ptr != (void *)NULL) && !_ptr_was_deleted;
|
||||
}
|
||||
|
@ -37,6 +37,7 @@ public:
|
||||
|
||||
PUBLISHED:
|
||||
INLINE bool was_deleted() const;
|
||||
INLINE bool is_valid_pointer() const;
|
||||
|
||||
protected:
|
||||
bool _ptr_was_deleted;
|
||||
|
Loading…
x
Reference in New Issue
Block a user