diff --git a/codegen.pri b/codegen.pri index 1a8dba3..80749f6 100644 --- a/codegen.pri +++ b/codegen.pri @@ -1,9 +1,10 @@ -# Define CODEGEN_OUT_PATH and CODEGEN_SRC_PATH, then include this file in a qmake project +# Define CODEGEN_DIR, CODEGEN_OUT_PATH and CODEGEN_SRC_PATH, then include this file in a qmake project # The include must be at the bottom of the file (after SOURCES, HEADERS, and INCLUDEPATH are all fully initialized) Codegen.name = Codegen Codegen.input = SOURCES Codegen.output = $$CODEGEN_OUT_PATH Codegen.variable_out = SOURCES -Codegen.commands = python $$EXTERNALS_DIR/CodeGen/codegen.py -pwd $$CODEGEN_SRC_PATH -cmdinput -include $$INCLUDEPATH -sourcefiles $$SOURCES $$HEADERS -o $$CODEGEN_OUT_PATH +Codegen.commands = python $$CODEGEN_DIR/codegen.py -pwd $$CODEGEN_SRC_PATH -cmdinput -include $$INCLUDEPATH -sourcefiles $$SOURCES $$HEADERS -o $$CODEGEN_OUT_PATH Codegen.CONFIG += target_predeps combine QMAKE_EXTRA_COMPILERS += Codegen +DEFINES += WITH_CODEGEN diff --git a/codegen.py b/codegen.py index 5e6c579..517cb7a 100644 --- a/codegen.py +++ b/codegen.py @@ -303,6 +303,7 @@ def RunCodegen(): SourceFiles += glob.glob("%s\\**\\*.h" % SourceRoot, recursive=True) OutCodegenSource = OutputCppSource + print("Codegen Input: " + " ".join(SourceFiles)) print("Build Dir: " + ExportPath) # Clang index diff --git a/include/codegen/EnumReflection.h b/include/codegen/EnumReflection.h index 6109303..456871b 100644 --- a/include/codegen/EnumReflection.h +++ b/include/codegen/EnumReflection.h @@ -4,9 +4,9 @@ #include #include #include -#include +#include -typedef std::unordered_map CEnumNameMap; +typedef std::map CEnumNameMap; /** Provides runtime information about enum types */ template::value >::type> @@ -65,9 +65,33 @@ public: */ inline static T ErrorValue() { - return skErrorValue; + return (T) skErrorValue; } + /** Iterator class for iterating through all possible enum values */ + class CIterator + { + CEnumNameMap::const_iterator mInternalIterator; + + public: + CIterator() + { + mInternalIterator = skNameMap.cbegin(); + } + + inline T Value() const { return (T) mInternalIterator->first; } + inline const char* Name() const { return mInternalIterator->second; } + inline operator bool() const { return mInternalIterator != skNameMap.cend(); } + inline CIterator& operator++() { mInternalIterator++; return *this; } + inline CIterator operator++(int){ CIterator RetV = *this; mInternalIterator++; return RetV; } + }; }; +/** Easier accessor function */ +template +inline const char* EnumValueName(T InEnum) +{ + return TEnumReflection::ConvertValueToString(InEnum); +} + #endif