Sleeping Wombat Common Library  0.50.0
swCommonLibrary
UPtr.h
1 #pragma once
2 
9 template< typename WrappedType >
10 class UPtr
11 {
12 private:
13  WrappedType* m_ptr;
14 
15 public:
16  UPtr()
17  : m_ptr( nullptr )
18  {}
19 
20  UPtr( WrappedType* ptr )
21  : m_ptr( ptr )
22  {}
23 
24  ~UPtr()
25  { ReleaseResource(); }
26 
27  UPtr( const UPtr< WrappedType >& other ) = delete;
28  UPtr( UPtr< WrappedType >&& other )
29  {
30  if( this != &other)
31  {
32  m_resource = other.m_resource;
33  other.m_resource = nullptr;
34  }
35  }
36 
37 
38  void operator=( const UPtr< WrappedType >& other ) = delete;
39 
40  void operator=( UPtr< WrappedType >&& other )
41  {
42  ReleaseResource();
43 
44  m_ptr = other.m_ptr;
45  other.m_ptr = nullptr;
46  }
47 
48 
49 
50 
51  void ReleaseResource()
52  {
53  if( m_ptr )
54  delete m_ptr;
55  m_ptr = nullptr;
56  }
57 
58  void AssignPointer( WrappedType* ptr )
59  {
60  m_ptr = ptr;
61  }
62 };
Definition: UPtr.h:10