]> https://gitweb.dealii.org/ - dealii.git/commitdiff
Add a function that resets the pointer and deletes the object pointed to
authorGuido Kanschat <dr.guido.kanschat@gmail.com>
Thu, 11 Nov 2010 21:07:28 +0000 (21:07 +0000)
committerGuido Kanschat <dr.guido.kanschat@gmail.com>
Thu, 11 Nov 2010 21:07:28 +0000 (21:07 +0000)
git-svn-id: https://svn.dealii.org/trunk@22695 0785d39b-7218-0410-832d-ea1e28bc413d

deal.II/include/deal.II/base/smartpointer.h

index 4f3bd1b8737fa96bbaabb6de4f2ac2adf6bcec79..36621b14ec7f94bf2887fc1d9a0e193ae70ddc29 100644 (file)
@@ -1,8 +1,7 @@
 //---------------------------------------------------------------------------
 //    $Id$
-//    Version: $Name$
 //
-//    Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2009 by the deal.II authors
+//    Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2009, 2010 by the deal.II authors
 //
 //    This file is subject to QPL and may not be  distributed
 //    without copyright and license information. Please refer
@@ -157,6 +156,12 @@ class SmartPointer
                                      */
     SmartPointer<T,P> & operator= (const SmartPointer<T,P> &tt);
 
+                                    /**
+                                     * Delete the object pointed to
+                                     * and set the pointer to zero.
+                                     */
+    void clear ();
+    
                                     /**
                                      * Conversion to normal pointer.
                                      */
@@ -315,6 +320,21 @@ SmartPointer<T,P>::~SmartPointer ()
 
 
 
+template <typename T, typename P>
+inline
+void
+SmartPointer<T,P>::clear ()
+{
+  if (t != 0)
+    {
+      t->unsubscribe(id);
+      delete t;
+      t = 0;
+    }
+}
+
+
+
 template <typename T, typename P>
 inline
 SmartPointer<T,P> & SmartPointer<T,P>::operator = (T *tt)

In the beginning the Universe was created. This has made a lot of people very angry and has been widely regarded as a bad move.

Douglas Adams


Typeset in Trocchi and Trocchi Bold Sans Serif.