主要内容是更加规范的编译期行为与基于继承的Object反射

This commit is contained in:
2025-08-21 15:41:58 +08:00
parent 32e099b621
commit 004f2f3367
10 changed files with 1217 additions and 0 deletions

103
detail/CP/CHash.hpp Normal file
View File

@@ -0,0 +1,103 @@
#pragma once
#ifndef __FILE_Detail_CP_CHash_Hpp
#define __FILE_Detail_CP_CHash_Hpp
//
// Hash functions for common types.
//
inline uint32_t Hash(const uint8_t A)
{
return A;
}
inline uint32_t Hash(const int8_t A)
{
return A;
}
inline uint32_t Hash(const uint16_t A)
{
return A;
}
inline uint32_t Hash(const int16_t A)
{
return A;
}
inline uint32_t Hash(const int32_t A)
{
return A;
}
inline uint32_t Hash(const uint32_t A)
{
return A;
}
inline uint32_t Hash(const uint64_t A)
{
return (uint32_t)A + ((uint32_t)(A >> 32) * 23);
}
inline uint32_t Hash(const int64_t A)
{
return (uint32_t)A + ((uint32_t)(A >> 32) * 23);
}
constexpr uint32_t CHash(const uint8_t A)
{
return A;
}
constexpr uint32_t CHash(const int8_t A)
{
return A;
}
constexpr uint32_t CHash(const uint16_t A)
{
return A;
}
constexpr uint32_t CHash(const int16_t A)
{
return A;
}
constexpr uint32_t CHash(const int32_t A)
{
return A;
}
constexpr uint32_t CHash(const uint32_t A)
{
return A;
}
constexpr uint32_t CHash(const uint64_t A)
{
return (uint32_t)A + ((uint32_t)(A >> 32) * 23);
}
constexpr uint32_t CHash(const int64_t A)
{
return (uint32_t)A + ((uint32_t)(A >> 32) * 23);
}
constexpr uint32_t CHash(const char* str, uint32_t hash = 5381)
{
return *str == '\0' ? hash : CHash(str + 1, ((hash << 5) + hash) + *str);
}
constexpr uint32_t CHash(std::string_view str, uint32_t hash = 5381)
{
for (size_t i = 0; i < str.length(); ++i)
{
hash = ((hash << 5) + hash) + str[i];
}
return hash;
}
#endif // !__FILE_Detail_CP_CHash_Hpp