Reference documentation for deal.II version 8.4.1
Public Member Functions | Private Types | Private Attributes | List of all members
Subscriptor Class Reference

#include <deal.II/base/subscriptor.h>

Inherited by Algorithms::OperatorBase, Algorithms::OutputOperator< VectorType >, Algorithms::TimestepControl, AnyData, ArpackSolver, BlockDiagonalMatrix< MatrixType >, BlockIndices, BlockInfo, BlockMatrixArray< number, BlockVectorType >, BlockMatrixBase< MatrixType >, BlockMatrixBase< PETScWrappers::SparseMatrix >, BlockMatrixBase< SparseMatrix >, BlockMatrixBase< SparseMatrix< number > >, BlockSparseMatrixEZ< Number >, BlockSparsityPatternBase< SparsityPatternType >, BlockSparsityPatternBase< DynamicSparsityPattern >, BlockSparsityPatternBase< SparsityPattern >, BlockVectorBase< VectorType >, BlockVectorBase< Vector >, BlockVectorBase< Vector< Number > >, ChunkSparseMatrix< number > [virtual], ChunkSparsityPattern, ConstraintMatrix, DataPostprocessor< dim >, DataPostprocessor< DoFHandlerType::space_dimension >, DoFHandler< dim, spacedim >, hp::DoFHandler< dim >, DoFHandler< dim >, DynamicSparsityPattern, hp::FECollection< dim, FEValuesType::space_dimension >, hp::FECollection< dim,::FEFaceValues< dim, spacedim >::space_dimension >, hp::FECollection< dim,::FESubfaceValues< dim, spacedim >::space_dimension >, hp::FECollection< dim,::FEValues< dim, spacedim >::space_dimension >, FETools::FEFactoryBase< FE::dimension, FE::space_dimension >, FETools::FEFactoryBase< dim, spacedim >, FEValuesBase< dim, spacedim >, FilteredMatrix< VectorType >, FiniteElement< dim, spacedim >, FiniteElement< 1, spacedim >, FiniteElement< dim, dim >, Function< dim, Number >, Function< 2 >, Function< chartdim >, Function< dim >, Function< spacedim >, hp::DoFHandler< dim, spacedim >, hp::FECollection< dim, spacedim >, hp::MappingCollection< dim, spacedim >, hp::QCollection< dim >, InterGridMap< MeshType >, InverseMatrixRichardson< VectorType >, IterativeInverse< VectorType >, LogStream, Manifold< dim, spacedim >, Mapping< dim, spacedim >, Mapping< dim >, hp::MappingCollection< dim, FEValuesType::space_dimension >, hp::MappingCollection< dim,::FEFaceValues< dim, spacedim >::space_dimension >, hp::MappingCollection< dim,::FESubfaceValues< dim, spacedim >::space_dimension >, hp::MappingCollection< dim,::FEValues< dim, spacedim >::space_dimension >, MatrixBlock< MatrixType >, MatrixBlock< FullMatrix< number > >, MeanValueFilter, MeshWorker::LocalIntegrator< dim, spacedim, number >, MeshWorker::VectorSelector, mg::SparseMatrixCollection< number >, MGCoarseGridBase< VectorType >, MGConstrainedDoFs, MGLevelObject< Object >, MGLevelObject< MatrixType >, MGLevelObject< parallel::distributed::Vector< Number > >, MGLevelObject< PointerMatrix< MatrixType, BlockVector< number > > >, MGLevelObject< PointerMatrix< MatrixType, VectorType > >, MGLevelObject< PointerMatrix< RelaxationType, BlockVector< number > > >, MGLevelObject< PreconditionerType >, MGLevelObject< RelaxationType >, MGLevelObject< SparseMatrix< number > >, MGLevelObject< SparsityPattern >, MGLevelObject< std_cxx11::shared_ptr< PointerMatrixBase< VectorType > > >, MGLevelObject< VectorType >, MGMatrixBase< VectorType >, MGMatrixBase< Vector< number > >, MGMatrixBlockVector< MatrixType >, MGSmootherBase< VectorType >, MGSmootherBase< BlockVector< number > >, MGTransferBase< VectorType >, MGTransferBase< BlockVector< number > >, MGTransferBase< parallel::distributed::Vector< Number > >, MGTransferBase< Vector< number > >, Multigrid< VectorType >, parallel::distributed::Vector< Number >, ParameterHandler, PETScWrappers::MatrixBase, PETScWrappers::VectorBase, Polynomials::PiecewisePolynomial< double >, PointerMatrixBase< VectorType >, PointerMatrixBase< typename BlockVectorType::BlockType >, PointerMatrixBase< Vector< number > >, PointerMatrixBase< Vector< vector_number > >, Polynomials::Polynomial< double >, Polynomials::PiecewisePolynomial< number >, Polynomials::Polynomial< number >, PreconditionBlock< MatrixType, inverse_type > [virtual], PreconditionBlockJacobi< MatrixType, inverse_type > [virtual], PreconditionBlockSOR< MatrixType, inverse_type > [virtual], PreconditionBlockSSOR< MatrixType, inverse_type > [virtual], PreconditionChebyshev< MatrixType, VectorType >, PreconditionIdentity, PreconditionLU< number >, PreconditionMG< dim, VectorType, TRANSFER >, PreconditionRelaxation< MatrixType >, PreconditionRichardson, PreconditionSelector< MatrixType, VectorType >, PreconditionUseMatrix< MatrixType, VectorType >, hp::QCollection< dim-1 >, hp::QCollection< q_dim >, Quadrature< dim >, Quadrature< 1 >, Quadrature< dim-1 >, RelaxationBlock< MatrixType, inverse_type >::AdditionalData, RelaxationBlockJacobi< MatrixType, inverse_type > [virtual], RelaxationBlockSOR< MatrixType, inverse_type > [virtual], RelaxationBlockSSOR< MatrixType, inverse_type > [virtual], ScaledMatrix< VectorType >, SchurMatrix< MA_inverse, MB, MDt, MC >, Solver< VectorType >, SolverControl, SolverSelector< VectorType >, SparseDirectUMFPACK, SparseLUDecomposition< number > [virtual], SparseMatrix< number > [virtual], SparseMatrixEZ< number >, SparsityPattern, TableBase< N, T >, TableBase< 1, T >, TableBase< 2, number >, TableBase< 2, T >, TableBase< 3, T >, TableBase< 4, T >, TableBase< 5, T >, TableBase< 6, T >, TableBase< 7, T >, TensorFunction< rank, dim, Number >, TensorFunction< 1, dim, Number >, TimeStepBase, Triangulation< dim, spacedim >, Triangulation< dim, dim >, Triangulation< DoFHandler< dim >::dimension, DoFHandler< dim >::space_dimension >, Triangulation< DoFHandlerType::dimension, DoFHandlerType::space_dimension >, TrilinosWrappers::PreconditionBase, TrilinosWrappers::SparseMatrix, TrilinosWrappers::SparsityPattern, TrilinosWrappers::VectorBase, Vector< Number >, parallel::distributed::Vector< double >, Vector< double >, Vector< number >, Vector< typename VectorType::value_type >, VectorMemory< VectorType >, VectorMemory< BlockVector< double > >, VectorMemory< BlockVector< number > >, VectorMemory< Vector >, and VectorMemory< Vector< number > >.

Public Member Functions

 Subscriptor ()
 Subscriptor (const Subscriptor &)
virtual ~Subscriptor ()
Subscriptoroperator= (const Subscriptor &)
void subscribe (const char *identifier=0) const
void unsubscribe (const char *identifier=0) const
unsigned int n_subscriptions () const
void list_subscribers () const
 DeclException3 (ExcInUse, int, char *, std::string &,<< "Object of class "<< arg2<< " is still used by "<< arg1<< " other objects."<< "\n\n"<< "(Additional information: "<< arg3<< ")\n\n"<< "See the entry in the Frequently Asked Questions of "<< "deal.II (linked to from for "<< "a lot more information on what this error means and "<< "how to fix programs in which it happens.")
 DeclException2 (ExcNoSubscriber, char *, char *,<< "No subscriber with identifier <"<< arg2<< "> subscribes to this object of class "<< arg1<< ". Consequently, it cannot be unsubscribed.")
template<class Archive >
void serialize (Archive &ar, const unsigned int version)

Private Types

typedef std::map< const char *, unsigned int >::value_type map_value_type
typedef std::map< const char *, unsigned int >::iterator map_iterator

Private Attributes

DEAL_VOLATILE unsigned int counter
std::map< const char *, unsigned int > counter_map
const std::type_info * object_info

Detailed Description

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 const char*. 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.

Due to a problem with volatile declarations, this additional feature is switched off if multithreading is used.
Guido Kanschat, 1998 - 2005

Definition at line 56 of file subscriptor.h.

Member Typedef Documentation

typedef std::map<const char *, unsigned int>::value_type Subscriptor::map_value_type

The data type used in counter_map.

Definition at line 160 of file subscriptor.h.

typedef std::map<const char *, unsigned int>::iterator Subscriptor::map_iterator

The iterator type used in counter_map.

Definition at line 166 of file subscriptor.h.

Constructor & Destructor Documentation

Subscriptor::Subscriptor ( )

Constructor setting the counter to zero.

Definition at line 47 of file

Subscriptor::Subscriptor ( const Subscriptor )


The counter of the copy is zero, since references point to the original object.

Definition at line 58 of file

Subscriptor::~Subscriptor ( )

Destructor, asserting that the counter is zero.

Definition at line 65 of file

Member Function Documentation

Subscriptor & Subscriptor::operator= ( const Subscriptor s)

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 *this.

Definition at line 144 of file

void Subscriptor::subscribe ( const char *  identifier = 0) const

Subscribes a user of the object. The subscriber may be identified by text supplied as identifier.

Definition at line 153 of file

void Subscriptor::unsubscribe ( const char *  identifier = 0) const

Unsubscribes a user from the object.

The identifier must be the same pointer as the one supplied to subscribe(), not just the same text.

Definition at line 180 of file

unsigned int Subscriptor::n_subscriptions ( ) 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.

Definition at line 207 of file

void Subscriptor::list_subscribers ( ) const

List the subscribers to deallog.

Definition at line 214 of file

template<class Archive >
void Subscriptor::serialize ( Archive &  ar,
const unsigned int  version 

Read or write the data of this object to or from a stream for the purpose of serialization.

This function does not actually serialize any of the member variables of this class. The reason is that what this class stores is only who subscribes to this object, but who does so at the time of storing the contents of this object does not necessarily have anything to do with who subscribes to the object when it is restored. Consequently, we do not want to overwrite the subscribers at the time of restoring, and then there is no reason to write the subscribers out in the first place.

Definition at line 206 of file subscriptor.h.

Member Data Documentation

DEAL_VOLATILE unsigned int Subscriptor::counter

Store the number of objects which subscribed to this object. Initially, 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 mutable 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 volatile. However, this is counter- productive in non-MT mode since it may pessimize code. So use the macro defined in deal.II/base/config.h to selectively add volatility.

Definition at line 184 of file subscriptor.h.

std::map<const char *, unsigned int> Subscriptor::counter_map

In this map, we count subscriptions for each different identification string supplied to subscribe().

Definition at line 190 of file subscriptor.h.

const std::type_info* Subscriptor::object_info

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.

Definition at line 198 of file subscriptor.h.

The documentation for this class was generated from the following files: