/usr/include/deal.II/base/subscriptor.h is in libdeal.ii-dev 6.3.1-1.1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 | //---------------------------------------------------------------------------
// $Id: subscriptor.h 20755 2010-03-09 00:32:44Z bangerth $
// Version: $Name$
//
// Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2010 by the deal.II authors
//
// This file is subject to QPL and may not be distributed
// without copyright and license information. Please refer
// to the file deal.II/doc/license.html for the text and
// further information on this license.
//
//---------------------------------------------------------------------------
#ifndef __deal2__subscriptor_h
#define __deal2__subscriptor_h
#include <base/config.h>
#include <base/exceptions.h>
#include <typeinfo>
#include <map>
#include <string>
DEAL_II_NAMESPACE_OPEN
/**
* Handling of subscriptions.
*
* This class, as a base class, allows to keep track of other objects
* using a specific object. It is used, when an object, given to a
* constructor by reference, is stored. Then, the original object may
* not be deleted before the dependent object is deleted. You can assert
* this constraint by letting the object passed be derived from this class
* and let the user subscribe() to this object. The destructor the used
* object inherits from the Subscriptor class then will lead to an error
* when destruction is attempted while there are still subscriptions.
*
* The utility of this class is even enhanced by providing identifying
* strings to the functions subscribe() and unsubscribe(). In case of
* a hanging subscription during destruction, this string will be
* listed in the exception's message. For reasons of efficiency, these
* strings are handled as <tt>const char*</tt>. Therefore, the
* pointers provided to subscribe() and to unsubscribe() must be the
* same. Strings with equal contents will not be recognized to be the
* same. The handling in SmartPointer will take care of this.
*
* @note Due to a problem with <tt>volatile</tt> declarations, this
* additional feature is switched of if multithreading is used.
*
* @ingroup memory
* @author Guido Kanschat, 1998 - 2005
*/
class Subscriptor
{
public:
/**
* Constructor setting the counter to zero.
*/
Subscriptor();
/**
* Copy-constructor.
*
* The counter of the copy is zero,
* since references point to the
* original object.
*/
Subscriptor(const Subscriptor&);
/**
* Destructor, asserting that the counter
* is zero.
*/
virtual ~Subscriptor();
/**
* Assignment operator.
*
* This has to be handled with
* care, too, because the counter
* has to remain the same. It therefore
* does nothing more than returning
* <tt>*this</tt>.
*/
Subscriptor& operator = (const Subscriptor&);
/**
* Subscribes a user of the
* object. The subscriber may be
* identified by text supplied as
* <tt>identifier</tt>.
*/
void subscribe (const char* identifier = 0) const;
/**
* Unsubscribes a user from the
* object.
*
* @note The <tt>identifier</tt>
* must be the <b>same
* pointer</b> as the one
* supplied to subscribe(), not
* just the same text.
*/
void unsubscribe (const char* identifier = 0) const;
/**
* Return the present number of
* subscriptions to this object.
* This allows to use this class
* for reference counted lifetime
* determination where the last one
* to unsubscribe also deletes the
* object.
*/
unsigned int n_subscriptions () const;
/**
* List the subscribers to #deallog.
*/
void list_subscribers () const;
/** @addtogroup Exceptions
* @{ */
/**
* Exception:
* Object may not be deleted, since
* it is used.
*/
DeclException3(ExcInUse,
int, char*, std::string &,
<< "Object of class " << arg2
<< " is still used by " << arg1 << " other objects."
<< arg3);
/**
* A subscriber with the
* identification string given to
* Subscriptor::unsubscribe() did
* not subscribe to the object.
*/
DeclException2(ExcNoSubscriber, char*, char*,
<< "No subscriber with identifier \"" << arg2
<< "\" did subscribe to this object of class " << arg1);
/**
* Exception: object should be
* used when
* Subscriptor::unsubscribe() is
* called.
*/
DeclException0(ExcNotUsed);
//@}
private:
/**
* Register a subscriber for
* debugging purposes. Called by
* subscribe() in debug mode.
*/
void do_subscribe(const char* id) const;
/**
* Deregister a subscriber for
* debugging purposes. Called by
* unsubscribe() in debug mode.
*/
void do_unsubscribe(const char* id) const;
/**
* The data type used in
* #counter_map.
*/
typedef std::map<const char*, unsigned int>::value_type
map_value_type;
/**
* The iterator type used in
* #counter_map.
*/
typedef std::map<const char*, unsigned int>::iterator
map_iterator;
/**
* 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).
*
* The creator (and owner) of an
* object is counted in the map
* below if HE manages to supply
* identification.
*
* We use the <tt>mutable</tt> keyword
* in order to allow subscription
* to constant objects also.
*
* In multithreaded mode, this
* counter may be modified by
* different threads. We thus
* have to mark it
* <tt>volatile</tt>. However, this is
* counter-productive in non-MT
* mode since it may pessimize
* code. So use the macro
* defined above to selectively
* add volatility.
*/
mutable DEAL_VOLATILE unsigned int counter;
/**
* In this map, we count
* subscriptions for each
* different identification strig
* supplied to subscribe().
*/
mutable std::map<const char*, unsigned int> counter_map;
/**
* 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 const std::type_info * object_info;
};
//---------------------------------------------------------------------------
// If we are in optimized mode, the subscription checking is turned
// off. Therefore, we provide inline definitions of subscribe and
// unsubscribe here. The definitions for debug mode are in
// subscriptor.cc.
#ifdef DEBUG
inline void
Subscriptor::subscribe(const char* id) const
{
do_subscribe(id);
}
inline void
Subscriptor::unsubscribe(const char* id) const
{
do_unsubscribe(id);
}
#else
inline void
Subscriptor::subscribe(const char*) const
{}
inline void
Subscriptor::unsubscribe(const char*) const
{}
#endif
DEAL_II_NAMESPACE_CLOSE
#endif
|