-
Notifications
You must be signed in to change notification settings - Fork 0
/
UniquePtr.h
95 lines (81 loc) · 1.1 KB
/
UniquePtr.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
#ifndef UNIQUE_POINTER_HEADER
#define UNIQUE_POINTER_HEADER
namespace Jet
{
template <class T>
class UniquePtr
{
T ptr;
public:
inline UniquePtr()
{
ptr = 0;
}
inline UniquePtr(T pointer)
{
ptr = pointer;
}
inline UniquePtr(UniquePtr<T> && other)
{
ptr = other.ptr;
other.ptr = 0;
}
inline ~UniquePtr()
{
delete ptr;
}
inline operator T()
{
return ptr;
}
inline T operator ->()
{
return ptr;
}
inline UniquePtr<T> operator = (const T p)
{
ptr = p;
return 0;
}
//returns the pointer and gets done with this
inline T Release()
{
auto temp = ptr;
ptr = 0;
return temp;
}
};
template <class T>
class UniquePtr<T[]>
{
typedef T type;
T* ptr;
public:
inline UniquePtr()
{
ptr = 0;
}
inline UniquePtr(T* pointer)
{
ptr = pointer;
}
inline UniquePtr(UniquePtr<T> && other)
{
ptr = other.ptr;
other.ptr = 0;
}
inline ~UniquePtr()
{
delete[] ptr;
}
inline operator T*()
{
return ptr;
}
//T& operator[](unsigned int id) const
//{
// return ptr[id];
//}
};
}
#endif