From 8a659de4e5e80c0819acd24a4b0fb1659b074f3c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1=C5=A1=20Oberhuber?= <oberhuber.tomas@gmail.com> Date: Sat, 9 Feb 2019 18:21:52 +0100 Subject: [PATCH] Fixed getType to work with enum types by conversion to underlying type. --- src/TNL/param-types.h | 104 ++++++++++++++++++++++-------------------- 1 file changed, 54 insertions(+), 50 deletions(-) diff --git a/src/TNL/param-types.h b/src/TNL/param-types.h index e7552d8489..228b742793 100644 --- a/src/TNL/param-types.h +++ b/src/TNL/param-types.h @@ -11,28 +11,76 @@ #pragma once #include <vector> +#include <type_traits> #include <TNL/Experimental/Arithmetics/Real.h> #include <TNL/String.h> namespace TNL { -template< typename T > -String getType(); - namespace __getType_impl { -template< typename T > +template< typename T, + bool isEnum = std::is_enum< T >::value > struct getTypeHelper { static String get() { return T::getType(); } }; +template<> struct getTypeHelper< void, false >{ static String get() { return String( "void" ); }; }; +template<> struct getTypeHelper< bool, false >{ static String get() { return String( "bool" ); }; }; + +template<> struct getTypeHelper< char, false >{ static String get() { return String( "char" ); }; }; +template<> struct getTypeHelper< short int, false >{ static String get() { return String( "short int" ); }; }; +template<> struct getTypeHelper< int, false >{ static String get() { return String( "int" ); }; }; +template<> struct getTypeHelper< long int, false >{ static String get() { return String( "long int" ); }; }; + +template<> struct getTypeHelper< unsigned char, false >{ static String get() { return String( "unsigned char" ); }; }; +template<> struct getTypeHelper< unsigned short, false >{ static String get() { return String( "unsigned short" ); }; }; +template<> struct getTypeHelper< unsigned int, false >{ static String get() { return String( "unsigned int" ); }; }; +template<> struct getTypeHelper< unsigned long, false >{ static String get() { return String( "unsigned long" ); }; }; + +template<> struct getTypeHelper< signed char, false >{ static String get() { return String( "signed char" ); }; }; + +template<> struct getTypeHelper< float, false >{ static String get() { return String( "float" ); }; }; +template<> struct getTypeHelper< double, false >{ static String get() { return String( "double" ); }; }; +template<> struct getTypeHelper< long double, false >{ static String get() { return String( "long double" ); }; }; +template<> struct getTypeHelper< tnlFloat, false >{ static String get() { return String( "tnlFloat" ); }; }; +template<> struct getTypeHelper< tnlDouble, false >{ static String get() { return String( "tnlDouble" ); }; }; + +// const specializations +template<> struct getTypeHelper< const void, false >{ static String get() { return String( "const void" ); }; }; +template<> struct getTypeHelper< const bool, false >{ static String get() { return String( "const bool" ); }; }; + +template<> struct getTypeHelper< const char, false >{ static String get() { return String( "const char" ); }; }; +template<> struct getTypeHelper< const short int, false >{ static String get() { return String( "const short int" ); }; }; +template<> struct getTypeHelper< const int, false >{ static String get() { return String( "const int" ); }; }; +template<> struct getTypeHelper< const long int, false >{ static String get() { return String( "const long int" ); }; }; + +template<> struct getTypeHelper< const unsigned char, false >{ static String get() { return String( "const unsigned char" ); }; }; +template<> struct getTypeHelper< const unsigned short, false >{ static String get() { return String( "const unsigned short" ); }; }; +template<> struct getTypeHelper< const unsigned int, false >{ static String get() { return String( "const unsigned int" ); }; }; +template<> struct getTypeHelper< const unsigned long, false >{ static String get() { return String( "const unsigned long" ); }; }; + +template<> struct getTypeHelper< const signed char, false >{ static String get() { return String( "const signed char" ); }; }; + +template<> struct getTypeHelper< const float, false >{ static String get() { return String( "const float" ); }; }; +template<> struct getTypeHelper< const double, false >{ static String get() { return String( "const double" ); }; }; +template<> struct getTypeHelper< const long double, false >{ static String get() { return String( "const long double" ); }; }; +template<> struct getTypeHelper< const tnlFloat, false >{ static String get() { return String( "const tnlFloat" ); }; }; +template<> struct getTypeHelper< const tnlDouble, false >{ static String get() { return String( "const tnlDouble" ); }; }; + +template< typename T > +struct getTypeHelper< T, true > +{ + static String get() { return getTypeHelper< typename std::underlying_type< T >::type, false >::get(); }; +}; + // wrappers for STL containers template< typename T > -struct getTypeHelper< std::vector< T > > +struct getTypeHelper< std::vector< T >, false > { - static String get() { return String( "std::vector< " ) + TNL::getType< T >() + " >"; } + static String get() { return String( "std::vector< " ) + getTypeHelper< T >::get() + " >"; } }; } // namespace __getType_impl @@ -40,48 +88,4 @@ struct getTypeHelper< std::vector< T > > template< typename T > String getType() { return __getType_impl::getTypeHelper< T >::get(); } -// non-const specializations -template<> inline String getType< void >() { return String( "void" ); } -template<> inline String getType< bool >() { return String( "bool" ); } - -template<> inline String getType< char >() { return String( "char" ); } -template<> inline String getType< short int >() { return String( "short int" ); } -template<> inline String getType< int >() { return String( "int" ); } -template<> inline String getType< long int >() { return String( "long int" ); } - -template<> inline String getType< unsigned char >() { return String( "unsigned char" ); } -template<> inline String getType< unsigned short >() { return String( "unsigned short" ); } -template<> inline String getType< unsigned int >() { return String( "unsigned int" ); } -template<> inline String getType< unsigned long >() { return String( "unsigned long" ); } - -template<> inline String getType< signed char >() { return String( "signed char" ); } - -template<> inline String getType< float >() { return String( "float" ); } -template<> inline String getType< double >() { return String( "double" ); } -template<> inline String getType< long double >() { return String( "long double" ); } -template<> inline String getType< tnlFloat >() { return String( "tnlFloat" ); } -template<> inline String getType< tnlDouble>() { return String( "tnlDouble" ); } - -// const specializations -template<> inline String getType< const void >() { return String( "const void" ); } -template<> inline String getType< const bool >() { return String( "const bool" ); } - -template<> inline String getType< const char >() { return String( "const char" ); } -template<> inline String getType< const short int >() { return String( "const short int" ); } -template<> inline String getType< const int >() { return String( "const int" ); } -template<> inline String getType< const long int >() { return String( "const long int" ); } - -template<> inline String getType< const unsigned char >() { return String( "const unsigned char" ); } -template<> inline String getType< const unsigned short >() { return String( "const unsigned short" ); } -template<> inline String getType< const unsigned int >() { return String( "const unsigned int" ); } -template<> inline String getType< const unsigned long >() { return String( "const unsigned long" ); } - -template<> inline String getType< const signed char >() { return String( "const signed char" ); } - -template<> inline String getType< const float >() { return String( "const float" ); } -template<> inline String getType< const double >() { return String( "const double" ); } -template<> inline String getType< const long double >() { return String( "const long double" ); } -template<> inline String getType< const tnlFloat >() { return String( "const tnlFloat" ); } -template<> inline String getType< const tnlDouble>() { return String( "const tnlDouble" ); } - } // namespace TNL -- GitLab