Fix up support for ASIO_NO_TYPEID (i.e. no RTTI).

This commit is contained in:
Christopher Kohlhoff 2015-03-17 19:42:07 +11:00
parent e19f2bd660
commit df9d70bc55
2 changed files with 31 additions and 7 deletions

View File

@ -205,10 +205,17 @@ public:
* @returns If @c *this has a target type of type @c T, <tt>typeid(T)</tt>;
* otherwise, <tt>typeid(void)</tt>.
*/
#if !defined(ASIO_NO_TYPEID) || defined(GENERATING_DOCUMENTATION)
const std::type_info& target_type() const ASIO_NOEXCEPT
{
return impl_ ? impl_->target_type() : typeid(void);
}
#else // !defined(ASIO_NO_TYPEID) || defined(GENERATING_DOCUMENTATION)
const void* target_type() const ASIO_NOEXCEPT
{
return impl_ ? impl_->target_type() : 0;
}
#endif // !defined(ASIO_NO_TYPEID) || defined(GENERATING_DOCUMENTATION)
/// Obtain a pointer to the target executor object.
/**
@ -249,6 +256,23 @@ private:
class function;
template <typename, typename> class impl;
#if !defined(ASIO_NO_TYPEID)
typedef const std::type_info& type_id_result_type;
#else // !defined(ASIO_NO_TYPEID)
typedef const void* type_id_result_type;
#endif // !defined(ASIO_NO_TYPEID)
template <typename T>
static type_id_result_type type_id()
{
#if !defined(ASIO_NO_TYPEID)
return typeid(T);
#else // !defined(ASIO_NO_TYPEID)
static int unique_id;
return &unique_id;
#endif // !defined(ASIO_NO_TYPEID)
}
// Base class for all polymorphic executor implementations.
class impl_base
{
@ -261,7 +285,7 @@ private:
virtual void dispatch(ASIO_MOVE_ARG(function)) = 0;
virtual void post(ASIO_MOVE_ARG(function)) = 0;
virtual void defer(ASIO_MOVE_ARG(function)) = 0;
virtual const std::type_info& target_type() const ASIO_NOEXCEPT = 0;
virtual type_id_result_type target_type() const ASIO_NOEXCEPT = 0;
virtual void* target() ASIO_NOEXCEPT = 0;
virtual const void* target() const ASIO_NOEXCEPT = 0;
virtual bool equals(const impl_base* e) const ASIO_NOEXCEPT = 0;

View File

@ -197,9 +197,9 @@ public:
executor_.defer(ASIO_MOVE_CAST(function)(f), allocator_);
}
const std::type_info& target_type() const ASIO_NOEXCEPT
type_id_result_type target_type() const ASIO_NOEXCEPT
{
return typeid(Executor);
return type_id<Executor>();
}
void* target() ASIO_NOEXCEPT
@ -306,9 +306,9 @@ public:
executor_.defer(ASIO_MOVE_CAST(function)(f), allocator_);
}
const std::type_info& target_type() const ASIO_NOEXCEPT
type_id_result_type target_type() const ASIO_NOEXCEPT
{
return typeid(system_executor);
return type_id<system_executor>();
}
void* target() ASIO_NOEXCEPT
@ -368,14 +368,14 @@ void executor::defer(ASIO_MOVE_ARG(Function) f, const Allocator& a)
template <typename Executor>
Executor* executor::target() ASIO_NOEXCEPT
{
return impl_ && impl_->target_type() == typeid(Executor)
return impl_ && impl_->target_type() == type_id<Executor>()
? static_cast<Executor*>(impl_->target()) : 0;
}
template <typename Executor>
const Executor* executor::target() const ASIO_NOEXCEPT
{
return impl_ && impl_->target_type() == typeid(Executor)
return impl_ && impl_->target_type() == type_id<Executor>()
? static_cast<Executor*>(impl_->target()) : 0;
}