]>
Commit | Line | Data |
---|---|---|
b2e465d6 AL |
1 | // -*- mode: cpp; mode: fold -*- |
2 | // Description /*{{{*/ | |
500827ed | 3 | // $Id: sptr.h,v 1.3 2001/03/11 07:22:19 jgg Exp $ |
b2e465d6 AL |
4 | /* ###################################################################### |
5 | ||
6 | Trivial non-ref counted 'smart pointer' | |
7 | ||
8 | This is really only good to eliminate | |
9 | { | |
10 | delete Foo; | |
11 | return; | |
12 | } | |
13 | ||
14 | Blocks from functions. | |
15 | ||
16 | I think G++ has become good enough that doing this won't have much | |
17 | code size implications. | |
18 | ||
19 | ##################################################################### */ | |
20 | /*}}}*/ | |
21 | #ifndef SMART_POINTER_H | |
22 | #define SMART_POINTER_H | |
5dd00edb | 23 | #include <apt-pkg/macros.h> |
b2e465d6 AL |
24 | |
25 | template <class T> | |
5dd00edb | 26 | class APT_DEPRECATED_MSG("use std::unique_ptr instead") SPtr |
b2e465d6 AL |
27 | { |
28 | public: | |
29 | T *Ptr; | |
30 | ||
31 | inline T *operator ->() {return Ptr;}; | |
32 | inline T &operator *() {return *Ptr;}; | |
33 | inline operator T *() {return Ptr;}; | |
34 | inline operator void *() {return Ptr;}; | |
35 | inline T *UnGuard() {T *Tmp = Ptr; Ptr = 0; return Tmp;}; | |
36 | inline void operator =(T *N) {Ptr = N;}; | |
37 | inline bool operator ==(T *lhs) const {return Ptr == lhs;}; | |
38 | inline bool operator !=(T *lhs) const {return Ptr != lhs;}; | |
39 | inline T*Get() {return Ptr;}; | |
40 | ||
41 | inline SPtr(T *Ptr) : Ptr(Ptr) {}; | |
42 | inline SPtr() : Ptr(0) {}; | |
43 | inline ~SPtr() {delete Ptr;}; | |
44 | }; | |
45 | ||
46 | template <class T> | |
5dd00edb | 47 | class APT_DEPRECATED_MSG("use std::unique_ptr instead") SPtrArray |
b2e465d6 AL |
48 | { |
49 | public: | |
50 | T *Ptr; | |
51 | ||
500827ed | 52 | //inline T &operator *() {return *Ptr;}; |
b2e465d6 AL |
53 | inline operator T *() {return Ptr;}; |
54 | inline operator void *() {return Ptr;}; | |
55 | inline T *UnGuard() {T *Tmp = Ptr; Ptr = 0; return Tmp;}; | |
500827ed | 56 | //inline T &operator [](signed long I) {return Ptr[I];}; |
b2e465d6 AL |
57 | inline void operator =(T *N) {Ptr = N;}; |
58 | inline bool operator ==(T *lhs) const {return Ptr == lhs;}; | |
59 | inline bool operator !=(T *lhs) const {return Ptr != lhs;}; | |
500827ed | 60 | inline T *Get() {return Ptr;}; |
b2e465d6 AL |
61 | |
62 | inline SPtrArray(T *Ptr) : Ptr(Ptr) {}; | |
63 | inline SPtrArray() : Ptr(0) {}; | |
c3392a9f DK |
64 | #if __GNUC__ >= 4 |
65 | #pragma GCC diagnostic push | |
66 | #pragma GCC diagnostic ignored "-Wunsafe-loop-optimizations" | |
67 | // gcc warns about this, but we can do nothing hereā¦ | |
68 | #endif | |
500827ed | 69 | inline ~SPtrArray() {delete [] Ptr;}; |
c3392a9f DK |
70 | #if __GNUC__ >= 4 |
71 | #pragma GCC diagnostic pop | |
72 | #endif | |
b2e465d6 AL |
73 | }; |
74 | ||
75 | #endif |