Advertisement
snake5

SGRX - handle for refcounted objects

Dec 24th, 2015
442
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.54 KB | None | 0 0
  1. template< class T >
  2. struct Handle
  3. {
  4.     typedef T subtype;
  5.     T* item;
  6.    
  7.     Handle() : item( NULL ){}
  8.     Handle( T* v ) : item( v ){ if( item ) item->Acquire(); }
  9.     Handle( const Handle& h ) : item( h.item ){ if( item ) item->Acquire(); }
  10.     ~Handle(){ if( item ){ item->Release(); item = NULL; } }
  11.     Handle& operator = ( const Handle& h ){ if( item ) item->Release(); item = h.item; if( item ) item->Acquire(); return *this; }
  12.     T* operator -> () const { return item; }
  13.     T& operator * () const { return *item; }
  14.     operator T* () const { return item; }
  15. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement