mirror of
https://gitlab.kitware.com/vtk/vtk-m
synced 2024-09-19 02:25:42 +00:00
Enable TypeToString
for type_info
VTK-m contains a helpful method named `vtkm::cont::TypeToString` that either takes a type as a template argument or a `std::type_info` object and returns a human-readable string for that type. The standard C++ library has an alternate for `std::type_info` named `std::type_index`, which has the added ability to be used in a container like `set` or `map`. The `TypeToString` overloads have been extended to also accept a `std::type_info` and report the name of the type stored in it (rather than the name of `type_info` itself).
This commit is contained in:
parent
8f2d002465
commit
6f5455d0d6
11
docs/changelog/type-index-names.md
Normal file
11
docs/changelog/type-index-names.md
Normal file
@ -0,0 +1,11 @@
|
||||
# Enable `TypeToString` for `type_info`
|
||||
|
||||
VTK-m contains a helpful method named `vtkm::cont::TypeToString` that
|
||||
either takes a type as a template argument or a `std::type_info` object and
|
||||
returns a human-readable string for that type.
|
||||
|
||||
The standard C++ library has an alternate for `std::type_info` named
|
||||
`std::type_index`, which has the added ability to be used in a container
|
||||
like `set` or `map`. The `TypeToString` overloads have been extended to
|
||||
also accept a `std::type_info` and report the name of the type stored in it
|
||||
(rather than the name of `type_info` itself).
|
@ -298,5 +298,24 @@ std::string GetLogLevelName(LogLevel level)
|
||||
using T = std::underlying_type<LogLevel>::type;
|
||||
return std::to_string(static_cast<T>(level));
|
||||
}
|
||||
|
||||
VTKM_CONT std::string TypeToString(const std::type_info& t)
|
||||
{
|
||||
#ifdef VTKM_ENABLE_LOGGING
|
||||
return loguru::demangle(t.name()).c_str();
|
||||
#else // VTKM_ENABLE_LOGGING
|
||||
return t.name();
|
||||
#endif // VTKM_ENABLE_LOGGING
|
||||
}
|
||||
|
||||
VTKM_CONT std::string TypeToString(const std::type_index& t)
|
||||
{
|
||||
#ifdef VTKM_ENABLE_LOGGING
|
||||
return loguru::demangle(t.name()).c_str();
|
||||
#else // VTKM_ENABLE_LOGGING
|
||||
return t.name();
|
||||
#endif // VTKM_ENABLE_LOGGING
|
||||
}
|
||||
|
||||
}
|
||||
} // end namespace vtkm::cont
|
||||
|
@ -39,6 +39,7 @@
|
||||
#endif // VTKM_ENABLE_LOGGING
|
||||
|
||||
#include <string>
|
||||
#include <typeindex>
|
||||
#include <typeinfo>
|
||||
|
||||
/// \file Logging.h
|
||||
@ -472,14 +473,8 @@ VTKM_CONT inline std::string GetSizeString(T&& bytes, int prec = 2)
|
||||
* enabled and the platform supports it, the type name will also be demangled.
|
||||
* @{
|
||||
*/
|
||||
inline VTKM_CONT std::string TypeToString(const std::type_info& t)
|
||||
{
|
||||
#ifdef VTKM_ENABLE_LOGGING
|
||||
return loguru::demangle(t.name()).c_str();
|
||||
#else // VTKM_ENABLE_LOGGING
|
||||
return t.name();
|
||||
#endif // VTKM_ENABLE_LOGGING
|
||||
}
|
||||
VTKM_CONT_EXPORT VTKM_CONT std::string TypeToString(const std::type_info& t);
|
||||
VTKM_CONT_EXPORT VTKM_CONT std::string TypeToString(const std::type_index& t);
|
||||
template <typename T>
|
||||
inline VTKM_CONT std::string TypeToString()
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user