Created
July 26, 2016 13:05
-
-
Save Redchards/71de32c22cc8b752ee71e49159532a92 to your computer and use it in GitHub Desktop.
Simple compile time type information.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #ifndef CTTI_HXX | |
| #define CTTI_HXX | |
| #include <ConstString.hxx> | |
| #include <Platform.hxx> | |
| #include <StaticString.hxx> | |
| template<class T> | |
| class CTTI | |
| { | |
| #if COMPILER == CLANG_COMPILER | |
| static constexpr ConstString exprBegin = "static auto CTTI<"; | |
| static constexpr ConstString exprMiddle = " >::getTypeName() [T = "; | |
| static constexpr ConstString exprEnd = "]"; | |
| #elif COMPILER == GCC_COMPILER | |
| static constexpr ConstString exprBegin = "static constexpr auto CTTI<T>::getTypeName() [with T = "; | |
| static constexpr ConstString exprEnd = "]"; | |
| #elif COMPILER == MSVC_COMPILER | |
| // TODO | |
| #error "Not implemented yet !" | |
| #else | |
| #error "Compiler not supported !" | |
| #endif | |
| public: | |
| static constexpr auto getTypeName() | |
| { | |
| constexpr ConstString functionName = FUNCTION; | |
| #if COMPILER == CLANG_COMPILER | |
| constexpr size_t typeNameLength = (functionName.size() - (exprBegin.size() + exprMiddle.size() + exprEnd.size())) / 2; | |
| #else | |
| constexpr size_t typeNameLength = (functionName.size() - (exprBegin.size() + exprEnd.size())); | |
| #endif | |
| return StaticString<typeNameLength>{ functionName.begin() + exprBegin.size(), functionName.begin() + exprBegin.size() + typeNameLength }; | |
| } | |
| }; | |
| template<class T> | |
| constexpr ConstString CTTI<T>::exprBegin; | |
| #if COMPILER == CLANG_COMPILER | |
| template<class T> | |
| constexpr ConstString CTTI<T>::exprMiddle; | |
| #endif | |
| template<class T> | |
| constexpr ConstString CTTI<T>::exprEnd; | |
| #endif // CTTI_HXX |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment