| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487 |
- // Filename: pointerTo.I
- // Created by: drose (10Feb99)
- //
- ////////////////////////////////////////////////////////////////////
- ////////////////////////////////////////////////////////////////////
- // Function: PointerToBase::Constructor
- // Access: Protected
- // Description:
- ////////////////////////////////////////////////////////////////////
- template<class T>
- INLINE PointerToBase<T>::
- PointerToBase(To *ptr) {
- _ptr = (To *)NULL;
- reassign(ptr);
- }
- ////////////////////////////////////////////////////////////////////
- // Function: PointerToBase::Copy Constructor
- // Access: Protected
- // Description:
- ////////////////////////////////////////////////////////////////////
- template<class T>
- INLINE PointerToBase<T>::
- PointerToBase(const PointerToBase<T> ©) {
- _ptr = (To *)NULL;
- reassign(copy);
- }
- ////////////////////////////////////////////////////////////////////
- // Function: PointerToBase::Destructor
- // Access: Protected
- // Description:
- ////////////////////////////////////////////////////////////////////
- template<class T>
- INLINE PointerToBase<T>::
- ~PointerToBase() {
- reassign((To *)NULL);
- }
- ////////////////////////////////////////////////////////////////////
- // Function: PointerToBase::reassign
- // Access: Protected
- // Description: This is the main work of the PointerTo family. When
- // the pointer is reassigned, decrement the old
- // reference count and increment the new one.
- ////////////////////////////////////////////////////////////////////
- template<class T>
- void PointerToBase<T>::
- reassign(To *ptr) {
- if (ptr != _ptr) {
- if (_ptr != (To *)NULL) {
- unref_delete(_ptr);
- }
-
- _ptr = ptr;
- if (_ptr != (To *)NULL) {
- _ptr->ref();
- #ifndef NDEBUG
- if (MemoryUsage::get_track_memory_usage()) {
- // Make sure the MemoryUsage record knows what the TypeHandle
- // is, if we know it ourselves.
- TypeHandle type = get_type_handle(To);
- if (type == TypeHandle::none()) {
- do_init_type(To);
- type = get_type_handle(To);
- }
- if (type != TypeHandle::none()) {
- MemoryUsage::update_type(_ptr, type);
- }
- }
- #endif
- }
- }
- }
- ////////////////////////////////////////////////////////////////////
- // Function: PointerToBase::reassign
- // Access: Protected
- // Description:
- ////////////////////////////////////////////////////////////////////
- template<class T>
- INLINE void PointerToBase<T>::
- reassign(const PointerToBase<To> ©) {
- reassign(copy._ptr);
- }
- #ifndef CPPPARSER
- #ifndef WIN32_VC
- ////////////////////////////////////////////////////////////////////
- // Function: PointerToBase::Equivalence operator
- // Access: Public
- // Description:
- ////////////////////////////////////////////////////////////////////
- template<class T>
- INLINE bool PointerToBase<T>::
- operator == (const To *other) const {
- return _ptr == other;
- }
- ////////////////////////////////////////////////////////////////////
- // Function: PointerToBase::Nonequivalence operator
- // Access: Public
- // Description:
- ////////////////////////////////////////////////////////////////////
- template<class T>
- INLINE bool PointerToBase<T>::
- operator != (const To *other) const {
- return _ptr != other;
- }
- ////////////////////////////////////////////////////////////////////
- // Function: PointerToBase::Greater-than operator
- // Access: Public
- // Description:
- ////////////////////////////////////////////////////////////////////
- template<class T>
- INLINE bool PointerToBase<T>::
- operator > (const To *other) const {
- return _ptr > other;
- }
- ////////////////////////////////////////////////////////////////////
- // Function: PointerToBase::Less-than-or-equal operator
- // Access: Public
- // Description:
- ////////////////////////////////////////////////////////////////////
- template<class T>
- INLINE bool PointerToBase<T>::
- operator <= (const To *other) const {
- return _ptr <= other;
- }
- ////////////////////////////////////////////////////////////////////
- // Function: PointerToBase::Greater-than-or-equal operator
- // Access: Public
- // Description:
- ////////////////////////////////////////////////////////////////////
- template<class T>
- INLINE bool PointerToBase<T>::
- operator >= (const To *other) const {
- return _ptr >= other;
- }
- ////////////////////////////////////////////////////////////////////
- // Function: PointerToBase::Equivalence operator
- // Access: Public
- // Description:
- ////////////////////////////////////////////////////////////////////
- template<class T>
- INLINE bool PointerToBase<T>::
- operator == (const PointerToBase<To> &other) const {
- return _ptr == other._ptr;
- }
- ////////////////////////////////////////////////////////////////////
- // Function: PointerToBase::Nonequivalence operator
- // Access: Public
- // Description:
- ////////////////////////////////////////////////////////////////////
- template<class T>
- INLINE bool PointerToBase<T>::
- operator != (const PointerToBase<To> &other) const {
- return _ptr != other._ptr;
- }
- ////////////////////////////////////////////////////////////////////
- // Function: PointerToBase::Greater-than operator
- // Access: Public
- // Description:
- ////////////////////////////////////////////////////////////////////
- template<class T>
- INLINE bool PointerToBase<T>::
- operator > (const PointerToBase<To> &other) const {
- return _ptr > other._ptr;
- }
- ////////////////////////////////////////////////////////////////////
- // Function: PointerToBase::Less-than-or-equal operator
- // Access: Public
- // Description:
- ////////////////////////////////////////////////////////////////////
- template<class T>
- INLINE bool PointerToBase<T>::
- operator <= (const PointerToBase<To> &other) const {
- return _ptr <= other._ptr;
- }
- ////////////////////////////////////////////////////////////////////
- // Function: PointerToBase::Greater-than-or-equal operator
- // Access: Public
- // Description:
- ////////////////////////////////////////////////////////////////////
- template<class T>
- INLINE bool PointerToBase<T>::
- operator >= (const PointerToBase<To> &other) const {
- return _ptr >= other._ptr;
- }
- #endif // WIN32_VC
- ////////////////////////////////////////////////////////////////////
- // Function: PointerToBase::Less-than operator
- // Access: Public
- // Description:
- ////////////////////////////////////////////////////////////////////
- template<class T>
- INLINE bool PointerToBase<T>::
- operator < (const To *other) const {
- return _ptr < other;
- }
- ////////////////////////////////////////////////////////////////////
- // Function: PointerToBase::Less-than operator
- // Access: Public
- // Description:
- ////////////////////////////////////////////////////////////////////
- template<class T>
- INLINE bool PointerToBase<T>::
- operator < (const PointerToBase<To> &other) const {
- return _ptr < other._ptr;
- }
- #endif // CPPPARSER
- ////////////////////////////////////////////////////////////////////
- // 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 (_ptr == NULL);
- }
- ////////////////////////////////////////////////////////////////////
- // Function: PointerToBase::clear
- // Access: Public
- // Description: A convenient way to set the PointerTo object to NULL.
- // (Assignment to a NULL pointer also works, of course.)
- ////////////////////////////////////////////////////////////////////
- template<class T>
- INLINE void PointerToBase<T>::
- clear() {
- reassign((To *)NULL);
- }
- ////////////////////////////////////////////////////////////////////
- // Function: PointerToBase::output
- // Access: Public
- // Description: A handy function to output PointerTo's as a hex
- // pointer followed by a reference count.
- ////////////////////////////////////////////////////////////////////
- template<class T>
- INLINE void PointerToBase<T>::
- output(ostream &out) const {
- out << (void *)_ptr;
- if (_ptr != (To *)NULL) {
- out << ":" << _ptr->get_ref_count();
- }
- }
- ////////////////////////////////////////////////////////////////////
- // Function: PointerTo::Constructor
- // Access: Public
- // Description:
- ////////////////////////////////////////////////////////////////////
- template<class T>
- INLINE PointerTo<T>::
- PointerTo(To *ptr) : PointerToBase<T>(ptr) {
- }
- ////////////////////////////////////////////////////////////////////
- // Function: PointerTo::Copy Constructor
- // Access: Public
- // Description:
- ////////////////////////////////////////////////////////////////////
- template<class T>
- INLINE PointerTo<T>::
- PointerTo(const PointerTo<T> ©) :
- PointerToBase<T>((const PointerToBase<T> &)copy)
- {
- }
- ////////////////////////////////////////////////////////////////////
- // Function: PointerTo::Dereference operator
- // Access: Public
- // Description:
- ////////////////////////////////////////////////////////////////////
- template<class T>
- INLINE PointerTo<T>::To &PointerTo<T>::
- operator *() const {
- return *_ptr;
- }
- ////////////////////////////////////////////////////////////////////
- // Function: PointerTo::Member access operator
- // Access: Public
- // Description:
- ////////////////////////////////////////////////////////////////////
- template<class T>
- INLINE PointerTo<T>::To *PointerTo<T>::
- operator -> () const {
- return _ptr;
- }
- ////////////////////////////////////////////////////////////////////
- // Function: PointerTo::Typecast operator
- // Access: Public
- // Description: We also have the typecast operator to automatically
- // convert PointerTo's to the required kind of actual
- // pointer. This introduces ambiguities which the
- // compiler will resolve one way or the other, but we
- // don't care which way it goes because either will be
- // correct.
- ////////////////////////////////////////////////////////////////////
- template<class T>
- INLINE PointerTo<T>::
- operator PointerToBase<T>::To *() const {
- return _ptr;
- }
- ////////////////////////////////////////////////////////////////////
- // Function: PointerTo::p
- // Access: Public
- // Description: Returns an ordinary pointer instead of a PointerTo.
- // Useful to work around compiler problems, particularly
- // for implicit upcasts.
- ////////////////////////////////////////////////////////////////////
- template<class T>
- INLINE PointerTo<T>::To *PointerTo<T>::
- p() const {
- return _ptr;
- }
- ////////////////////////////////////////////////////////////////////
- // Function: PointerTo::Assignment operator
- // Access: Public
- // Description:
- ////////////////////////////////////////////////////////////////////
- template<class T>
- INLINE PointerTo<T> &PointerTo<T>::
- operator = (To *ptr) {
- reassign(ptr);
- return *this;
- }
- ////////////////////////////////////////////////////////////////////
- // Function: PointerTo::Assignment operator
- // Access: Public
- // Description:
- ////////////////////////////////////////////////////////////////////
- template<class T>
- INLINE PointerTo<T> &PointerTo<T>::
- operator = (const PointerTo<T> ©) {
- reassign((const PointerToBase<T> &)copy);
- return *this;
- }
- ////////////////////////////////////////////////////////////////////
- // Function: ConstPointerTo::Constructor
- // Access: Public
- // Description:
- ////////////////////////////////////////////////////////////////////
- template<class T>
- INLINE ConstPointerTo<T>::
- ConstPointerTo(const To *ptr) :
- PointerToBase<T>((ConstPointerTo<T>::To *)ptr)
- {
- }
- ////////////////////////////////////////////////////////////////////
- // Function: ConstPointerTo::Copy Constructor
- // Access: Public
- // Description:
- ////////////////////////////////////////////////////////////////////
- template<class T>
- INLINE ConstPointerTo<T>::
- ConstPointerTo(const PointerTo<T> ©) :
- PointerToBase<T>((const PointerToBase<T> &)copy)
- {
- }
- ////////////////////////////////////////////////////////////////////
- // Function: ConstPointerTo::Copy Constructor
- // Access: Public
- // Description:
- ////////////////////////////////////////////////////////////////////
- template<class T>
- INLINE ConstPointerTo<T>::
- ConstPointerTo(const ConstPointerTo<T> ©) :
- PointerToBase<T>((const PointerToBase<T> &)copy)
- {
- }
- ////////////////////////////////////////////////////////////////////
- // Function: ConstPointerTo::Dereference operator
- // Access: Public
- // Description:
- ////////////////////////////////////////////////////////////////////
- template<class T>
- INLINE const ConstPointerTo<T>::To &ConstPointerTo<T>::
- operator *() const {
- return *_ptr;
- }
- ////////////////////////////////////////////////////////////////////
- // Function: ConstPointerTo::Member access operator
- // Access: Public
- // Description:
- ////////////////////////////////////////////////////////////////////
- template<class T>
- INLINE const ConstPointerTo<T>::To *ConstPointerTo<T>::
- operator -> () const {
- return _ptr;
- }
- ////////////////////////////////////////////////////////////////////
- // Function: ConstPointerTo::Typecast operator
- // Access: Public
- // Description: We also have the typecast operator to automatically
- // convert ConstPointerTo's to the required kind of actual
- // pointer. This introduces ambiguities which the
- // compiler will resolve one way or the other, but we
- // don't care which way it goes because either will be
- // correct.
- ////////////////////////////////////////////////////////////////////
- template<class T>
- INLINE ConstPointerTo<T>::
- operator const PointerToBase<T>::To *() const {
- return _ptr;
- }
- ////////////////////////////////////////////////////////////////////
- // Function: ConstPointerTo::p
- // Access: Public
- // Description: Returns an ordinary pointer instead of a ConstPointerTo.
- // Useful to work around compiler problems, particularly
- // for implicit upcasts.
- ////////////////////////////////////////////////////////////////////
- template<class T>
- INLINE const ConstPointerTo<T>::To *ConstPointerTo<T>::
- p() const {
- return _ptr;
- }
- ////////////////////////////////////////////////////////////////////
- // Function: ConstPointerTo::Assignment operator
- // Access: Public
- // Description:
- ////////////////////////////////////////////////////////////////////
- template<class T>
- INLINE ConstPointerTo<T> &ConstPointerTo<T>::
- operator = (const To *ptr) {
- reassign((To *)ptr);
- return *this;
- }
- ////////////////////////////////////////////////////////////////////
- // Function: ConstPointerTo::Assignment operator
- // Access: Public
- // Description:
- ////////////////////////////////////////////////////////////////////
- template<class T>
- INLINE ConstPointerTo<T> &ConstPointerTo<T>::
- operator = (const ConstPointerTo<T> ©) {
- reassign((const PointerToBase<T> &)copy);
- return *this;
- }
- ////////////////////////////////////////////////////////////////////
- // Function: ConstPointerTo::Assignment operator
- // Access: Public
- // Description:
- ////////////////////////////////////////////////////////////////////
- template<class T>
- INLINE ConstPointerTo<T> &ConstPointerTo<T>::
- operator = (const PointerTo<T> ©) {
- reassign((const PointerToBase<T> &)copy);
- return *this;
- }
|