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
|
@ -3,7 +3,7 @@
|
|||
|
||||
#include "doorkeeper/implem/maptypes.hpp"
|
||||
#include "doorkeeper/primitivetypes.hpp"
|
||||
#include "doorkeeper/helpers/hashing.hpp"
|
||||
#include "doorkeeper/helpers/typename.hpp"
|
||||
#include "doorkeeper/implem/coords_utils.hpp"
|
||||
#include <cstdint>
|
||||
#include <vector>
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
|
||||
#include "doorkeeper/components/tyler.hpp"
|
||||
#include "doorkeeper/components/basemapsource.hpp"
|
||||
#include "doorkeeper/helpers/hashing.hpp"
|
||||
#include "doorkeeper/helpers/typename.hpp"
|
||||
#include "doorkeeper/components/exception.hpp"
|
||||
#include <cstdint>
|
||||
#include <utility>
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
#ifndef id4E5F8A0ABA6047BA988D512351B9DD2D
|
||||
#define id4E5F8A0ABA6047BA988D512351B9DD2D
|
||||
#ifndef id3A8D22AD652142C9A44142EC942E4482
|
||||
#define id3A8D22AD652142C9A44142EC942E4482
|
||||
|
||||
#include "doorkeeper/implem/doorkeeper_conf.h"
|
||||
|
||||
|
@ -16,7 +16,7 @@
|
|||
#endif
|
||||
|
||||
#if defined(IS_PRETTY_FUNC_CONSTEXPR)
|
||||
# include "doorkeeper/implem/string_bt.hpp"
|
||||
# include "sprout/string.hpp"
|
||||
# include "doorkeeper/implem/tiger_bt.hpp"
|
||||
# include <stdexcept>
|
||||
#endif
|
||||
|
@ -35,15 +35,38 @@ namespace dk {
|
|||
|
||||
bool operator< ( const HashType& parL, const HashType& parR );
|
||||
|
||||
template <typename T, uint32_t D>
|
||||
HashType make_signature_hash ( void ) a_pure;
|
||||
|
||||
namespace implem {
|
||||
HashType hash_string ( const char* parString, std::size_t parLen ) a_pure;
|
||||
|
||||
#if defined(IS_PRETTY_FUNC_CONSTEXPR)
|
||||
template <typename T>
|
||||
struct type_name_info {
|
||||
constexpr type_name_info ( void );
|
||||
|
||||
const std::size_t len;
|
||||
const char* const str;
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
constexpr std::size_t type_name_len ( void ) a_pure;
|
||||
#endif
|
||||
} //namespace implem
|
||||
|
||||
template <typename T>
|
||||
#if defined(IS_PRETTY_FUNC_CONSTEXPR)
|
||||
constexpr
|
||||
#endif
|
||||
HashType type_name_hash ( void ) a_pure;
|
||||
|
||||
template <typename T>
|
||||
#if defined(IS_PRETTY_FUNC_CONSTEXPR)
|
||||
constexpr sprout::string<implem::type_name_len<T>()> type_name ( void ) a_pure;
|
||||
#else
|
||||
std::string type_name ( void ) a_pure;
|
||||
#endif
|
||||
} //namespace dk
|
||||
|
||||
#include "doorkeeper/implem/hashing.inl"
|
||||
#include "doorkeeper/implem/typename.inl"
|
||||
|
||||
#if defined(IS_PRETTY_FUNC_CONSTEXPR)
|
||||
# undef IS_PRETTY_FUNC_CONSTEXPR
|
|
@ -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