Skip to content

Commit

Permalink
Move type info into hpx::debug namespace and add print helper functions
Browse files Browse the repository at this point in the history
  • Loading branch information
biddisco committed Feb 23, 2018
1 parent a4c18bd commit 9279688
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 11 deletions.
2 changes: 1 addition & 1 deletion hpx/runtime/actions/action_support.hpp
Expand Up @@ -72,7 +72,7 @@ namespace hpx { namespace actions
static_assert(
traits::needs_automatic_registration<Action>::value,
"HPX_REGISTER_ACTION_DECLARATION missing");
return util::type_id<Action>::typeid_.type_id();
return debug::type_id<Action>::typeid_.type_id();
}
#endif

Expand Down
Expand Up @@ -157,12 +157,12 @@ namespace hpx { namespace serialization { namespace detail

#define HPX_SERIALIZATION_POLYMORPHIC_TEMPLATE(Class) \
HPX_SERIALIZATION_POLYMORPHIC_WITH_NAME( \
Class, hpx::util::type_id<Class>::typeid_.type_id();) \
Class, hpx::debug::type_id<Class>::typeid_.type_id();) \
/**/

#define HPX_SERIALIZATION_POLYMORPHIC_TEMPLATE_SPLITTED(Class) \
HPX_SERIALIZATION_POLYMORPHIC_WITH_NAME_SPLITTED( \
Class, hpx::util::type_id<T>::typeid_.type_id();) \
Class, hpx::debug::type_id<T>::typeid_.type_id();) \
/**/

#endif
Expand Up @@ -48,7 +48,7 @@ namespace hpx { namespace serialization { namespace detail
static_assert(
traits::needs_automatic_registration<T>::value,
"HPX_REGISTER_ACTION_DECLARATION missing");
return util::type_id<T>::typeid_.type_id();
return debug::type_id<T>::typeid_.type_id();
}
};
#endif
Expand Down Expand Up @@ -281,7 +281,7 @@ namespace hpx { namespace serialization { namespace detail
#define HPX_SERIALIZATION_REGISTER_CLASS_TEMPLATE(Parameters, Template) \
HPX_SERIALIZATION_REGISTER_CLASS_NAME_TEMPLATE( \
Parameters, Template, \
hpx::util::type_id<HPX_PP_STRIP_PARENS(Template) >::typeid_.type_id())\
hpx::debug::type_id<HPX_PP_STRIP_PARENS(Template) >::typeid_.type_id())\
HPX_PP_STRIP_PARENS(Parameters) hpx::serialization::detail::register_class< \
HPX_PP_STRIP_PARENS(Template)> \
HPX_PP_STRIP_PARENS(Template)::hpx_register_class_instance; \
Expand Down
41 changes: 36 additions & 5 deletions hpx/util/demangle_helper.hpp
@@ -1,3 +1,4 @@
// Copyright (c) 2017 John Biddiscombe
// Copyright (c) 2007-2012 Hartmut Kaiser
//
// Distributed under the Boost Software License, Version 1.0. (See accompanying
Expand All @@ -7,14 +8,18 @@
#define HPX_UTIL_DEMANGLE_HELPER_OCT_28_2011_0410PM

#include <hpx/config.hpp>
#include <string>
#include <type_traits>

// disable the code specific to gcc for now as this causes problems
// (see #811: simple_central_tuplespace_client run error)
#if 0 // defined(__GNUC__)
#if defined(__GNUC__)
#include <cxxabi.h>
#include <stdlib.h>

namespace hpx { namespace util
namespace hpx { namespace debug
{
// --------------------------------------------------------------------
// demangle an arbitrary c++ type using gnu utility
// --------------------------------------------------------------------
template <typename T>
class demangle_helper
{
Expand All @@ -36,6 +41,7 @@ namespace hpx { namespace util
private:
char* demangled_;
};

}}

#else
Expand All @@ -57,7 +63,7 @@ namespace hpx { namespace util
#endif

///////////////////////////////////////////////////////////////////////////////
namespace hpx { namespace util
namespace hpx { namespace debug
{
template <typename T>
struct type_id
Expand All @@ -67,6 +73,31 @@ namespace hpx { namespace util

template <typename T>
demangle_helper<T> type_id<T>::typeid_ = demangle_helper<T>();

// --------------------------------------------------------------------
// print type information
// usage : std::cout << print_type<args...>("separator")
// separator is appended if the number of types > 1
// --------------------------------------------------------------------
template <typename T=void>
inline std::string print_type(const char *delim="")
{
return std::string(debug::type_id<T>::typeid_.type_id());;
}

template <>
inline std::string print_type<>(const char *delim)
{
return "void";
}

template <typename T, typename ...Args>
inline typename std::enable_if<sizeof...(Args)!=0, std::string>::type
print_type(const char *delim="")
{
std::string temp(debug::type_id<T>::typeid_.type_id());
return temp + delim + print_type<Args...>(delim);
}
}}

#endif
Expand Down
2 changes: 1 addition & 1 deletion hpx/util/detail/function_registration.hpp
Expand Up @@ -30,7 +30,7 @@ namespace hpx { namespace util { namespace detail
static char const* call()
#ifdef HPX_HAVE_AUTOMATIC_SERIALIZATION_REGISTRATION
{
return util::type_id<F>::typeid_.type_id();
return debug::type_id<F>::typeid_.type_id();
}
#else
= delete;
Expand Down

0 comments on commit 9279688

Please sign in to comment.