Use build time strings for pretty function names if supported.
This doesn't really do much until I have build time hashing.
This commit is contained in:
parent
fd8a1cbabc
commit
dba88117e4
6 changed files with 174 additions and 10 deletions
|
@ -1,15 +1,13 @@
|
|||
namespace dk {
|
||||
template <typename T, uint32_t D>
|
||||
HashType make_signature_hash() {
|
||||
#if defined(__GNUC__)
|
||||
//TODO: use bt::string if possible
|
||||
#if IS_PRETTY_FUNC_CONSTEXPR
|
||||
constexpr bt::string<sizeof(__PRETTY_FUNCTION__)-1> func_pretty(__PRETTY_FUNCTION__);
|
||||
return implem::hash_string(func_pretty.data(), func_pretty.size());
|
||||
#else
|
||||
const char* const pf = __PRETTY_FUNCTION__;
|
||||
const std::size_t len = sizeof(__PRETTY_FUNCTION__) - 1;
|
||||
//constexpr bt::string<sizeof(__PRETTY_FUNCTION__)-1> func_pretty(pf);
|
||||
#else
|
||||
# error "Unknown compiler"
|
||||
#endif
|
||||
//return implem::hash_string(func_pretty.data(), func_pretty.size());
|
||||
return implem::hash_string(pf, len);
|
||||
#endif
|
||||
}
|
||||
} //namespace dk
|
||||
|
|
31
include/doorkeeper/implem/sequence_bt.hpp
Normal file
31
include/doorkeeper/implem/sequence_bt.hpp
Normal file
|
@ -0,0 +1,31 @@
|
|||
#ifndef id4FAEF395B9ED47CB9D6B50B54C9A289A
|
||||
#define id4FAEF395B9ED47CB9D6B50B54C9A289A
|
||||
|
||||
#include <cstddef>
|
||||
|
||||
namespace dk {
|
||||
namespace bt {
|
||||
template <std::size_t... I>
|
||||
struct index_seq {
|
||||
};
|
||||
|
||||
namespace implem {
|
||||
template <std::size_t MIN, std::size_t MAX, std::size_t... I>
|
||||
struct range_builder;
|
||||
|
||||
template <std::size_t MIN, std::size_t... I>
|
||||
struct range_builder<MIN, MIN, I...> {
|
||||
typedef index_seq<I...> type;
|
||||
};
|
||||
|
||||
template <std::size_t MIN, std::size_t N, std::size_t... I>
|
||||
struct range_builder : public range_builder<MIN, N - 1, N - 1, I...> {
|
||||
};
|
||||
} //namespace implem
|
||||
|
||||
template <std::size_t MIN, std::size_t MAX>
|
||||
using index_range = typename implem::range_builder<MIN, MAX>::type;
|
||||
} //namespace bt
|
||||
} //namespace dk
|
||||
|
||||
#endif
|
95
include/doorkeeper/implem/string_bt.hpp
Normal file
95
include/doorkeeper/implem/string_bt.hpp
Normal file
|
@ -0,0 +1,95 @@
|
|||
#ifndef id170B0E6C34D14EBA9B92A35977BDBFB3
|
||||
#define id170B0E6C34D14EBA9B92A35977BDBFB3
|
||||
|
||||
#include "doorkeeper/implem/sequence_bt.hpp"
|
||||
#include <cstddef>
|
||||
#include <iostream>
|
||||
#include <stdexcept>
|
||||
|
||||
namespace dk {
|
||||
namespace bt {
|
||||
template <std::size_t S>
|
||||
class string;
|
||||
|
||||
template <std::size_t S>
|
||||
std::ostream& operator<< ( std::ostream& parStream, const string<S>& parString );
|
||||
|
||||
template <std::size_t S>
|
||||
class string {
|
||||
public:
|
||||
friend std::ostream& operator<< <>( std::ostream& parStream, const string<S>& parString );
|
||||
constexpr string ( const char* parString );
|
||||
|
||||
constexpr std::size_t size ( void ) const { return S - 1; }
|
||||
template <std::size_t S2>
|
||||
constexpr string<S + S2 - 1> operator+ ( const string<S2>& parOther ) const;
|
||||
constexpr char operator[] ( std::size_t parIndex ) const;
|
||||
|
||||
template <typename... Args>
|
||||
constexpr string ( Args... );
|
||||
|
||||
constexpr const char (&data_arr() const)[S] { return m_data; }
|
||||
constexpr const char* data() const { return m_data; }
|
||||
|
||||
private:
|
||||
template <std::size_t... I>
|
||||
constexpr string ( const index_seq<I...>&, const char* parString );
|
||||
|
||||
const char m_data[S];
|
||||
};
|
||||
|
||||
namespace implem {
|
||||
template <std::size_t S, std::size_t S2, std::size_t... I>
|
||||
constexpr string<S + S2 - 1> concat ( const index_seq<I...>&, const string<S>& parLeft, const string<S2>& parRight ) {
|
||||
return string<S + S2 - 1>(
|
||||
(I < S - 1 ? parLeft[I] : (I < S + S2 - 2 ? parRight[I - (S - 1)] : '\0'))...
|
||||
);
|
||||
}
|
||||
|
||||
} //namespace implem
|
||||
|
||||
template <std::size_t S>
|
||||
template <std::size_t... I>
|
||||
constexpr string<S>::string (const index_seq<I...>&, const char* parString) :
|
||||
m_data{parString[I]...}
|
||||
{
|
||||
}
|
||||
|
||||
template <std::size_t S>
|
||||
inline constexpr string<S>::string (const char* parString) :
|
||||
string(index_range<0, S>(), parString)
|
||||
{
|
||||
}
|
||||
|
||||
template <std::size_t S>
|
||||
template <typename... Args>
|
||||
inline constexpr string<S>::string (Args... parArgs) :
|
||||
m_data{parArgs...}
|
||||
{
|
||||
}
|
||||
|
||||
template <std::size_t S>
|
||||
template <std::size_t S2>
|
||||
constexpr inline string<S + S2 - 1> string<S>::operator+ (const string<S2>& parOther) const {
|
||||
return implem::concat(index_range<0, S + S2 - 1>(), string<S>(m_data), parOther);
|
||||
}
|
||||
|
||||
template <std::size_t S>
|
||||
inline std::ostream& operator<< (std::ostream& parStream, const string<S>& parString) {
|
||||
parStream << parString.m_data;
|
||||
return parStream;
|
||||
}
|
||||
|
||||
template <std::size_t S>
|
||||
constexpr char string<S>::operator[] (std::size_t parIndex) const {
|
||||
return (parIndex < S ? m_data[parIndex] : throw std::out_of_range(""));
|
||||
}
|
||||
|
||||
template <std::size_t S>
|
||||
constexpr string<S> make_string (const char (&parData)[S]) {
|
||||
return string<S>(parData);
|
||||
}
|
||||
} //namespace bt
|
||||
} //namespace dk
|
||||
|
||||
#endif
|
Loading…
Add table
Add a link
Reference in a new issue