--- /dev/null
+Changed: SmartPointer and Subscriptor use a std::string
+instead of a const char * as identifier.
+<br>
+(Daniel Arndt, 2019/04/08)
* The <tt>id</tt> is used in the call to Subscriptor::subscribe(id) and by
* ~SmartPointer() in the call to Subscriptor::unsubscribe().
*/
- SmartPointer(T *t, const char *id);
+ SmartPointer(T *t, const std::string &id);
/**
* Constructor taking a normal pointer. If possible, i.e. if the pointer is
/**
* The identification for the subscriptor.
*/
- const char *const id;
+ const std::string id;
/**
* The Smartpointer is invalidated when the object pointed to is destroyed
template <typename T, typename P>
-inline SmartPointer<T, P>::SmartPointer(T *t, const char *id)
+inline SmartPointer<T, P>::SmartPointer(T *t, const std::string &id)
: t(t)
, id(id)
, pointed_to_object_is_alive(false)
/**
* Subscribes a user of the object by storing the pointer @p validity. The
- * subscriber may be identified by text supplied as @p 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.
- */
- template <typename ConstCharStar = const char *>
- typename std::enable_if<
- std::is_same<ConstCharStar, const char *>::value>::type
- subscribe(std::atomic<bool> *const validity,
- ConstCharStar identifier = nullptr) const;
-
- /**
- * Calling subscribe() with a rvalue reference as identifier is not allowed.
+ * subscriber may be identified by text supplied as @p identifier.
*/
void
subscribe(std::atomic<bool> *const validity,
- const char *&& identifier) const = delete;
+ const std::string & identifier = "") const;
/**
* Unsubscribes a user from the object.
*/
void
unsubscribe(std::atomic<bool> *const validity,
- const char * identifier = nullptr) const;
+ const std::string & identifier = "") const;
/**
* Return the present number of subscriptions to this object. This allows to
*/
mutable std::atomic<unsigned int> counter;
- /*
- * Functor struct used for key comparison in #counter_map.
- * Not the memory location but the actual C-string content is compared.
- */
- struct MapCompare
- {
- bool
- operator()(const char *lhs, const char *rhs) const
- {
- return std::strcmp(lhs, rhs) > 0;
- }
- };
-
/**
* In this map, we count subscriptions for each different identification
* string supplied to subscribe().
*/
- mutable std::map<const char *, unsigned int, MapCompare> counter_map;
+ mutable std::map<std::string, unsigned int> counter_map;
/**
* The data type used in #counter_map.
<< it.first << '\"' << std::endl;
}
-// forward declare template specialization
-template <>
-void
-Subscriptor::subscribe<const char *>(std::atomic<bool> *const validity,
- const char * id) const;
DEAL_II_NAMESPACE_CLOSE
#endif
-template <>
void
-Subscriptor::subscribe<const char *>(std::atomic<bool> *const validity,
- const char * id) const
+Subscriptor::subscribe(std::atomic<bool> *const validity,
+ const std::string & id) const
{
std::lock_guard<std::mutex> lock(mutex);
object_info = &typeid(*this);
++counter;
- const char *const name = (id != nullptr) ? id : unknown_subscriber;
+ const std::string name = (id != "") ? id : unknown_subscriber;
map_iterator it = counter_map.find(name);
if (it == counter_map.end())
void
Subscriptor::unsubscribe(std::atomic<bool> *const validity,
- const char * id) const
+ const std::string & id) const
{
- const char *name = (id != nullptr) ? id : unknown_subscriber;
+ const std::string name = (id != "") ? id : unknown_subscriber;
if (counter == 0)
{
AssertNothrow(counter > 0, ExcNoSubscriber(object_info->name(), name));
DEAL::
--------------------------------------------------------
An error occurred in file <subscriptor.cc> in function
- void dealii::Subscriptor::unsubscribe(std::atomic<bool>*, const char*) const
+ void dealii::Subscriptor::unsubscribe(std::atomic<bool>*, const string&) const
The violated condition was:
it != counter_map.end()
Additional information:
DEAL::
--------------------------------------------------------
An error occurred in file <subscriptor.cc> in function
- void dealii::Subscriptor::unsubscribe(std::atomic<bool>*, const char*) const
+ void dealii::Subscriptor::unsubscribe(std::atomic<bool>*, const string&) const
The violated condition was:
validity_ptr_it != validity_pointers.end()
Additional information:
DEAL::
--------------------------------------------------------
An error occurred in file <subscriptor.cc> in function
- void dealii::Subscriptor::unsubscribe(std::atomic<bool> *const, const char *) const
+ void dealii::Subscriptor::unsubscribe(std::atomic<bool> *const, const std::string &) const
The violated condition was:
it != counter_map.end()
Additional information:
DEAL::
--------------------------------------------------------
An error occurred in file <subscriptor.cc> in function
- void dealii::Subscriptor::unsubscribe(std::atomic<bool> *const, const char *) const
+ void dealii::Subscriptor::unsubscribe(std::atomic<bool> *const, const std::string &) const
The violated condition was:
validity_ptr_it != validity_pointers.end()
Additional information:
DEAL::
--------------------------------------------------------
An error occurred in file <subscriptor.cc> in function
- void dealii::Subscriptor::unsubscribe(std::atomic<bool> *, const char *) const
+ void dealii::Subscriptor::unsubscribe(std::atomic<bool> *, const std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>> &) const
The violated condition was:
it != counter_map.end()
Additional information:
DEAL::
--------------------------------------------------------
An error occurred in file <subscriptor.cc> in function
- void dealii::Subscriptor::unsubscribe(std::atomic<bool> *, const char *) const
+ void dealii::Subscriptor::unsubscribe(std::atomic<bool> *, const std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>> &) const
The violated condition was:
validity_ptr_it != validity_pointers.end()
Additional information: