summaryrefslogtreecommitdiff
path: root/Plugins/utils/scope.h
diff options
context:
space:
mode:
authorpescuma <pescuma@c086bb3d-8645-0410-b8da-73a8550f86e7>2009-01-24 00:29:50 +0000
committerpescuma <pescuma@c086bb3d-8645-0410-b8da-73a8550f86e7>2009-01-24 00:29:50 +0000
commitbe94a568ef65120465b49f5c6db90cd4ec3c3eb2 (patch)
treefe7fc014fe1053e821860c53f78e4cabb95b9ac7 /Plugins/utils/scope.h
parent52e0dac49837ca1123412fccd95fdb95873c8321 (diff)
utils: sync with BerliOS
git-svn-id: http://pescuma.googlecode.com/svn/trunk/Miranda@132 c086bb3d-8645-0410-b8da-73a8550f86e7
Diffstat (limited to 'Plugins/utils/scope.h')
-rw-r--r--Plugins/utils/scope.h37
1 files changed, 37 insertions, 0 deletions
diff --git a/Plugins/utils/scope.h b/Plugins/utils/scope.h
new file mode 100644
index 0000000..2fad797
--- /dev/null
+++ b/Plugins/utils/scope.h
@@ -0,0 +1,37 @@
+#ifndef __PTR_H__
+# define __PTR_H__
+
+
+template<class T>
+class scope
+{
+public:
+ scope() : p(NULL) {}
+ scope(T t) : p(t) {}
+ ~scope() { release(); }
+
+ void release()
+ {
+ if (p != NULL)
+ delete p;
+ p = NULL;
+ }
+
+ T operator=(T t) { release(); p = t; return t; }
+ T operator->() const { return p; }
+ operator T() const { return p; }
+
+ T detach()
+ {
+ T ret = p;
+ p = NULL;
+ return ret;
+ }
+
+private:
+ T p;
+};
+
+
+
+#endif // __PTR_H__