finish enum to string

This commit is contained in:
yyc12345 2023-02-09 14:12:02 +08:00
parent b8da0a802e
commit 7fe2bd8f5c
4 changed files with 111 additions and 7 deletions

View File

@ -6,9 +6,9 @@ def RemoveAnnotation(strl: str) -> str:
def Underline2Camel(orig: str) -> str: def Underline2Camel(orig: str) -> str:
return ''.join(map( return ''.join(map(
lambda mixed: mixed[-1].upper() if mixed[0] == '_' else mixed[-1].lower(), lambda strl: strl[0].upper() + strl[1:].lower(),
((('_' if idx == 0 else orig[idx - 1]), c) for idx, c in enumerate(orig)) orig.split('_')
)).replace('_', '') ))
class EnumEntry(): class EnumEntry():
def __init__(self, name: str, val: str): def __init__(self, name: str, val: str):
@ -21,6 +21,7 @@ class EnumEntry():
class EnumBody(): class EnumBody():
def __init__(self, name: str, is_flag: bool): def __init__(self, name: str, is_flag: bool):
self.name: str = name self.name: str = name
self.camel_name: str = Underline2Camel(name)
self.is_flag: bool = is_flag self.is_flag: bool = is_flag
self.entries: list[EnumEntry] = [] self.entries: list[EnumEntry] = []
def __repr__(self) -> str: def __repr__(self) -> str:
@ -72,15 +73,30 @@ with open('dest/CKMISC.txt', 'w', encoding='utf-8') as fw:
fw.write('\n') fw.write('\n')
# write vector # write decl
fw.write('namespace EnumDesc {\n')
for item in full_enum: for item in full_enum:
fw.write('static const std::array<std::pair<LibCmo::{}, const char*>, {}> _{} {{\n'.format( fw.write('extern const EnumDescPairArray<LibCmo::{}> {};\n'.format(
item.name, len(item.entries), Underline2Camel(item.name) item.name, item.name
))
fw.write('}')
fw.write('\n')
# write vector
fw.write('namespace EnumDesc {\n')
for item in full_enum:
fw.write('const EnumDescPairArray<LibCmo::{}> {} {{\n'.format(
item.name, item.name
)) ))
fw.write(',\n'.join(map( fw.write(',\n'.join(map(
lambda x: '{{ LibCmo::{}, "{}" }}'.format(x.name, x.name), lambda x: '{{ LibCmo::{}::{}, "{}" }}'.format(item.name, x.name, x.name),
item.entries item.entries
))) )))
fw.write('\n};\n') fw.write('\n};\n')
fw.write('}')
fw.write('\n')
fw.close() fw.close()

View File

@ -134,5 +134,31 @@ namespace LibCmo {
CKERR_INVALIDANIMATION = -123 CKERR_INVALIDANIMATION = -123
}; };
enum class CK_FILE_WRITEMODE : int32_t {
CKFILE_UNCOMPRESSED = 0,
CKFILE_CHUNKCOMPRESSED_OLD = 1,
CKFILE_EXTERNALTEXTURES_OLD = 2,
CKFILE_FORVIEWER = 4,
CKFILE_WHOLECOMPRESSED = 8
};
enum class CK_LOAD_FLAGS : int32_t {
CK_LOAD_ANIMATION = 1 << 0,
CK_LOAD_GEOMETRY = 1 << 1,
CK_LOAD_DEFAULT = CK_LOAD_GEOMETRY | CK_LOAD_ANIMATION,
CK_LOAD_ASCHARACTER = 1 << 2,
CK_LOAD_DODIALOG = 1 << 3,
CK_LOAD_AS_DYNAMIC_OBJECT = 1 << 4,
CK_LOAD_AUTOMATICMODE = 1 << 5,
CK_LOAD_CHECKDUPLICATES = 1 << 6,
CK_LOAD_CHECKDEPENDENCIES = 1 << 7,
CK_LOAD_ONLYBEHAVIORS = 1 << 8
};
enum class CK_FO_OPTIONS : int32_t {
CK_FO_DEFAULT = 0,
CK_FO_RENAMEOBJECT,
CK_FO_REPLACEOBJECT,
CK_FO_DONTLOADOBJECT
};
} }

View File

@ -6,6 +6,52 @@
namespace Unvirt { namespace Unvirt {
namespace AccessibleValue { namespace AccessibleValue {
#pragma region universal enum name
namespace EnumDesc {
const EnumDescPairArray<LibCmo::CK_FILE_WRITEMODE> CK_FILE_WRITEMODE{
{ LibCmo::CK_FILE_WRITEMODE::CKFILE_UNCOMPRESSED, "CKFILE_UNCOMPRESSED" },
{ LibCmo::CK_FILE_WRITEMODE::CKFILE_CHUNKCOMPRESSED_OLD, "CKFILE_CHUNKCOMPRESSED_OLD" },
{ LibCmo::CK_FILE_WRITEMODE::CKFILE_EXTERNALTEXTURES_OLD, "CKFILE_EXTERNALTEXTURES_OLD" },
{ LibCmo::CK_FILE_WRITEMODE::CKFILE_FORVIEWER, "CKFILE_FORVIEWER" },
{ LibCmo::CK_FILE_WRITEMODE::CKFILE_WHOLECOMPRESSED, "CKFILE_WHOLECOMPRESSED" }
};
const EnumDescPairArray<LibCmo::CK_LOAD_FLAGS> CK_LOAD_FLAGS{
{ LibCmo::CK_LOAD_FLAGS::CK_LOAD_ANIMATION, "CK_LOAD_ANIMATION" },
{ LibCmo::CK_LOAD_FLAGS::CK_LOAD_GEOMETRY, "CK_LOAD_GEOMETRY" },
{ LibCmo::CK_LOAD_FLAGS::CK_LOAD_DEFAULT, "CK_LOAD_DEFAULT" },
{ LibCmo::CK_LOAD_FLAGS::CK_LOAD_ASCHARACTER, "CK_LOAD_ASCHARACTER" },
{ LibCmo::CK_LOAD_FLAGS::CK_LOAD_DODIALOG, "CK_LOAD_DODIALOG" },
{ LibCmo::CK_LOAD_FLAGS::CK_LOAD_AS_DYNAMIC_OBJECT, "CK_LOAD_AS_DYNAMIC_OBJECT" },
{ LibCmo::CK_LOAD_FLAGS::CK_LOAD_AUTOMATICMODE, "CK_LOAD_AUTOMATICMODE" },
{ LibCmo::CK_LOAD_FLAGS::CK_LOAD_CHECKDUPLICATES, "CK_LOAD_CHECKDUPLICATES" },
{ LibCmo::CK_LOAD_FLAGS::CK_LOAD_CHECKDEPENDENCIES, "CK_LOAD_CHECKDEPENDENCIES" },
{ LibCmo::CK_LOAD_FLAGS::CK_LOAD_ONLYBEHAVIORS, "CK_LOAD_ONLYBEHAVIORS" }
};
const EnumDescPairArray<LibCmo::CK_FO_OPTIONS> CK_FO_OPTIONS{
{ LibCmo::CK_FO_OPTIONS::CK_FO_DEFAULT, "CK_FO_DEFAULT" },
{ LibCmo::CK_FO_OPTIONS::CK_FO_RENAMEOBJECT, "CK_FO_RENAMEOBJECT" },
{ LibCmo::CK_FO_OPTIONS::CK_FO_REPLACEOBJECT, "CK_FO_REPLACEOBJECT" },
{ LibCmo::CK_FO_OPTIONS::CK_FO_DONTLOADOBJECT, "CK_FO_DONTLOADOBJECT" }
};
}
template<typename TEnum>
void GetEnumName(const EnumDescPairArray<TEnum> desc, std::string& strl, TEnum val) {
}
template<typename TEnum>
void GetFlagEnumName(const EnumDescPairArray<TEnum> desc, std::string& strl, TEnum val) {
}
#pragma endregion
#pragma region class id and ck error
template<typename TKey, typename TValue> template<typename TKey, typename TValue>
static inline const TValue* GetEnumData(const std::vector<std::pair<TKey, TValue>>& vec, const TKey key) { static inline const TValue* GetEnumData(const std::vector<std::pair<TKey, TValue>>& vec, const TKey key) {
size_t len = vec.size(); size_t len = vec.size();
@ -187,6 +233,8 @@ namespace Unvirt {
} }
} }
#pragma endregion
void GetAccessibleFileSize(std::string& strl, uint64_t size) { void GetAccessibleFileSize(std::string& strl, uint64_t size) {
static double denominator = (double)0b1111111111; static double denominator = (double)0b1111111111;

View File

@ -1,17 +1,31 @@
#pragma once #pragma once
#include <VTConstants.hpp> #include <VTConstants.hpp>
#include <vector>
#include <string> #include <string>
namespace Unvirt { namespace Unvirt {
namespace AccessibleValue { namespace AccessibleValue {
template<typename TEnum>
using EnumDescPairArray = std::vector<std::pair<TEnum, const char*>>;
namespace EnumDesc {
extern const EnumDescPairArray<LibCmo::CK_FILE_WRITEMODE> CK_FILE_WRITEMODE;
extern const EnumDescPairArray<LibCmo::CK_LOAD_FLAGS> CK_LOAD_FLAGS;
extern const EnumDescPairArray<LibCmo::CK_FO_OPTIONS> CK_FO_OPTIONS;
}
template<typename TEnum>
void GetEnumName(const EnumDescPairArray<TEnum> desc, std::string& strl, TEnum val);
template<typename TEnum>
void GetFlagEnumName(const EnumDescPairArray<TEnum> desc, std::string& strl, TEnum val);
void GetClassIdName(std::string& strl, LibCmo::CK_CLASSID cls); void GetClassIdName(std::string& strl, LibCmo::CK_CLASSID cls);
void GetCkErrorName(std::string& strl, LibCmo::CKERROR err); void GetCkErrorName(std::string& strl, LibCmo::CKERROR err);
void GetClassIdHierarchy(std::string& strl, LibCmo::CK_CLASSID cls); void GetClassIdHierarchy(std::string& strl, LibCmo::CK_CLASSID cls);
void GetCkErrorDescription(std::string& strl, LibCmo::CKERROR err); void GetCkErrorDescription(std::string& strl, LibCmo::CKERROR err);
void GetAccessibleFileSize(std::string& strl, uint64_t size); void GetAccessibleFileSize(std::string& strl, uint64_t size);
} }