Implement the type_name() function. Only tested on gcc 5.1
Add Sprout library.
This commit is contained in:
parent
6a39b82e5e
commit
f1bcf8674d
14 changed files with 141 additions and 38 deletions
|
@ -1,19 +0,0 @@
|
|||
namespace dk {
|
||||
template <typename T, uint32_t D>
|
||||
inline HashType make_signature_hash() {
|
||||
#if defined(IS_PRETTY_FUNC_CONSTEXPR)
|
||||
//static_assert(dk::tiger("a", 1, 0x01).a == 0xABF87E2EEFFBBE77ULL, "Bug in tiger hash");
|
||||
//static_assert(dk::tiger("message digest", 14, 0x01).a == 0x951A2078CBF881D9ULL, "Bug in tiger hash");
|
||||
|
||||
constexpr bt::string<sizeof(__PRETTY_FUNCTION__)-1> func_pretty(__PRETTY_FUNCTION__);
|
||||
// set padding to 0x80 for tiger V2
|
||||
constexpr HashType retval = dk::tiger(func_pretty.data(), func_pretty.size(), 0x01);
|
||||
|
||||
return retval;
|
||||
#else
|
||||
const char* const pf = __PRETTY_FUNCTION__;
|
||||
const std::size_t len = sizeof(__PRETTY_FUNCTION__) - 1;
|
||||
return implem::hash_string(pf, len);
|
||||
#endif
|
||||
}
|
||||
} //namespace dk
|
|
@ -1,7 +1,7 @@
|
|||
#ifndef id1E6CCE44307549A9B6C9E4E5923AC002
|
||||
#define id1E6CCE44307549A9B6C9E4E5923AC002
|
||||
|
||||
#include "doorkeeper/helpers/hashing.hpp"
|
||||
//#include "doorkeeper/helpers/hashing.hpp"
|
||||
#include "doorkeeper/implem/compatibility.h"
|
||||
#include <cstdint>
|
||||
#include <ciso646>
|
||||
|
|
71
include/doorkeeper/implem/typename.inl
Normal file
71
include/doorkeeper/implem/typename.inl
Normal file
|
@ -0,0 +1,71 @@
|
|||
|
||||
namespace dk {
|
||||
template <typename T>
|
||||
#if defined(IS_PRETTY_FUNC_CONSTEXPR)
|
||||
constexpr
|
||||
#endif
|
||||
inline HashType type_name_hash() {
|
||||
#if defined(IS_PRETTY_FUNC_CONSTEXPR)
|
||||
//static_assert(dk::tiger("a", 1, 0x01).a == 0xABF87E2EEFFBBE77ULL, "Bug in tiger hash");
|
||||
//static_assert(dk::tiger("message digest", 14, 0x01).a == 0x951A2078CBF881D9ULL, "Bug in tiger hash");
|
||||
|
||||
// set padding to 0x80 for tiger V2
|
||||
return dk::tiger(type_name<T>().data(), type_name<T>().size(), 0x01);
|
||||
#else
|
||||
const auto retstring = type_name<T>();
|
||||
return implem::hash_string(retstring.data(), retstring.size());
|
||||
#endif
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
#if defined(IS_PRETTY_FUNC_CONSTEXPR)
|
||||
constexpr inline sprout::string<implem::type_name_len<T>()> type_name()
|
||||
#else
|
||||
inline std::string type_name()
|
||||
#endif
|
||||
{
|
||||
#if defined(IS_PRETTY_FUNC_CONSTEXPR)
|
||||
# if defined(__GNUC__)
|
||||
typedef sprout::string<implem::type_name_info<T>().len> sproutstring;
|
||||
typedef sprout::string<implem::type_name_len<T>()> sproutstringret;
|
||||
|
||||
return sproutstringret(
|
||||
implem::type_name_info<T>().str + sproutstring(implem::type_name_info<T>().str).find(
|
||||
'=',
|
||||
sproutstring(implem::type_name_info<T>().str).find('[')
|
||||
) + 2,
|
||||
implem::type_name_len<T>() - 1
|
||||
);
|
||||
# else
|
||||
# error "not implemented"
|
||||
# endif
|
||||
#else
|
||||
# error "not implemented"
|
||||
const char* const pf = __PRETTY_FUNCTION__;
|
||||
const std::size_t len = sizeof(__PRETTY_FUNCTION__) - 1;
|
||||
#endif
|
||||
}
|
||||
|
||||
namespace implem {
|
||||
template <typename T>
|
||||
constexpr type_name_info<T>::type_name_info() :
|
||||
len(sizeof(__PRETTY_FUNCTION__)),
|
||||
str(__PRETTY_FUNCTION__)
|
||||
{
|
||||
}
|
||||
|
||||
#if defined(IS_PRETTY_FUNC_CONSTEXPR)
|
||||
template <typename T>
|
||||
constexpr std::size_t type_name_len() {
|
||||
typedef sprout::string<implem::type_name_info<T>().len> sproutstring;
|
||||
|
||||
# if defined(__GNUC__)
|
||||
return type_name_info<T>().len - sproutstring(
|
||||
implem::type_name_info<T>().str).find('=', sproutstring(implem::type_name_info<T>().str).find('[')) - 3;
|
||||
# else
|
||||
# error "not implemented"
|
||||
# endif
|
||||
}
|
||||
#endif
|
||||
} //namespace implem
|
||||
} //namespace dk
|
Loading…
Add table
Add a link
Reference in a new issue