]> https://gitweb.dealii.org/ - dealii-svn.git/commitdiff
Subscriptor prints class name
authorguido <guido@0785d39b-7218-0410-832d-ea1e28bc413d>
Wed, 12 Apr 2000 19:21:37 +0000 (19:21 +0000)
committerguido <guido@0785d39b-7218-0410-832d-ea1e28bc413d>
Wed, 12 Apr 2000 19:21:37 +0000 (19:21 +0000)
git-svn-id: https://svn.dealii.org/trunk@2706 0785d39b-7218-0410-832d-ea1e28bc413d

deal.II/base/include/base/subscriptor.h
deal.II/base/source/subscriptor.cc

index a70a225e82fdfc4de434a67010c10fbbb4b1d54e..9728a01d3dfb4ce849b7c49d7b5d9e09bb7484c1 100644 (file)
 #include <base/exceptions.h>
 #endif
 
+#ifndef QUIET_SUBSCRIPTOR
+#include <typeinfo>
+#include <string>
+#endif
 
 /**
  * Handling of subscriptions.
@@ -39,13 +43,19 @@ class Subscriptor
                                      */
     Subscriptor();
 
+#ifndef QUIET_SUBSCRIPTOR
+                                    /**
+                                     * Destructor, asserting that the counter
+                                     * is zero.
+                                     */
+    virtual ~Subscriptor();
+#else
                                     /**
                                      * Destructor, asserting that the counter
                                      * is zero.
                                      */
-    
     ~Subscriptor();
-    
+#endif
                                     /**
                                      * Copy-constructor.
                                      *
@@ -86,7 +96,17 @@ class Subscriptor
                                      * object.
                                      */
     unsigned int n_subscriptions () const;
-    
+
+#ifndef QUIET_SUBSCRIPTOR
+                                    /**
+                                     * Exception:
+                                     * Object may not be deleted, since
+                                     * it is used.
+                                     */
+    DeclException2(ExcInUse,
+                  int, string&,
+                  << "Object of class " << arg2 << " is still used by " << arg1 << " other objects.");
+#else
                                     /**
                                      * Exception:
                                      * Object may not be deleted, since
@@ -95,6 +115,8 @@ class Subscriptor
     DeclException1(ExcInUse,
                   int,
                   << "This object is still used by " << arg1 << " other objects.");
+#endif
+
                                     /**
                                      * Exception: object should be used
                                      * when #unsubscribe# is called.
@@ -119,6 +141,17 @@ class Subscriptor
                                      * objects also.
                                      */
     mutable unsigned int counter;
+#ifndef QUIET_SUBSCRIPTOR
+                                    /**
+                                     * Storage for the class name.
+                                     * Since the name of the derived
+                                     * class is neither available in
+                                     * the destructor, nor in the
+                                     * constructor, we obtain it in
+                                     * between and store it here.
+                                     */
+    mutable string classname;
+#endif
 };
 
 
index 72e6ab803a394d75cc54b67e1b1244a8497bb6c3..46533df9512b457e3633124a75c2663ba3cd73b1 100644 (file)
@@ -25,17 +25,30 @@ Subscriptor::Subscriptor (const Subscriptor &) :
 {};
 
 
-Subscriptor::~Subscriptor () {
+Subscriptor::~Subscriptor ()
+{
+#ifndef QUIET_SUBSCRIPTOR
+  Assert (counter == 0, ExcInUse(counter, classname ));
+#else
   Assert (counter == 0, ExcInUse(counter));
-};
+#endif
+}
 
 
-Subscriptor & Subscriptor::operator = (const Subscriptor &) {
+Subscriptor & Subscriptor::operator = (const Subscriptor &)
+{
   return *this;
 };
 
 
-void Subscriptor::subscribe () const {
+void Subscriptor::subscribe () const
+{
+#ifdef DEBUG
+#ifndef QUIET_SUBSCRIPTOR
+  if(classname.size() == 0)
+    classname = string(typeid(*this).name());
+#endif
+#endif
   ++counter;
 };
 

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.