diff --git a/panda/src/express/pointerTo.I b/panda/src/express/pointerTo.I index 3d7d4568cb..4db9dfeff8 100644 --- a/panda/src/express/pointerTo.I +++ b/panda/src/express/pointerTo.I @@ -79,7 +79,7 @@ operator TYPENAME PointerToBase::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 @@ -104,7 +104,7 @@ operator = (To *ptr) { //////////////////////////////////////////////////////////////////// // Function: PointerTo::Assignment operator -// Access: Public +// Access: Published // Description: //////////////////////////////////////////////////////////////////// template @@ -191,7 +191,7 @@ operator const TYPENAME PointerToBase::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 @@ -216,7 +216,7 @@ operator = (const To *ptr) { //////////////////////////////////////////////////////////////////// // Function: ConstPointerTo::Assignment operator -// Access: Public +// Access: Published // Description: //////////////////////////////////////////////////////////////////// template @@ -228,7 +228,7 @@ operator = (const PointerTo ©) { //////////////////////////////////////////////////////////////////// // Function: ConstPointerTo::Assignment operator -// Access: Public +// Access: Published // Description: //////////////////////////////////////////////////////////////////// template diff --git a/panda/src/express/pointerTo.h b/panda/src/express/pointerTo.h index f79e3f78da..ac260c9dae 100644 --- a/panda/src/express/pointerTo.h +++ b/panda/src/express/pointerTo.h @@ -155,11 +155,10 @@ PUBLISHED: INLINE ConstPointerTo &operator = (const PointerTo ©); INLINE ConstPointerTo &operator = (const ConstPointerTo ©); - // 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::is_null(); } + // this works again in interrogate, we can remove this. INLINE void clear() { PointerToBase::clear(); } }; diff --git a/panda/src/express/pointerToArray.I b/panda/src/express/pointerToArray.I index ca627f63f2..6fe4c806d2 100644 --- a/panda/src/express/pointerToArray.I +++ b/panda/src/express/pointerToArray.I @@ -509,7 +509,7 @@ clear() { //////////////////////////////////////////////////////////////////// // Function: ConstPointerToArray::Constructor -// Access: Public +// Access: Published // Description: //////////////////////////////////////////////////////////////////// template @@ -521,7 +521,7 @@ ConstPointerToArray() : //////////////////////////////////////////////////////////////////// // Function: ConstPointerToArray::Copy Constructor -// Access: Public +// Access: Published // Description: //////////////////////////////////////////////////////////////////// template @@ -533,7 +533,7 @@ ConstPointerToArray(const PointerToArray ©) : //////////////////////////////////////////////////////////////////// // Function: ConstPointerToArray::Copy Constructor -// Access: Public +// Access: Published // Description: //////////////////////////////////////////////////////////////////// template @@ -601,7 +601,7 @@ rend() const { //////////////////////////////////////////////////////////////////// // Function: ConstPointerToArray::size -// Access: Public +// Access: Published // Description: //////////////////////////////////////////////////////////////////// template @@ -649,37 +649,6 @@ capacity() const { return ((To *)(this->_void_ptr))->capacity(); } -#ifndef WIN32_VC -//////////////////////////////////////////////////////////////////// -// Function: ConstPointerToArray::Indexing operator -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -template -INLINE TYPENAME ConstPointerToArray::reference ConstPointerToArray:: -operator [](size_type n) const { - nassertd((this->_void_ptr) != NULL) { - ((ConstPointerToArray *)this)->reassign(new RefCountObj >); - } - 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 -INLINE TYPENAME ConstPointerToArray::reference ConstPointerToArray:: -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 +INLINE TYPENAME ConstPointerToArray::reference ConstPointerToArray:: +operator [](size_type n) const { + nassertd((this->_void_ptr) != NULL) { + ((ConstPointerToArray *)this)->reassign(new RefCountObj >); + } + 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 +INLINE TYPENAME ConstPointerToArray::reference ConstPointerToArray:: +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 +INLINE const Element &ConstPointerToArray:: +get_element(size_type n) const { + return (*this)[n]; +} + //////////////////////////////////////////////////////////////////// // Function: ConstPointerToArray::Typecast operator // Access: Public diff --git a/panda/src/express/pointerToArray.h b/panda/src/express/pointerToArray.h index 5c207ea615..d977c3cc99 100644 --- a/panda/src/express/pointerToArray.h +++ b/panda/src/express/pointerToArray.h @@ -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 empty_array(size_type n); INLINE PointerToArray(size_type n, const Element &value); INLINE PointerToArray(const PointerToArray ©); @@ -217,10 +216,12 @@ public: typedef TYPENAME pvector::difference_type difference_type; typedef TYPENAME pvector::size_type size_type; +PUBLISHED: INLINE ConstPointerToArray(); INLINE ConstPointerToArray(const PointerToArray ©); INLINE ConstPointerToArray(const ConstPointerToArray ©); +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 &v() const; diff --git a/panda/src/express/pointerToBase.I b/panda/src/express/pointerToBase.I index 3be98596d3..c016b263a8 100644 --- a/panda/src/express/pointerToBase.I +++ b/panda/src/express/pointerToBase.I @@ -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 -INLINE bool PointerToBase:: -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. //////////////////////////////////////////////////////////////////// diff --git a/panda/src/express/pointerToBase.h b/panda/src/express/pointerToBase.h index 556d6cd7c9..082a563a83 100644 --- a/panda/src/express/pointerToBase.h +++ b/panda/src/express/pointerToBase.h @@ -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; diff --git a/panda/src/express/pointerToVoid.I b/panda/src/express/pointerToVoid.I index 44ed64a33d..f15f068bd0 100644 --- a/panda/src/express/pointerToVoid.I +++ b/panda/src/express/pointerToVoid.I @@ -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); +} diff --git a/panda/src/express/pointerToVoid.h b/panda/src/express/pointerToVoid.h index 853a03e05f..98bce14b45 100644 --- a/panda/src/express/pointerToVoid.h +++ b/panda/src/express/pointerToVoid.h @@ -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. diff --git a/panda/src/express/weakPointerTo.I b/panda/src/express/weakPointerTo.I index 6593a20879..22c2aa7120 100644 --- a/panda/src/express/weakPointerTo.I +++ b/panda/src/express/weakPointerTo.I @@ -59,8 +59,8 @@ WeakPointerTo(const WeakPointerTo ©) : template INLINE TYPENAME WeakPointerTo::To &WeakPointerTo:: 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 INLINE TYPENAME WeakPointerTo::To *WeakPointerTo:: 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 INLINE WeakPointerTo:: operator TYPENAME WeakPointerToBase::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::To *() const { template INLINE TYPENAME WeakPointerTo::To *WeakPointerTo:: 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 ©) { //////////////////////////////////////////////////////////////////// template INLINE WeakConstPointerTo:: -WeakConstPointerTo(const TYPENAME WeakConstPointerTo::To *ptr) : - WeakPointerToBase((TYPENAME WeakConstPointerTo::To *)ptr) +WeakConstPointerTo(const To *ptr) : + WeakPointerToBase((WeakConstPointerTo::To *)ptr) { } @@ -210,8 +210,8 @@ WeakConstPointerTo(const WeakConstPointerTo ©) : template INLINE const TYPENAME WeakConstPointerTo::To &WeakConstPointerTo:: 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 INLINE const TYPENAME WeakConstPointerTo::To *WeakConstPointerTo:: 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 INLINE WeakConstPointerTo:: operator const TYPENAME WeakPointerToBase::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::To *() const { template INLINE const TYPENAME WeakConstPointerTo::To *WeakConstPointerTo:: p() const { - nassertr(!is_null(), (To *)NULL); - return (To *)(this->_void_ptr); + nassertr(!this->was_deleted(), (To *)NULL); + return (To *)_void_ptr; } //////////////////////////////////////////////////////////////////// diff --git a/panda/src/express/weakPointerTo.h b/panda/src/express/weakPointerTo.h index 32de4ce232..351c79afd8 100644 --- a/panda/src/express/weakPointerTo.h +++ b/panda/src/express/weakPointerTo.h @@ -52,11 +52,10 @@ PUBLISHED: INLINE WeakPointerTo &operator = (const PointerTo ©); INLINE WeakPointerTo &operator = (const WeakPointerTo ©); - // 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::is_null(); } + // this works again in interrogate, we can remove this. INLINE void clear() { WeakPointerToBase::clear(); } }; diff --git a/panda/src/express/weakPointerToBase.I b/panda/src/express/weakPointerToBase.I index 86c978da62..e32c2d26f4 100644 --- a/panda/src/express/weakPointerToBase.I +++ b/panda/src/express/weakPointerToBase.I @@ -387,22 +387,9 @@ operator < (const PointerToBase &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 -INLINE bool WeakPointerToBase:: -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. //////////////////////////////////////////////////////////////////// diff --git a/panda/src/express/weakPointerToBase.h b/panda/src/express/weakPointerToBase.h index 14047c0b53..4b3d38a2ed 100644 --- a/panda/src/express/weakPointerToBase.h +++ b/panda/src/express/weakPointerToBase.h @@ -82,7 +82,6 @@ public: #endif // CPPPARSER PUBLISHED: - INLINE bool is_null() const; INLINE void clear(); void output(ostream &out) const; diff --git a/panda/src/express/weakPointerToVoid.I b/panda/src/express/weakPointerToVoid.I index b7710a03f6..410e1598c7 100644 --- a/panda/src/express/weakPointerToVoid.I +++ b/panda/src/express/weakPointerToVoid.I @@ -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; +} diff --git a/panda/src/express/weakPointerToVoid.h b/panda/src/express/weakPointerToVoid.h index 1766bebcf0..734e295b00 100644 --- a/panda/src/express/weakPointerToVoid.h +++ b/panda/src/express/weakPointerToVoid.h @@ -37,6 +37,7 @@ public: PUBLISHED: INLINE bool was_deleted() const; + INLINE bool is_valid_pointer() const; protected: bool _ptr_was_deleted;