[+] Initial Commit
This commit is contained in:
commit
d87d88faaf
31
.gitignore
vendored
Normal file
31
.gitignore
vendored
Normal file
@ -0,0 +1,31 @@
|
|||||||
|
Build_CompilerWorkingDirectory/*
|
||||||
|
Build_Developers/*
|
||||||
|
Build_Ship/*
|
||||||
|
Build_Internal/*
|
||||||
|
Build_Develop/*
|
||||||
|
Build_Stage/*
|
||||||
|
Build_Ship/*
|
||||||
|
Build_Workspace/*
|
||||||
|
*.vcxproj
|
||||||
|
*.vcxproj.filters
|
||||||
|
*.vcxproj.user
|
||||||
|
*.licenseheader
|
||||||
|
*.dll
|
||||||
|
*.exe
|
||||||
|
*.obj
|
||||||
|
*.so
|
||||||
|
*.dynlib
|
||||||
|
*.lib
|
||||||
|
*.d
|
||||||
|
*.o
|
||||||
|
*.a
|
||||||
|
*.la
|
||||||
|
*.out
|
||||||
|
.vs
|
||||||
|
compile_flags.txt
|
||||||
|
*.mk
|
||||||
|
*.project
|
||||||
|
*cmake
|
||||||
|
.intellij
|
||||||
|
.clion
|
||||||
|
Makefile
|
6
Aurora.json
Normal file
6
Aurora.json
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
{
|
||||||
|
"name":" AuroraEnum",
|
||||||
|
"type": "generic",
|
||||||
|
"include": "Include",
|
||||||
|
"noLink": true
|
||||||
|
}
|
51
Include/AuroraEnum.hpp
Normal file
51
Include/AuroraEnum.hpp
Normal file
@ -0,0 +1,51 @@
|
|||||||
|
/***
|
||||||
|
Copyright (C) 2021 J Reece Wilson (a/k/a "Reece"). All rights reserved.
|
||||||
|
|
||||||
|
File: AuroraEnum.hpp
|
||||||
|
Date: 2021-10-28
|
||||||
|
Author: Reece
|
||||||
|
***/
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
///////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
/// Utilities
|
||||||
|
///////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
/// @hideinitializer
|
||||||
|
#define AUE_BRACKET_SCOPE(...) __VA_ARGS__
|
||||||
|
|
||||||
|
/// @hideinitializer
|
||||||
|
#define AUE_STRIP_BRACKETS_(X) X
|
||||||
|
|
||||||
|
/// @hideinitializer
|
||||||
|
#define AUE_STRIP_BRACKETS(X) AUE_STRIP_BRACKETS_(AUE_BRACKET_SCOPE X)
|
||||||
|
|
||||||
|
/// @hideinitializer
|
||||||
|
#define AUE_EMIT_ARRAY(val) val,
|
||||||
|
|
||||||
|
/// @hideinitializer
|
||||||
|
#define AUE_EMIT_A(val) #val
|
||||||
|
|
||||||
|
/// @hideinitializer
|
||||||
|
#define AUE_EMIT_B(val) , #val
|
||||||
|
|
||||||
|
/// @hideinitializer
|
||||||
|
#define AUE_EMIT_PAIRNAME(name, val) {#val, name::val},
|
||||||
|
|
||||||
|
/// @hideinitializer
|
||||||
|
#define AUE_EMIT_CALL(name, val) consumer(name::val);
|
||||||
|
|
||||||
|
/// @hideinitializer
|
||||||
|
#define AUE_EMIT_CHECK(name, val) if (codename == #val) {return name::val;}
|
||||||
|
|
||||||
|
///////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
// API
|
||||||
|
///////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
#define AUE_DEFINE(name, vals) enum class name { AU_FOR_EACH(AUE_EMIT_ARRAY, AUE_STRIP_BRACKETS(vals)) kEnumCount }; \
|
||||||
|
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} }; \
|
||||||
|
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 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)) }
|
40
README.md
Normal file
40
README.md
Normal file
@ -0,0 +1,40 @@
|
|||||||
|
## Aurora Enum
|
||||||
|
|
||||||
|
[TODO]
|
||||||
|
|
||||||
|
## Example
|
||||||
|
|
||||||
|
```c++
|
||||||
|
#define AUE_DEFINE(name, enumerations)
|
||||||
|
|
||||||
|
AUE_DEFINE(EMyTestEnum, (
|
||||||
|
eValueA,
|
||||||
|
eValueB,
|
||||||
|
eValueC,
|
||||||
|
eValueD
|
||||||
|
));
|
||||||
|
|
||||||
|
static void TestAUE()
|
||||||
|
{
|
||||||
|
EMyTestEnum referenceValue = EMyTestEnum::eValueB;
|
||||||
|
|
||||||
|
// Convert the index to a string safely O(1)
|
||||||
|
const AuString &string = EMyTestEnumToString(referenceValue);
|
||||||
|
|
||||||
|
// Lookup O(n)
|
||||||
|
EMyTestEnum backAgain = EMyTestEnumFromString(string);
|
||||||
|
|
||||||
|
// Lookup using a hash table
|
||||||
|
EMyTestEnum fromHashTable = EMyTestEnumFromHashString(string);
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
SysAssert(backAgain == referenceValue);
|
||||||
|
SysAssert(fromHashTable == referenceValue);
|
||||||
|
|
||||||
|
// And iteration for fun
|
||||||
|
EMyTestEnumForEach([](EMyTestEnum e)
|
||||||
|
{
|
||||||
|
LogDbg(EMyTestEnumToString(e));
|
||||||
|
});
|
||||||
|
}
|
||||||
|
```
|
Loading…
Reference in New Issue
Block a user