Browse Source

Added convenience operator=(int) in ctkServiceReference/Registration

This allows to conveniently release resources and to "reset" a
stack variable.
Sascha Zelzer 14 years ago
parent
commit
fda5960ddf

+ 11 - 0
Libs/PluginFramework/ctkServiceReference.cpp

@@ -52,6 +52,17 @@ ctkServiceReference::operator bool() const
   return getPlugin();
   return getPlugin();
 }
 }
 
 
+ctkServiceReference& ctkServiceReference::operator=(int null)
+{
+  if (null == 0)
+  {
+    if (d_func() && !d_func()->ref.deref())
+      delete d_ptr;
+    d_ptr = new ctkServiceReferencePrivate(0);
+  }
+  return *this;
+}
+
 ctkServiceReference::~ctkServiceReference()
 ctkServiceReference::~ctkServiceReference()
 {
 {
   if (!d_func()->ref.deref())
   if (!d_func()->ref.deref())

+ 6 - 0
Libs/PluginFramework/ctkServiceReference.h

@@ -86,6 +86,12 @@ public:
    */
    */
   operator bool() const;
   operator bool() const;
 
 
+  /**
+   * Releases any resources held or locked by this
+   * <code>ctkServiceReference</code> and renders it invalid.
+   */
+  ctkServiceReference& operator=(int null);
+
   ~ctkServiceReference();
   ~ctkServiceReference();
 
 
   /**
   /**

+ 10 - 0
Libs/PluginFramework/ctkServiceRegistration.cpp

@@ -63,6 +63,16 @@ ctkServiceRegistration::operator bool() const
   return d_func();
   return d_func();
 }
 }
 
 
+ctkServiceRegistration& ctkServiceRegistration::operator=(int null)
+{
+  if (null == 0)
+  {
+    if (d_func() && !d_func()->ref.deref())
+      delete d_ptr;
+  }
+  return *this;
+}
+
 ctkServiceRegistration::~ctkServiceRegistration()
 ctkServiceRegistration::~ctkServiceRegistration()
 {
 {
   if (d_func() && !d_func()->ref.deref())
   if (d_func() && !d_func()->ref.deref())

+ 6 - 0
Libs/PluginFramework/ctkServiceRegistration.h

@@ -62,6 +62,12 @@ public:
 
 
   operator bool() const;
   operator bool() const;
 
 
+  /**
+   * Releases any resources held or locked by this
+   * <code>ctkServiceRegistration</code> and renders it invalid.
+   */
+  ctkServiceRegistration& operator=(int null);
+
   ~ctkServiceRegistration();
   ~ctkServiceRegistration();
 
 
   /**
   /**