diff options
author | pescuma <pescuma@c086bb3d-8645-0410-b8da-73a8550f86e7> | 2008-11-17 00:15:02 +0000 |
---|---|---|
committer | pescuma <pescuma@c086bb3d-8645-0410-b8da-73a8550f86e7> | 2008-11-17 00:15:02 +0000 |
commit | 974495437f862c1f26fc70760bb72c2db6fcdd41 (patch) | |
tree | 324f8edcc09b21d40f65a840bf0819c71762b419 /Plugins/utils/mir_scope.h | |
parent | 6b5a5851340510255cde717b74697fa693679732 (diff) |
utils: Added scope<> and made Buffer more user friendly
git-svn-id: http://pescuma.googlecode.com/svn/trunk/Miranda@115 c086bb3d-8645-0410-b8da-73a8550f86e7
Diffstat (limited to 'Plugins/utils/mir_scope.h')
-rw-r--r-- | Plugins/utils/mir_scope.h | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/Plugins/utils/mir_scope.h b/Plugins/utils/mir_scope.h new file mode 100644 index 0000000..a18bf55 --- /dev/null +++ b/Plugins/utils/mir_scope.h @@ -0,0 +1,35 @@ +#ifndef __PTR_H__
+# define __PTR_H__
+
+
+template<class T>
+class scope
+{
+public:
+ scope(T t) : p(t) {}
+ ~scope() { free(); }
+
+ void free()
+ {
+ if (p != NULL)
+ mir_free(p);
+ p = NULL;
+ }
+
+// 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__
|