]> https://gitweb.dealii.org/ - dealii.git/commitdiff
Change the internal way the subscriptors and SmartPointers/References work.
authorWolfgang Bangerth <bangerth@math.tamu.edu>
Thu, 3 Sep 1998 12:30:16 +0000 (12:30 +0000)
committerWolfgang Bangerth <bangerth@math.tamu.edu>
Thu, 3 Sep 1998 12:30:16 +0000 (12:30 +0000)
git-svn-id: https://svn.dealii.org/trunk@549 0785d39b-7218-0410-832d-ea1e28bc413d

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

index a9d1afb8feba3c36955d1395efc347b5de7173b5..588bb2728b04a5c22b25e8cc1d1e4d9ff2697c92 100644 (file)
@@ -4,6 +4,12 @@
 #define __subscriptor_H
 /*----------------------------   subscriptor.h     ---------------------------*/
 
+
+
+#include <base/exceptions.h>
+
+
+
 /**
  * Handling of subscriptions.
  *
  */
 class Subscriptor
 {
-  unsigned counter;
-public:
-                                  /// Object may not be deleted, since it is used.
-  DeclException0(InUse);//, unsigned, "Object is used " << counter << " times");
-  DeclException0(NotUsed);
+                                    /**
+                                     * Store the number of objects which
+                                     * subscribed to this object. Initialally,
+                                     * this number is zero, and upon
+                                     * destruction it shall be zero again
+                                     * (i.e. all objects which subscribed
+                                     * should have unsubscribed again).
+                                     */
+    mutable unsigned int counter;
+  public:
+                                    /**
+                                     * Object may not be deleted, since
+                                     * it is used.
+                                     */
+    DeclException0(InUse);//, unsigned, "Object is used " << counter << " times");
+    DeclException0(NotUsed);
   
-                                  /// Constructor setting the counter to zero.
-  Subscriptor()
-                 : counter(0)
+                                    /**
+                                     * Constructor setting the counter to zero.
+                                     */
+    Subscriptor()
+                   : counter(0)
       {}
-                                  /// Destructor, asserting that the counter is zero.
-  ~Subscriptor()
+                                    /**
+                                     * Destructor, asserting that the counter
+                                     * is zero.
+                                     */
+    
+    ~Subscriptor()
       {
        Assert(counter==0, InUse());
       }
-                                  /**
-                                   * Copy-constructor.
-                                   *
-                                   * The counter of the copy is zero,
-                                   * since references point to the
-                                   * original object. */
-
-  Subscriptor(const Subscriptor&)
-                 : counter(0)
+
+                                    /**
+                                     * Copy-constructor.
+                                     *
+                                     * The counter of the copy is zero,
+                                     * since references point to the
+                                     * original object.
+                                     */
+    Subscriptor(const Subscriptor&)
+                   : counter(0)
       {}
 
-                                  /**
-                                   * Assignment operator.
-                                   *
-                                   * This has to be handled with
-                                   * care, too, because the counter
-                                   * has to remain the same. */
-  Subscriptor& operator=(const Subscriptor&)
+                                    /**
+                                     * Assignment operator.
+                                     *
+                                     * This has to be handled with
+                                     * care, too, because the counter
+                                     * has to remain the same.
+                                     */
+    Subscriptor& operator = (const Subscriptor&) 
       {
        return *this;
       }
-
-                                  /// Subscribes a user of the object.
-  void subscribe() //mutable
+    
+                                    /**
+                                     * Subscribes a user of the object.
+                                     */
+    void subscribe () const
       {
        ++counter;
       }
   
-                                  /// Unsubscribes a user from the object.
-  void unsubscribe() //mutable
+                                    /**
+                                     * Unsubscribes a user from the object.
+                                     */
+    void unsubscribe () const
       {
        Assert(counter>0, NotUsed());
        --counter;
       }
 };
 
+
+
+
+
 /**
  * Smart references avoid destruction of a referenced object.
  */
 template<class T>
 class SmartReference
 {
-  T& t;
-public:
-                                  /// Constructor taking a normal reference.
-  SmartReference(const T& tt)
-                 : t(/*const_cast<T&>*/ tt) 
+    T& t;
+
+  public:
+                                    /**
+                                     * Constructor taking a normal reference.
+                                     */
+    SmartReference(const T& tt)
+                   : t(tt) 
       {
        t.subscribe();
       }
-                                  /// Destructor, removing the subscription.
-      ~SmartReference()
+    
+                                    /**
+                                     * Destructor, removing the subscription.
+                                     */
+    ~SmartReference()
       {
        t.unsubscribe();
       }
   
-                                  /// Conversion to normal reference
-      operator T& ()
-      {
-       return t;
-      }
-                                  /// Conversion to normal const reference.
-      operator const T& () const
+                                    /**
+                                     * Conversion to normal reference
+                                     */
+    operator T& ()
       {
        return t;
       }
 };
 
+
+
+
 /**
  * Smart pointers avoid destruction of an object in use.
  */
 template<class T>
 class SmartPointer
 {
-  T* t;
-public:
-                                  /// Constructor taking a normal pointer.
-  SmartPointer(const T* tt)
-                 : t(/*const_cast<T&>*/ tt) 
+    T* t;
+
+  public:
+                                    /**
+                                     * Constructor taking a normal pointer.
+                                     */
+    SmartPointer(T* tt)
+                   : t(tt) 
       {
        t->subscribe();
       }
-                                  /// Destructor, removing the subscription.
-      ~SmartPointer()
+
+                                    /**
+                                     * Destructor, removing the subscription.
+                                     */
+    ~SmartPointer()
       {
        t->unsubscribe();
       }
-  
-                                  /// Conversion to normal pointer.
-      operator T* ()
-      {
-       return t;
-      }
-                                  /// Conversion to normal const pointer.
-      operator const T* () const
+    
+                                    /**
+                                     * Conversion to normal pointer.
+                                     */
+    operator T* () const
       {
        return t;
       }
-      T& operator* ()
-      {
-       return *t;
-      }
-      const T& operator* () const
+
+                                    /**
+                                     * Dereferencing operator.
+                                     */
+    T& operator* () const
       {
        return *t;
       }
-      T* operator -> ()
-      {
-       return t;
-      }
-      const T* operator -> () const
+
+                                    /**
+                                     * Dereferencing operator.
+                                     */
+    T* operator -> () const
       {
        return t;
       }
-
 };
 
 

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.