include/deal.II/base/subscriptor.h

00001 //---------------------------------------------------------------------------
00002 //    @f$Id: subscriptor.h 25460 2012-04-27 09:19:06Z bangerth @f$
00003 //
00004 //    Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2010, 2012 by the deal.II authors
00005 //
00006 //    This file is subject to QPL and may not be  distributed
00007 //    without copyright and license information. Please refer
00008 //    to the file deal.II/doc/license.html for the  text  and
00009 //    further information on this license.
00010 //
00011 //---------------------------------------------------------------------------
00012 #ifndef __deal2__subscriptor_h
00013 #define __deal2__subscriptor_h
00014 
00015 
00016 #include <deal.II/base/config.h>
00017 #include <deal.II/base/exceptions.h>
00018 
00019 #include <typeinfo>
00020 #include <map>
00021 #include <string>
00022 
00023 DEAL_II_NAMESPACE_OPEN
00024 
00052 class Subscriptor
00053 {
00054   public:
00058     Subscriptor();
00059 
00067     Subscriptor(const Subscriptor&);
00068 
00073     virtual ~Subscriptor();
00074 
00084     Subscriptor& operator = (const Subscriptor&);
00085 
00092     void subscribe (const char* identifier = 0) const;
00093 
00104     void unsubscribe (const char* identifier = 0) const;
00105 
00115     unsigned int n_subscriptions () const;
00116 
00120     void list_subscribers () const;
00121 
00130     DeclException3(ExcInUse,
00131                    int, char*, std::string &,
00132                    << "Object of class " << arg2
00133                    << " is still used by " << arg1 << " other objects."
00134                    << arg3);
00135 
00142     DeclException2(ExcNoSubscriber, char*, char*,
00143                    << "No subscriber with identifier \"" << arg2
00144                    << "\" did subscribe to this object of class " << arg1);
00146 
00171     template <class Archive>
00172     void serialize(Archive & ar, const unsigned int version);
00173 
00174   private:
00180     void do_subscribe(const char* id) const;
00181 
00187     void do_unsubscribe(const char* id) const;
00188 
00193     typedef std::map<const char*, unsigned int>::value_type
00194     map_value_type;
00195 
00200     typedef std::map<const char*, unsigned int>::iterator
00201     map_iterator;
00202 
00233     mutable DEAL_VOLATILE unsigned int counter;
00234 
00241     mutable std::map<const char*, unsigned int> counter_map;
00242 
00254     mutable const std::type_info * object_info;
00255 };
00256 
00257 //---------------------------------------------------------------------------
00258 
00259 template <class Archive>
00260 inline
00261 void
00262 Subscriptor::serialize(Archive &,
00263                        const unsigned int)
00264 {
00265                                    // do nothing, as explained in the
00266                                    // documentation of this function
00267 }
00268 
00269 // If we are in optimized mode, the subscription checking is turned
00270 // off. Therefore, we provide inline definitions of subscribe and
00271 // unsubscribe here. The definitions for debug mode are in
00272 // subscriptor.cc.
00273 
00274 #ifdef DEBUG
00275 
00276 inline void
00277 Subscriptor::subscribe(const char* id) const
00278 {
00279   do_subscribe(id);
00280 }
00281 
00282 
00283 inline void
00284 Subscriptor::unsubscribe(const char* id) const
00285 {
00286   do_unsubscribe(id);
00287 }
00288 
00289 #else
00290 
00291 inline void
00292 Subscriptor::subscribe(const char*) const
00293 {}
00294 
00295 
00296 inline void
00297 Subscriptor::unsubscribe(const char*) const
00298 {}
00299 
00300 #endif
00301 DEAL_II_NAMESPACE_CLOSE
00302 
00303 #endif
00304 
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines

deal.II documentation generated on Wed May 23 2012 12:03:21 by doxygen 1.7.3