Reference documentation for deal.II version Git e7c9a24 2019-02-08 08:26:19 +0100
Public Member Functions | Static Public Member Functions | Private Types | Private Member Functions | Private Attributes | Static Private Attributes | List of all members
Subscriptor Class Reference

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

Inherited by AffineConstraints< number >, AffineConstraints< double >, AffineConstraints< typename MatrixType::value_type >, AffineConstraints< typename VectorType::value_type >, Algorithms::OperatorBase, Algorithms::OutputOperator< VectorType >, Algorithms::TimestepControl, AnyData, ArpackSolver, BlockIndices, BlockInfo, BlockMatrixArray< number, BlockVectorType >, BlockMatrixBase< MatrixType >, BlockMatrixBase< SparseMatrix >, BlockMatrixBase< SparseMatrix< number > >, BlockSparseMatrixEZ< Number >, BlockSparsityPatternBase< SparsityPatternType >, BlockSparsityPatternBase< DynamicSparsityPattern >, BlockSparsityPatternBase< SparsityPattern >, BlockVectorBase< VectorType >, BlockVectorBase< MPI::Vector >, BlockVectorBase< Vector >, BlockVectorBase< Vector< Number > >, GridTools::Cache< dim, DoFHandlerType::space_dimension >, CellDataStorage< CellIteratorType, DataType >, ChunkSparseMatrix< number > [virtual], ChunkSparsityPattern, CUDAWrappers::MatrixFree< dim, Number >, CUDAWrappers::SparseMatrix< Number > [virtual], DataPostprocessor< dim >, DataPostprocessor< DoFHandlerType::space_dimension >, DiagonalMatrix< VectorType >, DoFHandler< dim, spacedim >, hp::DoFHandler< dim >, DoFHandler< dim >, DynamicSparsityPattern, hp::FECollection< dim, dim >, 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 >, FESeries::Fourier< dim, spacedim >, FESeries::Legendre< dim, spacedim >, FETools::FEFactoryBase< dim, spacedim >, FEValuesBase< dim, spacedim >, FilteredMatrix< VectorType >, FiniteElement< dim, spacedim >, FiniteElement< 1, spacedim >, FiniteElement< 2, 2 >, FiniteElement< dim >, FiniteElement< dim, dim >, Function< dim, RangeNumberType >, Function< 2 >, Function< chartdim >, Function< dim >, Function< dim, VectorType::value_type >, Function< spacedim >, GridTools::Cache< dim, spacedim >, hp::DoFHandler< dim, spacedim >, hp::FECollection< dim, spacedim >, hp::MappingCollection< dim, spacedim >, hp::QCollection< dim >, InterGridMap< MeshType >, LinearAlgebra::distributed::Vector< Number, MemorySpace >, LinearAlgebra::EpetraWrappers::Vector, LinearAlgebra::ReadWriteVector< Number >, LogStream, Manifold< dim, spacedim >, Manifold< dim, dim >, 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 > >, MatrixFree< dim, Number >, MatrixFreeOperators::Base< dim, VectorType >, MatrixFreeOperators::MGInterfaceOperator< OperatorType >, MeanValueFilter, MeshWorker::LocalIntegrator< dim, spacedim, number >, MeshWorker::VectorSelector, mg::SparseMatrixCollection< number >, MGCoarseGridBase< VectorType >, MGConstrainedDoFs, MGLevelObject< Object >, MGLevelObject< LinearAlgebra::distributed::Vector< Number > >, MGLevelObject< LinearOperator< BlockVector< number > > >, MGLevelObject< LinearOperator< VectorType > >, MGLevelObject< MatrixType >, MGLevelObject< PreconditionerType >, MGLevelObject< RelaxationType >, MGLevelObject< SparseMatrix< number > >, MGLevelObject< SparsityPattern >, MGLevelObject< VectorType >, MGMatrixBase< VectorType >, MGMatrixBase< Vector< number > >, MGMatrixBlockVector< MatrixType >, MGSmootherBase< VectorType >, MGSmootherBase< BlockVector< number > >, MGTransferBase< VectorType >, MGTransferBase< BlockVector< number > >, MGTransferBase< LinearAlgebra::distributed::BlockVector< Number > >, MGTransferBase< LinearAlgebra::distributed::Vector< Number > >, MGTransferBase< Vector< number > >, Multigrid< VectorType >, ParameterAcceptor, ParameterHandler, PArpackSolver< VectorType >, PArpackSolver< VectorType >::Shift< MatrixType >, Particles::ParticleHandler< dim, spacedim >, PETScWrappers::MatrixBase, PETScWrappers::VectorBase, Polynomials::PiecewisePolynomial< double >, PointerMatrixBase< VectorType >, PointerMatrixBase< typename BlockVectorType::BlockType >, PointerMatrixBase< 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, PreconditionerType >, PreconditionIdentity, PreconditionLU< number >, PreconditionMG< dim, VectorType, TRANSFER >, PreconditionRelaxation< MatrixType >, PreconditionRichardson, PreconditionSelector< MatrixType, VectorType >, PreconditionUseMatrix< MatrixType, VectorType >, hp::QCollection< q_dim >, Quadrature< dim >, Quadrature< 1 >, Quadrature< dim-1 >, Quadrature< structdim >, RelaxationBlock< MatrixType, InverseNumberType, VectorType >::AdditionalData, RelaxationBlockJacobi< MatrixType, InverseNumberType, VectorType > [virtual], RelaxationBlockSOR< MatrixType, InverseNumberType, VectorType > [virtual], RelaxationBlockSSOR< MatrixType, InverseNumberType, VectorType > [virtual], 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, NumberType >, 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, RangeNumberType >, TimeStepBase, Triangulation< dim, spacedim >, Triangulation< dim, dim >, Triangulation< DoFHandler< dim >::dimension, DoFHandler< dim >::space_dimension >, Triangulation< DoFHandlerType::dimension, DoFHandlerType::space_dimension >, TrilinosWrappers::MPI::Vector, TrilinosWrappers::PreconditionBase, TrilinosWrappers::SparseMatrix, TrilinosWrappers::SparsityPattern, Vector< Number >, LinearAlgebra::distributed::Vector< double >, Vector< double >, LinearAlgebra::distributed::Vector< Number >, Vector< number >, Vector< RangeNumberType >, Vector< typename VectorType::value_type >, VectorMemory< VectorType >, VectorMemory< BlockVector< number > >, and VectorMemory< Vector< number > >.

Public Member Functions

 Subscriptor ()
 Subscriptor (const Subscriptor &)
 Subscriptor (Subscriptor &&) noexcept
virtual ~Subscriptor ()
Subscriptoroperator= (const Subscriptor &)
Subscriptoroperator= (Subscriptor &&) noexcept
template<typename ConstCharStar = const char *>
std::enable_if< std::is_same< ConstCharStar, const char * >::value >::type subscribe (std::atomic< bool > *const validity, ConstCharStar identifier=nullptr) const
void subscribe (std::atomic< bool > *const validity, const char *&&identifier) const =delete
void unsubscribe (std::atomic< bool > *const validity, const char *identifier=nullptr) const
unsigned int n_subscriptions () const
template<typename StreamType >
void list_subscribers (StreamType &stream) const
void list_subscribers () const
template<class Archive >
void serialize (Archive &ar, const unsigned int version)

Static Public Member Functions

static::ExceptionBase & ExcInUse (int arg1, std::string arg2, std::string arg3)
static::ExceptionBase & ExcNoSubscriber (std::string arg1, std::string arg2)

Private Types

using map_value_type = decltype(counter_map)::value_type
using map_iterator = decltype(counter_map)::iterator

Private Member Functions

void check_no_subscribers () const noexcept

Private Attributes

std::atomic< unsigned int > counter
std::map< const char *, unsigned int, MapCompare > counter_map
std::vector< std::atomic< bool > * > validity_pointers
const std::type_info * object_info

Static Private Attributes

static std::mutex mutex

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 to avoid that pointers that point to an object of a class derived from Subscriptor are referenced after that object has been invalidated. Here, invalidation is assumend to happen when the object is moved from or destroyed. The mechanism works as follows: The member function subscribe() accepts a pointer to a boolean that is modified on invalidation. The object that owns this pointer (usually an object of class type SmartPointer) is then expected to check the state of the boolean before trying to access this class.

The utility of this class is even enhanced by providing identifying strings to the functions subscribe() and unsubscribe(). These strings are represented as const char pointers since the underlying buffer comes from (and is managed by) the run-time type information system: more exactly, these pointers are the result the function call typeid(x).name() where x is some object. 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. The current subscribers to this class can be obtained by calling list_subscribers().

Guido Kanschat, Daniel Arndt, 1998 - 2005, 2018

Definition at line 62 of file subscriptor.h.

Member Typedef Documentation

using Subscriptor::map_value_type = decltype(counter_map)::value_type

The data type used in counter_map.

Definition at line 247 of file subscriptor.h.

using Subscriptor::map_iterator = decltype(counter_map)::iterator

The iterator type used in counter_map.

Definition at line 252 of file subscriptor.h.

Constructor & Destructor Documentation

Subscriptor::Subscriptor ( )

Constructor setting the counter to zero.

Definition at line 293 of file subscriptor.h.

Subscriptor::Subscriptor ( const Subscriptor )


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

Definition at line 300 of file subscriptor.h.

Subscriptor::Subscriptor ( Subscriptor &&  subscriptor)

Move constructor.

An object inheriting from Subscriptor can only be moved if no other objects are subscribing to it.

Definition at line 34 of file

Subscriptor::~Subscriptor ( )

Destructor, asserting that the counter is zero.

Definition at line 44 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 308 of file subscriptor.h.

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

Move assignment operator. Only invalidates the object moved from.

Definition at line 119 of file

template<typename ConstCharStar = const char *>
std::enable_if< std::is_same<ConstCharStar, const char *>::value>::type Subscriptor::subscribe ( std::atomic< bool > *const  validity,
ConstCharStar  identifier = nullptr 
) const

Subscribes a user of the object by storing the pointer validity. The subscriber may be identified by text supplied as identifier. The latter variable must not be a temporary and its type must decay to const char *. In particular, calling this function with a rvalue reference is not allowed.

void Subscriptor::subscribe ( std::atomic< bool > *const  validity,
const char *&&  identifier 
) const

Calling subscribe() with a rvalue reference as identifier is not allowed.

void Subscriptor::unsubscribe ( std::atomic< bool > *const  validity,
const char *  identifier = nullptr 
) const

Unsubscribes a user from the object.

The identifier and the validity pointer must be the same as the one supplied to subscribe().

Definition at line 155 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 317 of file subscriptor.h.

template<typename StreamType >
void Subscriptor::list_subscribers ( StreamType &  stream) const

List the subscribers to the input stream.

Definition at line 334 of file subscriptor.h.

void Subscriptor::list_subscribers ( ) const

List the subscribers to deallog.

Definition at line 202 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 326 of file subscriptor.h.

void Subscriptor::check_no_subscribers ( ) const

Check that there are no objects subscribing to this object. If this check passes then it is safe to destroy the current object. It this check fails then this function will either abort or print an error message to deallog (by using the AssertNothrow mechanism), but will not throw an exception.

Since this function is just a consistency check it does nothing in release mode.
If this function is called when there is an uncaught exception then, rather than aborting, this function prints an error message to the standard error stream and returns.

Definition at line 53 of file

Member Data Documentation

std::atomic<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.

This counter may be read from and written to concurrently in multithreaded code: hence we use the std::atomic class template.

Definition at line 223 of file subscriptor.h.

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

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

Definition at line 242 of file subscriptor.h.

std::vector<std::atomic<bool> *> Subscriptor::validity_pointers

In this vector, we store pointers to the validity bool in the SmartPointer objects that subscribe to this class.

Definition at line 258 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 266 of file subscriptor.h.

std::mutex Subscriptor::mutex

A mutex used to ensure data consistency when printing out the list of subscribers.

Definition at line 288 of file subscriptor.h.

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