Przeglądaj źródła

Make ctkServiceReference default constructible.

Sascha Zelzer 14 lat temu
rodzic
commit
b74913eec6

+ 11 - 0
Libs/PluginFramework/ctkServiceReference.cpp

@@ -28,6 +28,12 @@
 #include <QStringList>
 #include <QMutexLocker>
 
+ctkServiceReference::ctkServiceReference()
+  : d_ptr(new ctkServiceReferencePrivate(0))
+{
+
+}
+
 ctkServiceReference::ctkServiceReference(const ctkServiceReference& ref)
   : d_ptr(ref.d_ptr)
 {
@@ -40,6 +46,11 @@ ctkServiceReference::ctkServiceReference(ctkServiceRegistrationPrivate* reg)
 
 }
 
+ctkServiceReference::operator bool() const
+{
+  return getPlugin();
+}
+
 ctkServiceReference::~ctkServiceReference()
 {
   if (!d_func()->ref.deref())

+ 15 - 0
Libs/PluginFramework/ctkServiceReference.h

@@ -68,8 +68,23 @@ class CTK_PLUGINFW_EXPORT ctkServiceReference {
 
 public:
 
+  /**
+   * Creates an invalid ctkServiceReference object. You can use
+   * this object in boolean expressions and it will evaluate to
+   * <code>false</code>.
+   */
+  ctkServiceReference();
+
   ctkServiceReference(const ctkServiceReference& ref);
 
+  /**
+   * Converts this ctkServiceReference instance into a boolean
+   * expression. If this instance was default constructed or
+   * the service it references has been unregistered, the conversion
+   * returns <code>false</code>, otherwise it returns <code>true</code>.
+   */
+  operator bool() const;
+
   ~ctkServiceReference();
 
   /**