Reference documentation for deal.II version 9.5.0
\(\newcommand{\dealvcentcolon}{\mathrel{\mathop{:}}}\) \(\newcommand{\dealcoloneq}{\dealvcentcolon\mathrel{\mkern-1.2mu}=}\) \(\newcommand{\jump}[1]{\left[\!\left[ #1 \right]\!\right]}\) \(\newcommand{\average}[1]{\left\{\!\left\{ #1 \right\}\!\right\}}\)
Loading...
Searching...
No Matches
subscriptor.h
Go to the documentation of this file.
1// ---------------------------------------------------------------------
2//
3// Copyright (C) 1998 - 2022 by the deal.II authors
4//
5// This file is part of the deal.II library.
6//
7// The deal.II library is free software; you can use it, redistribute
8// it, and/or modify it under the terms of the GNU Lesser General
9// Public License as published by the Free Software Foundation; either
10// version 2.1 of the License, or (at your option) any later version.
11// The full text of the license can be found in the file LICENSE.md at
12// the top level directory of deal.II.
13//
14// ---------------------------------------------------------------------
15
16#ifndef dealii_subscriptor_h
17#define dealii_subscriptor_h
18
19
20#include <deal.II/base/config.h>
21
23
24#include <atomic>
25#include <map>
26#include <mutex>
27#include <string>
28#include <typeinfo>
29#include <vector>
30
32
61{
62public:
67
74 Subscriptor(const Subscriptor &);
75
82 Subscriptor(Subscriptor &&) noexcept;
83
87 virtual ~Subscriptor();
88
96 operator=(const Subscriptor &);
97
102 operator=(Subscriptor &&) noexcept;
103
116 void
117 subscribe(std::atomic<bool> *const validity,
118 const std::string & identifier = "") const;
119
126 void
127 unsubscribe(std::atomic<bool> *const validity,
128 const std::string & identifier = "") const;
129
135 unsigned int
136 n_subscriptions() const;
137
141 template <typename StreamType>
142 void
143 list_subscribers(StreamType &stream) const;
144
148 void
149 list_subscribers() const;
150
162 int,
163 std::string,
164 std::string,
165 << "Object of class " << arg2 << " is still used by " << arg1
166 << " other objects."
167 << "\n\n"
168 << "(Additional information: " << arg3 << ")\n\n"
169 << "See the entry in the Frequently Asked Questions of "
170 << "deal.II (linked to from http://www.dealii.org/) for "
171 << "a lot more information on what this error means and "
172 << "how to fix programs in which it happens.");
173
179 std::string,
180 std::string,
181 << "No subscriber with identifier <" << arg2
182 << "> subscribes to this object of class " << arg1
183 << ". Consequently, it cannot be unsubscribed.");
199 template <class Archive>
200 void
201 serialize(Archive &ar, const unsigned int version);
202
203private:
219 mutable std::atomic<unsigned int> counter;
220
225 mutable std::map<std::string, unsigned int> counter_map;
226
230 using map_value_type = decltype(counter_map)::value_type;
231
235 using map_iterator = decltype(counter_map)::iterator;
236
241 mutable std::vector<std::atomic<bool> *> validity_pointers;
242
249 mutable const std::type_info *object_info;
250
264 void
265 check_no_subscribers() const noexcept;
266
271 static std::mutex mutex;
272};
273
274//---------------------------------------------------------------------------
275
277 : counter(0)
278 , object_info(nullptr)
279{}
280
281
282
284 : counter(0)
285 , object_info(nullptr)
286{}
287
288
289
290inline Subscriptor &
292{
294 return *this;
295}
296
297
298
299inline unsigned int
301{
302 return counter;
303}
304
305
306
307template <class Archive>
308inline void
309Subscriptor::serialize(Archive &, const unsigned int)
310{
311 // do nothing, as explained in the
312 // documentation of this function
313}
314
315template <typename StreamType>
316inline void
317Subscriptor::list_subscribers(StreamType &stream) const
318{
319 std::lock_guard<std::mutex> lock(mutex);
320
321 for (const auto &it : counter_map)
322 stream << it.second << '/' << counter << " subscriptions from \""
323 << it.first << '\"' << std::endl;
324}
325
327
328#endif
std::vector< std::atomic< bool > * > validity_pointers
void unsubscribe(std::atomic< bool > *const validity, const std::string &identifier="") const
std::atomic< unsigned int > counter
void check_no_subscribers() const noexcept
void list_subscribers() const
const std::type_info * object_info
Subscriptor & operator=(const Subscriptor &)
void subscribe(std::atomic< bool > *const validity, const std::string &identifier="") const
void serialize(Archive &ar, const unsigned int version)
std::map< std::string, unsigned int > counter_map
static std::mutex mutex
decltype(counter_map)::iterator map_iterator
decltype(counter_map)::value_type map_value_type
virtual ~Subscriptor()
unsigned int n_subscriptions() const
#define DEAL_II_NAMESPACE_OPEN
Definition config.h:472
#define DEAL_II_NAMESPACE_CLOSE
Definition config.h:473
static ::ExceptionBase & ExcInUse(int arg1, std::string arg2, std::string arg3)
#define DeclException2(Exception2, type1, type2, outsequence)
Definition exceptions.h:533
static ::ExceptionBase & ExcNoSubscriber(std::string arg1, std::string arg2)
#define DeclException3(Exception3, type1, type2, type3, outsequence)
Definition exceptions.h:556
STL namespace.