// Filename: threadSafePointerTo.h // Created by: drose (28Apr06) // //////////////////////////////////////////////////////////////////// // // PANDA 3D SOFTWARE // Copyright (c) 2001 - 2004, Disney Enterprises, Inc. All rights reserved // // All use of this software is subject to the terms of the Panda 3d // Software license. You should have received a copy of this license // along with this source code; you will also find a current copy of // the license at http://etc.cmu.edu/panda3d/docs/license/ . // // To contact the maintainers of this program write to // panda3d-general@lists.sourceforge.net . // //////////////////////////////////////////////////////////////////// #ifndef THREADSAFEPOINTERTO_H #define THREADSAFEPOINTERTO_H #include "pandabase.h" #include "threadSafePointerToBase.h" //////////////////////////////////////////////////////////////////// // Class : ThreadSafePointerTo // Description : This works exactly like PointerTo, except that the // object is designed to be thread-safe: it is generally // safe to make unprotected assignments to this pointer, // in the sense that the last assignment will win and // the reference counts will be properly maintained. //////////////////////////////////////////////////////////////////// template class ThreadSafePointerTo : public ThreadSafePointerToBase { public: typedef TYPENAME ThreadSafePointerToBase::To To; PUBLISHED: INLINE ThreadSafePointerTo(To *ptr = (To *)NULL); INLINE ThreadSafePointerTo(const ThreadSafePointerTo ©); INLINE ~ThreadSafePointerTo(); public: INLINE To &operator *() const; INLINE To *operator -> () const; // MSVC.NET 2005 insists that we use T *, and not To *, here. INLINE operator T *() const; PUBLISHED: // When downcasting to a derived class from a ThreadSafePointerTo, // C++ would normally require you to cast twice: once to an actual // BaseClass pointer, and then again to your desired pointer. You // can use the handy function p() to avoid this first cast and make // your code look a bit cleaner. // e.g. instead of (MyType *)(BaseClass *)ptr, use (MyType *)ptr.p() // If your base class is a derivative of TypedObject, you might want // to use the DCAST macro defined in typedObject.h instead, // e.g. DCAST(MyType, ptr). This provides a clean downcast that // doesn't require .p() or any double-casting, and it can be // run-time checked for correctness. INLINE To *p() const; INLINE ThreadSafePointerTo &operator = (To *ptr); INLINE ThreadSafePointerTo &operator = (const ThreadSafePointerTo ©); // These 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 ThreadSafePointerToBase class). When // this works again in interrogate, we can remove these. INLINE bool is_null() const { return ThreadSafePointerToBase::is_null(); } INLINE void clear() { ThreadSafePointerToBase::clear(); } }; //////////////////////////////////////////////////////////////////// // Class : ThreadSafeConstPointerTo // Description : //////////////////////////////////////////////////////////////////// template class ThreadSafeConstPointerTo : public ThreadSafePointerToBase { public: typedef TYPENAME ThreadSafePointerToBase::To To; PUBLISHED: INLINE ThreadSafeConstPointerTo(const To *ptr = (const To *)NULL); INLINE ThreadSafeConstPointerTo(const ThreadSafePointerTo ©); INLINE ThreadSafeConstPointerTo(const ThreadSafeConstPointerTo ©); INLINE ~ThreadSafeConstPointerTo(); public: INLINE const To &operator *() const; INLINE const To *operator -> () const; INLINE operator const T *() const; PUBLISHED: INLINE const To *p() const; INLINE ThreadSafeConstPointerTo &operator = (const To *ptr); INLINE ThreadSafeConstPointerTo &operator = (const ThreadSafePointerTo ©); INLINE ThreadSafeConstPointerTo &operator = (const ThreadSafeConstPointerTo ©); // 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 ThreadSafePointerToBase class). When // this works again in interrogate, we can remove this. INLINE void clear() { ThreadSafePointerToBase::clear(); } }; #define TSPT(type) ThreadSafePointerTo< type > #define TSCPT(type) ThreadSafeConstPointerTo< type > #include "threadSafePointerTo.I" #endif