瀏覽代碼

ctkLDAPSearchFilter is now implicitly shared plus API changes.

Sascha Zelzer 14 年之前
父節點
當前提交
ebad3004e7
共有 2 個文件被更改,包括 51 次插入27 次删除
  1. 38 19
      Libs/PluginFramework/ctkLDAPSearchFilter.cpp
  2. 13 8
      Libs/PluginFramework/ctkLDAPSearchFilter.h

+ 38 - 19
Libs/PluginFramework/ctkLDAPSearchFilter.cpp

@@ -21,35 +21,50 @@
 
 #include "ctkLDAPSearchFilter.h"
 
-#include "ctkLDAPExpr.h"
+#include "ctkLDAPExpr_p.h"
+#include "ctkServiceReferencePrivate.h"
 
 
-class ctkLDAPSearchFilterPrivate {
+class ctkLDAPSearchFilterData : public QSharedData
+{
 public:
 
-  ctkLDAPSearchFilterPrivate(const QString& filter)
-    : ref(1), ldapExpr(filter)
+  ctkLDAPSearchFilterData()
+  {}
+
+  ctkLDAPSearchFilterData(const QString& filter)
+    : ldapExpr(filter)
+  {}
+
+  ctkLDAPSearchFilterData(const ctkLDAPSearchFilterData& other)
+    : QSharedData(other), ldapExpr(other.ldapExpr)
   {}
 
-  QAtomicInt ref;
   ctkLDAPExpr ldapExpr;
 };
 
+ctkLDAPSearchFilter::ctkLDAPSearchFilter()
+  : d(new ctkLDAPSearchFilterData())
+{
+}
+
 ctkLDAPSearchFilter::ctkLDAPSearchFilter(const QString& filter)
-  : d(new ctkLDAPSearchFilterPrivate(filter))
+  : d(new ctkLDAPSearchFilterData(filter))
 {
 }
 
-ctkLDAPSearchFilter::ctkLDAPSearchFilter(const ctkLDAPSearchFilter& filter)
-  : d(filter.d)
+ctkLDAPSearchFilter::ctkLDAPSearchFilter(const ctkLDAPSearchFilter& other)
+  : d(other.d)
 {
-  d->ref.ref();
 }
 
 ctkLDAPSearchFilter::~ctkLDAPSearchFilter()
 {
-  if (!d->ref.deref())
-    delete d;
+}
+
+bool ctkLDAPSearchFilter::match(const ctkServiceReference& reference) const
+{
+  return d->ldapExpr.evaluate(reference.d_func()->getProperties(), true);
 }
 
 bool ctkLDAPSearchFilter::match(const ctkDictionary& dictionary) const
@@ -62,6 +77,11 @@ bool ctkLDAPSearchFilter::matchCase(const ctkDictionary& dictionary) const
   return d->ldapExpr.evaluate(dictionary, true);
 }
 
+QString ctkLDAPSearchFilter::toString() const
+{
+  return d->ldapExpr.toString();
+}
+
 bool ctkLDAPSearchFilter::operator==(const ctkLDAPSearchFilter& other) const
 {
   return d->ldapExpr.toString() == other.d->ldapExpr.toString();
@@ -69,14 +89,13 @@ bool ctkLDAPSearchFilter::operator==(const ctkLDAPSearchFilter& other) const
 
 ctkLDAPSearchFilter& ctkLDAPSearchFilter::operator=(const ctkLDAPSearchFilter& filter)
 {
-  if (d != filter.d)
-  {
-    if (!d->ref.deref())
-      delete d;
-
-    d = filter.d;
-    d->ref.ref();
-  }
+  d = filter.d;
 
   return *this;
 }
+
+QDebug operator<<(QDebug dbg, const ctkLDAPSearchFilter& filter)
+{
+  dbg << filter.toString();
+  return dbg.maybeSpace();
+}

+ 13 - 8
Libs/PluginFramework/ctkLDAPSearchFilter.h

@@ -24,33 +24,38 @@
 
 #include "CTKPluginFrameworkExport.h"
 
-#include "ctkPluginFramework_global.h"
+#include "ctkServiceReference.h"
 
-#include <QMap>
-#include <QString>
-#include <QVariant>
+#include <QSharedDataPointer>
+#include <QDebug>
 
-class ctkLDAPSearchFilterPrivate;
+class ctkLDAPSearchFilterData;
 
 class CTK_PLUGINFW_EXPORT ctkLDAPSearchFilter {
 
 public:
 
-  ctkLDAPSearchFilter(const QString& filter = "");
-  ctkLDAPSearchFilter(const ctkLDAPSearchFilter& filter);
+  ctkLDAPSearchFilter();
+  ctkLDAPSearchFilter(const QString& filter);
+  ctkLDAPSearchFilter(const ctkLDAPSearchFilter& other);
 
   ~ctkLDAPSearchFilter();
 
+  bool match(const ctkServiceReference& reference) const;
   bool match(const ctkDictionary& dictionary) const;
   bool matchCase(const ctkDictionary& dictionary) const;
 
+  QString toString() const;
+
   bool operator==(const ctkLDAPSearchFilter& other) const;
   ctkLDAPSearchFilter& operator=(const ctkLDAPSearchFilter& filter);
 
 protected:
 
-  ctkLDAPSearchFilterPrivate * d;
+  QSharedDataPointer<ctkLDAPSearchFilterData> d;
 
 };
 
+CTK_PLUGINFW_EXPORT QDebug operator<<(QDebug dbg, const ctkLDAPSearchFilter& filter);
+
 #endif // CTKLDAPSEARCHFILTER_H