vsg: include/vsg/core/type_name.h Source File

vsg 1.1.3 VulkanSceneGraph library

Loading...
Searching...
No Matches
type_name.h
1#pragma once
2
3/* <editor-fold desc="MIT License">
4
5Copyright(c) 2018 Robert Osfield
6
7Permission 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
9The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
10
11THE 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 <cstdint>
16#include <string>
17#include <typeinfo>
18
19namespace vsg
20{
21 // clang-format off
22
23 template<typename T>
24 constexpr const char* type_name() noexcept { return typeid(T).name(); }
25
26 template<typename T>
27 constexpr const char* type_name(const T&) noexcept { return type_name<T>(); }
28
29 template<> constexpr const char* type_name<std::string>() noexcept { return "string"; }
30 template<> constexpr const char* type_name<bool>() noexcept { return "bool"; }
31 template<> constexpr const char* type_name<char>() noexcept { return "char"; }
32 template<> constexpr const char* type_name<int8_t>() noexcept { return "int8_t"; }
33 template<> constexpr const char* type_name<unsigned char>() noexcept { return "uchar"; }
34 template<> constexpr const char* type_name<short>() noexcept { return "short"; }
35 template<> constexpr const char* type_name<unsigned short>() noexcept { return "ushort"; }
36 template<> constexpr const char* type_name<int>() noexcept { return "int"; }
37 template<> constexpr const char* type_name<unsigned int>() noexcept { return "uint"; }
38 template<> constexpr const char* type_name<float>() noexcept { return "float"; }
39 template<> constexpr const char* type_name<double>() noexcept { return "double"; }
40
41 // helper define for defining the type_name() for a type within the vsg namespace.
42 #define VSG_type_name(T) \
43 template<> constexpr const char* type_name<T>() noexcept { return #T; } \
44 template<> constexpr const char* type_name<const T>() noexcept { return "const "#T; }
45
46
47 // helper define for defining the type_name() for a type in a namespace other than vsg, note must be placed in global namespace.
48 #define EVSG_type_name(T) \
49 template<> constexpr const char* vsg::type_name<T>() noexcept { return #T; } \
50 template<> constexpr const char* vsg::type_name<const T>() noexcept { return "const "#T; }
51
52 // clang-format on
53
54} // namespace vsg