Panda3D

threadSafePointerToBase.h

00001 // Filename: threadSafePointerToBase.h
00002 // Created by:  drose (28Apr06)
00003 //
00004 ////////////////////////////////////////////////////////////////////
00005 //
00006 // PANDA 3D SOFTWARE
00007 // Copyright (c) Carnegie Mellon University.  All rights reserved.
00008 //
00009 // All use of this software is subject to the terms of the revised BSD
00010 // license.  You should have received a copy of this license along
00011 // with this source code in a file named "LICENSE."
00012 //
00013 ////////////////////////////////////////////////////////////////////
00014 
00015 #ifndef THREADSAFEPOINTERTOBASE_H
00016 #define THREADSAFEPOINTERTOBASE_H
00017 
00018 #include "pandabase.h"
00019 #include "pointerToVoid.h"
00020 #include "referenceCount.h"
00021 #include "typedef.h"
00022 #include "memoryUsage.h"
00023 #include "config_express.h"
00024 #include "atomicAdjust.h"
00025 
00026 ////////////////////////////////////////////////////////////////////
00027 //       Class : ThreadSafePointerToBase
00028 // Description : This is the base class for ThreadSafePointerTo and
00029 //               ThreadSafeConstPointerTo.  Don't try to use it
00030 //               directly; use either derived class instead.
00031 ////////////////////////////////////////////////////////////////////
00032 template <class T>
00033 class ThreadSafePointerToBase : public PointerToVoid {
00034 public:
00035   typedef T To;
00036 
00037 protected:
00038   INLINE ThreadSafePointerToBase(To *ptr);
00039   INLINE ThreadSafePointerToBase(const ThreadSafePointerToBase<T> &copy);
00040   INLINE ~ThreadSafePointerToBase();
00041 
00042   INLINE void reassign(To *ptr);
00043   INLINE void reassign(const ThreadSafePointerToBase<To> &copy);
00044 
00045 #ifdef DO_MEMORY_USAGE
00046   void update_type(To *ptr);
00047 #endif  // DO_MEMORY_USAGE
00048 
00049   // No assignment or retrieval functions are declared in
00050   // ThreadSafePointerToBase, because we will have to specialize on const
00051   // vs. non-const later.
00052 
00053 PUBLISHED:
00054   INLINE void clear();
00055 
00056   void output(ostream &out) const;
00057 };
00058 
00059 template<class T>
00060 INLINE ostream &operator <<(ostream &out, const ThreadSafePointerToBase<T> &pointer) {
00061   pointer.output(out);
00062   return out;
00063 }
00064 
00065 #include "threadSafePointerToBase.I"
00066 
00067 #endif
 All Classes Functions Variables Enumerations