瀏覽代碼

ctkEvent class now uses QSharedData.

Sascha Zelzer 14 年之前
父節點
當前提交
64ce38d7fc
共有 2 個文件被更改,包括 30 次插入13 次删除
  1. 16 7
      Libs/PluginFramework/service/event/ctkEvent.cpp
  2. 14 6
      Libs/PluginFramework/service/event/ctkEvent.h

+ 16 - 7
Libs/PluginFramework/service/event/ctkEvent.cpp

@@ -25,12 +25,13 @@
 
 #include <stdexcept>
 
-class ctkEventPrivate {
+class ctkEventData : public QSharedData
+{
 
 public:
 
-  ctkEventPrivate(const QString& topic, const ctkDictionary& properties)
-    : ref(1), topic(topic), properties(properties)
+  ctkEventData(const QString& topic, const ctkDictionary& properties)
+    : topic(topic), properties(properties)
   {
     validateTopicName(topic);
     this->properties.insert(ctkEventConstants::EVENT_TOPIC, topic);
@@ -65,15 +66,19 @@ public:
     }
   }
 
-  QAtomicInt ref;
   const QString topic;
   ctkDictionary properties;
 
 };
 
+ctkEvent::ctkEvent()
+  : d(0)
+{
+
+}
 
 ctkEvent::ctkEvent(const QString& topic, const ctkDictionary& properties)
-  : d(new ctkEventPrivate(topic, properties))
+  : d(new ctkEventData(topic, properties))
 {
 
 }
@@ -89,8 +94,12 @@ ctkEvent::ctkEvent(const ctkEvent &event)
 
 ctkEvent::~ctkEvent()
 {
-  if (!d->ref.deref())
-    delete d;
+}
+
+ctkEvent& ctkEvent::operator=(const ctkEvent& other)
+{
+  d = other.d;
+  return *this;
 }
 
 bool ctkEvent::operator==(const ctkEvent& other) const

+ 14 - 6
Libs/PluginFramework/service/event/ctkEvent.h

@@ -31,7 +31,7 @@
 #include <ctkLDAPSearchFilter.h>
 
 
-class ctkEventPrivate;
+class ctkEventData;
 
 /**
  * A CTK event.
@@ -39,11 +39,21 @@ class ctkEventPrivate;
  * <code>ctkEvent</code> objects are delivered to <code>ctkEventHandler</code>
  * or Qt slots which subscribe to the topic of the event.
  */
-class CTK_PLUGINFW_EXPORT ctkEvent {
+class CTK_PLUGINFW_EXPORT ctkEvent
+{
+
+  QSharedDataPointer<ctkEventData> d;
 
 public:
 
   /**
+   * Default constructor for use with the Qt meta object system.
+   */
+  ctkEvent();
+
+  ~ctkEvent();
+
+  /**
    * Constructs an event.
    *
    * @param topic The topic of the event.
@@ -52,7 +62,8 @@ public:
    */
   ctkEvent(const QString& topic, const ctkDictionary& properties = ctkDictionary());
   ctkEvent(const ctkEvent& event);
-  ~ctkEvent();
+
+  ctkEvent& operator=(const ctkEvent& other);
 
   /**
    * Compares this <code>ctkEvent</code> object to another object.
@@ -112,9 +123,6 @@ public:
    */
   bool matches(const ctkLDAPSearchFilter& filter) const;
 
-protected:
-
-  ctkEventPrivate * const d;
 };