PointerHandle.h

Go to the documentation of this file.
00001 #ifndef __POINTERHANDLE_H__
00002 #define __POINTERHANDLE_H__
00003 
00004 #include <map>
00005 
00006 #include "../debug/DebugUtils.h"
00007 
00008 namespace oasys {
00009 
00015 template <
00016     typename _PtrType          // type of pointer being stored
00017 >
00018 class PointerHandle {
00019 public:
00023     PointerHandle() : ptr_(0) {}
00024     
00028     virtual ~PointerHandle() { ptr_ = 0; }
00029 
00031     _PtrType& operator*() const {
00032         restore_and_update();
00033         return *ptr_;
00034     }    
00035     _PtrType* operator->() const {
00036         restore_and_update();
00037         return ptr_;
00038     }
00040 
00042     _PtrType* ptr() const { 
00043         restore_and_update();
00044         return ptr_; 
00045     }
00046     
00047 protected:
00048     mutable _PtrType* ptr_;
00049 
00054     virtual void invalidate() const = 0;
00055     
00060     virtual void restore() const = 0;
00061 
00065     virtual void update() const = 0;
00066 
00067     void restore_and_update() const {
00068         if (ptr_ == 0) {
00069             restore();
00070             ASSERT(ptr_ != 0);
00071         }
00072         update();
00073     }
00074 };
00075 
00076 } // namespace oasys
00077 
00078 #endif /* __POINTERHANDLE_H__ */

Generated on Fri Dec 22 14:48:00 2006 for DTN Reference Implementation by  doxygen 1.5.1