Reference documentation for deal.II version 9.0.0
subscriptor.h
1 // ---------------------------------------------------------------------
2 //
3 // Copyright (C) 1998 - 2018 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 at
12 // the top level of the deal.II distribution.
13 //
14 // ---------------------------------------------------------------------
15 
16 #ifndef dealii_subscriptor_h
17 #define dealii_subscriptor_h
18 
19 
20 #include <deal.II/base/config.h>
21 #include <deal.II/base/exceptions.h>
22 
23 #include <atomic>
24 #include <map>
25 #include <string>
26 #include <typeinfo>
27 
28 DEAL_II_NAMESPACE_OPEN
29 
61 {
62 public:
66  Subscriptor();
67 
74  Subscriptor(const Subscriptor &);
75 
82  Subscriptor(Subscriptor &&) noexcept;
83 
87  virtual ~Subscriptor();
88 
96 
102  Subscriptor &operator = (Subscriptor &&) noexcept;
103 
108  void subscribe (const char *identifier = nullptr) const;
109 
116  void unsubscribe (const char *identifier = nullptr) const;
117 
123  unsigned int n_subscriptions () const;
124 
128  void list_subscribers () const;
129 
139  int, std::string, std::string,
140  << "Object of class " << arg2
141  << " is still used by " << arg1 << " other objects."
142  << "\n\n"
143  << "(Additional information: " << arg3 << ")\n\n"
144  << "See the entry in the Frequently Asked Questions of "
145  << "deal.II (linked to from http://www.dealii.org/) for "
146  << "a lot more information on what this error means and "
147  << "how to fix programs in which it happens.");
148 
153  DeclException2(ExcNoSubscriber, std::string, std::string,
154  << "No subscriber with identifier <" << arg2
155  << "> subscribes to this object of class " << arg1
156  << ". Consequently, it cannot be unsubscribed.");
158 
171  template <class Archive>
172  void serialize(Archive &ar, const unsigned int version);
173 
174 private:
178  typedef std::map<const char *, unsigned int>::value_type
180 
184  typedef std::map<const char *, unsigned int>::iterator
186 
203  mutable std::atomic<unsigned int> counter;
204 
209  mutable std::map<const char *, unsigned int> counter_map;
210 
217  mutable const std::type_info *object_info;
218 
232  void check_no_subscribers () const noexcept;
233 };
234 
235 //---------------------------------------------------------------------------
236 
237 template <class Archive>
238 inline
239 void
241  const unsigned int)
242 {
243  // do nothing, as explained in the
244  // documentation of this function
245 }
246 
247 DEAL_II_NAMESPACE_CLOSE
248 
249 #endif
static ::ExceptionBase & ExcInUse(int arg1, std::string arg2, std::string arg3)
#define DeclException2(Exception2, type1, type2, outsequence)
Definition: exceptions.h:358
const std::type_info * object_info
Definition: subscriptor.h:217
void unsubscribe(const char *identifier=nullptr) const
Definition: subscriptor.cc:177
Subscriptor & operator=(const Subscriptor &)
Definition: subscriptor.cc:129
void list_subscribers() const
Definition: subscriptor.cc:212
void serialize(Archive &ar, const unsigned int version)
Definition: subscriptor.h:240
unsigned int n_subscriptions() const
Definition: subscriptor.cc:205
void subscribe(const char *identifier=nullptr) const
Definition: subscriptor.cc:149
std::atomic< unsigned int > counter
Definition: subscriptor.h:203
std::map< const char *, unsigned int > counter_map
Definition: subscriptor.h:209
std::map< const char *, unsigned int >::iterator map_iterator
Definition: subscriptor.h:185
virtual ~Subscriptor()
Definition: subscriptor.cc:59
std::map< const char *, unsigned int >::value_type map_value_type
Definition: subscriptor.h:179
#define DeclException3(Exception3, type1, type2, type3, outsequence)
Definition: exceptions.h:370
static ::ExceptionBase & ExcNoSubscriber(std::string arg1, std::string arg2)
void check_no_subscribers() const noexcept
Definition: subscriptor.cc:66