summaryrefslogtreecommitdiffstats
path: root/kbarcode/referencecounted.h
diff options
context:
space:
mode:
authortpearson <tpearson@283d02a7-25f6-0310-bc7c-ecb5cbfe19da>2010-02-15 18:34:54 +0000
committertpearson <tpearson@283d02a7-25f6-0310-bc7c-ecb5cbfe19da>2010-02-15 18:34:54 +0000
commit8805e6b17b1460f3316ccb28629e8ad78e4b9c2c (patch)
treedc9b702962ecf0060cc473397b9f80268c2456c9 /kbarcode/referencecounted.h
downloadkbarcode-8805e6b17b1460f3316ccb28629e8ad78e4b9c2c.tar.gz
kbarcode-8805e6b17b1460f3316ccb28629e8ad78e4b9c2c.zip
Added abandoned KDE3 version of kbarcode
git-svn-id: svn://anonsvn.kde.org/home/kde/branches/trinity/applications/kbarcode@1090667 283d02a7-25f6-0310-bc7c-ecb5cbfe19da
Diffstat (limited to 'kbarcode/referencecounted.h')
-rw-r--r--kbarcode/referencecounted.h64
1 files changed, 64 insertions, 0 deletions
diff --git a/kbarcode/referencecounted.h b/kbarcode/referencecounted.h
new file mode 100644
index 0000000..684cd21
--- /dev/null
+++ b/kbarcode/referencecounted.h
@@ -0,0 +1,64 @@
+/***************************************************************************
+ referencecounted.h - description
+ -------------------
+ begin : Mo Apr 18 2005
+ copyright : (C) 2005 by Dominik Seichter
+ email : domseichter@web.de
+ ***************************************************************************/
+
+/***************************************************************************
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ ***************************************************************************/
+
+#ifndef REFERENCE_COUNTED_H
+#define REFERENCE_COUNTED_H
+
+/**
+ * A class to make objects reference counted.
+ * Most likely you will want to subclass this class.
+ * @see TCanvasItem for an example.
+ *
+ * Whenever you get a reference to a ReferenceCounted
+ * object, call addRef(). Whenever you do not need
+ * the object anymore, call remRef().
+ *
+ * When the reference count reaches 0, the object
+ * deletes itself.
+ */
+
+
+class ReferenceCounted {
+ public:
+ ReferenceCounted():m_counter(0) {}
+ virtual ~ReferenceCounted() {}
+
+ inline void addRef()
+ {
+ m_counter++;
+ }
+
+
+ inline void remRef()
+ {
+ if(--m_counter == 0) delete this;
+ }
+
+
+ inline unsigned int refCount()
+ {
+ return m_counter;
+ }
+
+ private:
+ unsigned int m_counter;
+
+};
+
+#endif // REFERENCE_COUNTED_H
+
+