Remove AuTryFind semantic, added AuString typedef, added AuHashMap typedef

This commit is contained in:
Reece Wilson 2021-10-28 21:15:29 +00:00
parent 80b2b7456b
commit eff2dfd500

View File

@ -7,6 +7,21 @@
***/ ***/
#pragma once #pragma once
#if defined(AUE_OUT_OF_ECOSYSTEM)
#if !defined(AU_AuHashMap)
#define AU_AuHashMap
template<typename T, typename Z>
using AuHashMap = std::unordered_map<T, Z>;
#endif
#if !defined(AU_AuString)
#define AU_AuString
using AuString = std::string;
#endif
#endif
/////////////////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////////////
/// Utilities /// Utilities
/////////////////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////////////
@ -46,6 +61,6 @@
static inline const AuString k ## name ## ToString[static_cast<int>(name::kEnumCount)] = {AU_FOR_EACH_FIRST(AUE_EMIT_A, AUE_EMIT_B, AUE_STRIP_BRACKETS(vals)) }; \ static inline const AuString k ## name ## ToString[static_cast<int>(name::kEnumCount)] = {AU_FOR_EACH_FIRST(AUE_EMIT_A, AUE_EMIT_B, AUE_STRIP_BRACKETS(vals)) }; \
inline const AuHashMap<AuString, name> kName ## FromString = { AU_FOR_EACH_THAT(AUE_EMIT_PAIRNAME, name, AUE_STRIP_BRACKETS(vals)) {"kEnumCount", name::kEnumCount} }; \ inline const AuHashMap<AuString, name> kName ## FromString = { AU_FOR_EACH_THAT(AUE_EMIT_PAIRNAME, name, AUE_STRIP_BRACKETS(vals)) {"kEnumCount", name::kEnumCount} }; \
static inline name name ## FromString (const AuString &codename) { AU_FOR_EACH_THAT(AUE_EMIT_CHECK, name, AUE_STRIP_BRACKETS(vals)) return name::kEnumCount; } \ static inline name name ## FromString (const AuString &codename) { AU_FOR_EACH_THAT(AUE_EMIT_CHECK, name, AUE_STRIP_BRACKETS(vals)) return name::kEnumCount; } \
static inline name name ## FromHashString(const AuString &codename) { const name *val; if (!AuTryFind(kName ## FromString, codename, val)) return name::kEnumCount; return *val; } \ static inline name name ## FromHashString(const AuString &codename) { auto itr = kName ## FromString.find(codename); if (itr == kName ## FromString.end()) return name::kEnumCount; return itr->second; } \
static inline const AuString & name ## ToString(name val) { static const AuString invalid = "kEnumCount"; if (static_cast<AuUInt>(val) >= static_cast<int>(name::kEnumCount)) return invalid; return k ## name ## ToString[static_cast<int>(val)]; } \ static inline const AuString & name ## ToString(name val) { static const AuString invalid = "kEnumCount"; if (static_cast<AuUInt>(val) >= static_cast<int>(name::kEnumCount)) return invalid; return k ## name ## ToString[static_cast<int>(val)]; } \
static inline void name ## ForEach(const AuConsumer<name> &consumer) { AU_FOR_EACH_THAT(AUE_EMIT_CALL, name, AUE_STRIP_BRACKETS(vals)) } static inline void name ## ForEach(const AuConsumer<name> &consumer) { AU_FOR_EACH_THAT(AUE_EMIT_CALL, name, AUE_STRIP_BRACKETS(vals)) }