vsg  1.1.0
VulkanSceneGraph library
type_name.h
1 #pragma once
2 
3 /* <editor-fold desc="MIT License">
4 
5 Copyright(c) 2018 Robert Osfield
6 
7 Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
8 
9 The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
10 
11 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
12 
13 </editor-fold> */
14 
15 #include <string>
16 #include <typeinfo>
17 
18 namespace vsg
19 {
20  // clang-format off
21 
22  template<typename T>
23  constexpr const char* type_name() noexcept { return typeid(T).name(); }
24 
25  template<typename T>
26  constexpr const char* type_name(const T&) noexcept { return type_name<T>(); }
27 
28  template<> constexpr const char* type_name<std::string>() noexcept { return "string"; }
29  template<> constexpr const char* type_name<bool>() noexcept { return "bool"; }
30  template<> constexpr const char* type_name<char>() noexcept { return "char"; }
31  template<> constexpr const char* type_name<int8_t>() noexcept { return "int8_t"; }
32  template<> constexpr const char* type_name<unsigned char>() noexcept { return "uchar"; }
33  template<> constexpr const char* type_name<short>() noexcept { return "short"; }
34  template<> constexpr const char* type_name<unsigned short>() noexcept { return "ushort"; }
35  template<> constexpr const char* type_name<int>() noexcept { return "int"; }
36  template<> constexpr const char* type_name<unsigned int>() noexcept { return "uint"; }
37  template<> constexpr const char* type_name<float>() noexcept { return "float"; }
38  template<> constexpr const char* type_name<double>() noexcept { return "double"; }
39 
40  // helper define for defining the type_name() for a type within the vsg namespace.
41  #define VSG_type_name(T) \
42  template<> constexpr const char* type_name<T>() noexcept { return #T; } \
43  template<> constexpr const char* type_name<const T>() noexcept { return "const "#T; }
44 
45 
46  // helper define for defining the type_name() for a type in a namespace other than vsg, note must be placed in global namespace.
47  #define EVSG_type_name(T) \
48  template<> constexpr const char* vsg::type_name<T>() noexcept { return #T; } \
49  template<> constexpr const char* vsg::type_name<const T>() noexcept { return "const "#T; }
50 
51  // clang-format on
52 
53 } // namespace vsg