cgv
type_name.h
1 #pragma once
2 
3 #include <string>
4 #include <cgv/type/info/type_id.h>
5 #include <cgv/type/cond/is_standard_type.h>
6 #include <typeinfo>
7 
8 #include <cgv/type/lib_begin.h>
9 
10 namespace cgv {
11  namespace type {
13  namespace info {
14 
16 extern CGV_API std::string extract_type_name(const std::type_info& ti);
17 
18 namespace detail {
19  // implementation of type_name traits for standard types
20  template <typename T, bool is_std = true>
21  struct dispatch_type_name
22  {
23  // use type id to determine name of standard type
24  static const char* get_name() { return get_type_name(type_id<T>::get_id()); }
25  };
26 
27  // implementation of type_name traits for all other types
28  template <typename T>
29  struct dispatch_type_name<T,false>
30  {
31  // use RTTI and clean up the resulting name from unwanted keywords
32  static const char* get_name() {
33  static std::string type_name = extract_type_name(typeid(T));
34  return type_name.c_str();
35  }
36  };
37 }
38 
52 template <typename T>
53 struct type_name
54 {
56  static const char* get_name() { return detail::dispatch_type_name<T, cond::is_standard_type<T>::value>::get_name(); }
57 };
58 
59  }
60  }
61 }
62 
63 #include <cgv/config/lib_end.h>
cgv::type::info::extract_type_name
std::string extract_type_name(const std::type_info &ti)
extract a type name from an type_info structure that does not contain the class, struct nor enum keyw...
Definition: type_name.cxx:9
cgv::type::info::type_name::get_name
static const char * get_name()
return special name for standard types or type name from RTTI cleaned from keywords for all other typ...
Definition: type_name.h:56
cgv::type::info::get_type_name
const char * get_type_name(TypeId tid)
function that returns the name of a type specified through TypeId
Definition: type_id.cxx:117
cgv
the cgv namespace
Definition: vr_calib.cxx:9
cgv::type::info::type_name
Definition: type_name.h:54