]> https://gitweb.dealii.org/ - dealii.git/commitdiff
Since no-one else stepped up: remove QUIET_DESTRUCTOR, let Subscriptor hold a pointer...
authorWolfgang Bangerth <bangerth@math.tamu.edu>
Wed, 10 May 2000 14:39:39 +0000 (14:39 +0000)
committerWolfgang Bangerth <bangerth@math.tamu.edu>
Wed, 10 May 2000 14:39:39 +0000 (14:39 +0000)
git-svn-id: https://svn.dealii.org/trunk@2835 0785d39b-7218-0410-832d-ea1e28bc413d

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

index 9728a01d3dfb4ce849b7c49d7b5d9e09bb7484c1..2a799718bcafe704f55f03ece0548f761533b256 100644 (file)
 #define __deal2__subscriptor_h
 
 
-#ifndef __exceptions_H
 #include <base/exceptions.h>
-#endif
-
-#ifndef QUIET_SUBSCRIPTOR
 #include <typeinfo>
-#include <string>
-#endif
+
+
 
 /**
  * Handling of subscriptions.
@@ -43,19 +39,6 @@ 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.
                                      *
@@ -64,6 +47,12 @@ class Subscriptor
                                      * original object.
                                      */
     Subscriptor(const Subscriptor&);
+
+                                    /**
+                                     * Destructor, asserting that the counter
+                                     * is zero.
+                                     */
+    virtual ~Subscriptor();
     
                                     /**
                                      * Assignment operator.
@@ -97,25 +86,15 @@ class Subscriptor
                                      */
     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
-                                     * it is used.
-                                     */
-    DeclException1(ExcInUse,
-                  int,
-                  << "This object is still used by " << arg1 << " other objects.");
-#endif
+                  int, char *,
+                  << "Object of class " << arg2
+                  << " is still used by " << arg1 << " other objects.");
 
                                     /**
                                      * Exception: object should be used
@@ -141,17 +120,19 @@ 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
+                                     * Pointer to the typeinfo object
+                                     * of this object, from which we
+                                     * can later deduce the class
+                                     * name. Since this information
+                                     * on 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
+    mutable const type_info * object_info;
 };
 
 
index 46533df9512b457e3633124a75c2663ba3cd73b1..7ea95800f9fd7fb01cd174d86b6839a3eca66cca 100644 (file)
 
 
 #include <base/subscriptor.h>
+#include <typeinfo>
+
 
 
 Subscriptor::Subscriptor () :
-               counter (0)
+               counter (0),
+               object_info (0)
 {};
 
 
 Subscriptor::Subscriptor (const Subscriptor &) :
-               counter (0)
+               counter (0),
+               object_info (0)
 {};
 
 
 Subscriptor::~Subscriptor ()
 {
-#ifndef QUIET_SUBSCRIPTOR
-  Assert (counter == 0, ExcInUse(counter, classname ));
-#else
-  Assert (counter == 0, ExcInUse(counter));
-#endif
+                                  // check whether there are still
+                                  // subscriptions to this object. if
+                                  // so, output the actual name of
+                                  // the class to which this object
+                                  // belongs, i.e. the most derived
+                                  // class. note that the name may be
+                                  // mangled, so it need not be the
+                                  // clear-text class name. however,
+                                  // you can obtain the latter by
+                                  // running the c++filt program over
+                                  // the output.
+  Assert (counter == 0, ExcInUse(counter, object_info->name()));
 }
 
 
-Subscriptor & Subscriptor::operator = (const Subscriptor &)
+
+Subscriptor & Subscriptor::operator = (const Subscriptor &s)
 {
+  object_info = s.object_info;
   return *this;
 };
 
 
+
 void Subscriptor::subscribe () const
 {
 #ifdef DEBUG
-#ifndef QUIET_SUBSCRIPTOR
-  if(classname.size() == 0)
-    classname = string(typeid(*this).name());
-#endif
+  if (object_info == 0)
+    object_info = &typeid(*this);
 #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.