#include <base/exceptions.h>
#endif
+#ifndef QUIET_SUBSCRIPTOR
+#include <typeinfo>
+#include <string>
+#endif
/**
* Handling of subscriptions.
*/
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.
*
* 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
DeclException1(ExcInUse,
int,
<< "This object is still used by " << arg1 << " other objects.");
+#endif
+
/**
* Exception: object should be used
* when #unsubscribe# is called.
* 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
};
{};
-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;
};