summaryrefslogtreecommitdiffstats
path: root/apt-pkg/contrib/sptr.h
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-05 18:07:13 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-05 18:07:13 +0000
commit636c7dc17286d93d788c741d15fd756aeda066d5 (patch)
treee7ae158cc54f591041a061b9865bcae51854f15c /apt-pkg/contrib/sptr.h
parentInitial commit. (diff)
downloadapt-636c7dc17286d93d788c741d15fd756aeda066d5.tar.xz
apt-636c7dc17286d93d788c741d15fd756aeda066d5.zip
Adding upstream version 1.8.2.3.upstream/1.8.2.3upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to '')
-rw-r--r--apt-pkg/contrib/sptr.h74
1 files changed, 74 insertions, 0 deletions
diff --git a/apt-pkg/contrib/sptr.h b/apt-pkg/contrib/sptr.h
new file mode 100644
index 0000000..77806d9
--- /dev/null
+++ b/apt-pkg/contrib/sptr.h
@@ -0,0 +1,74 @@
+// -*- mode: cpp; mode: fold -*-
+// Description /*{{{*/
+/* ######################################################################
+
+ Trivial non-ref counted 'smart pointer'
+
+ This is really only good to eliminate
+ {
+ delete Foo;
+ return;
+ }
+
+ Blocks from functions.
+
+ I think G++ has become good enough that doing this won't have much
+ code size implications.
+
+ ##################################################################### */
+ /*}}}*/
+#ifndef SMART_POINTER_H
+#define SMART_POINTER_H
+#include <apt-pkg/macros.h>
+
+template <class T>
+class APT_DEPRECATED_MSG("use std::unique_ptr instead") SPtr
+{
+ public:
+ T *Ptr;
+
+ inline T *operator ->() {return Ptr;};
+ inline T &operator *() {return *Ptr;};
+ inline operator T *() {return Ptr;};
+ inline operator void *() {return Ptr;};
+ inline T *UnGuard() {T *Tmp = Ptr; Ptr = 0; return Tmp;};
+ inline void operator =(T *N) {Ptr = N;};
+ inline bool operator ==(T *lhs) const {return Ptr == lhs;};
+ inline bool operator !=(T *lhs) const {return Ptr != lhs;};
+ inline T*Get() {return Ptr;};
+
+ inline SPtr(T *Ptr) : Ptr(Ptr) {};
+ inline SPtr() : Ptr(0) {};
+ inline ~SPtr() {delete Ptr;};
+};
+
+template <class T>
+class APT_DEPRECATED_MSG("use std::unique_ptr instead") SPtrArray
+{
+ public:
+ T *Ptr;
+
+ //inline T &operator *() {return *Ptr;};
+ inline operator T *() {return Ptr;};
+ inline operator void *() {return Ptr;};
+ inline T *UnGuard() {T *Tmp = Ptr; Ptr = 0; return Tmp;};
+ //inline T &operator [](signed long I) {return Ptr[I];};
+ inline void operator =(T *N) {Ptr = N;};
+ inline bool operator ==(T *lhs) const {return Ptr == lhs;};
+ inline bool operator !=(T *lhs) const {return Ptr != lhs;};
+ inline T *Get() {return Ptr;};
+
+ inline SPtrArray(T *Ptr) : Ptr(Ptr) {};
+ inline SPtrArray() : Ptr(0) {};
+#if __GNUC__ >= 4
+ #pragma GCC diagnostic push
+ #pragma GCC diagnostic ignored "-Wunsafe-loop-optimizations"
+ // gcc warns about this, but we can do nothing hereā€¦
+#endif
+ inline ~SPtrArray() {delete [] Ptr;};
+#if __GNUC__ >= 4
+ #pragma GCC diagnostic pop
+#endif
+};
+
+#endif