libcmo21/Unvirt/AccessibleValue.hpp

70 lines
2.0 KiB
C++
Raw Normal View History

2023-02-08 22:57:31 +08:00
#pragma once
2023-08-26 20:34:51 +08:00
#include <VTAll.hpp>
2023-02-09 14:12:02 +08:00
#include <vector>
2023-02-08 22:57:31 +08:00
#include <string>
namespace Unvirt {
namespace AccessibleValue {
2023-03-03 16:05:32 +08:00
constexpr const char c_InvalidEnumName[] = "[undefined]";
2023-02-09 17:16:58 +08:00
2023-08-26 20:34:51 +08:00
struct GeneralReflection { const char* mName; };
template<typename _Ty>
using GeneralReflectionArray = std::vector<std::pair<_Ty, GeneralReflection>>;
2023-02-09 17:16:58 +08:00
2023-08-26 20:34:51 +08:00
template<typename _Ty>
std::string GetEnumName(_Ty val, const GeneralReflectionArray<_Ty>& desc) {
2023-03-03 16:05:32 +08:00
std::string strl;
2023-08-26 20:34:51 +08:00
for (auto& item : desc) {
if (item.first == val) {
strl = item.second.mName;
2023-03-03 16:05:32 +08:00
return strl;
2023-02-09 17:16:58 +08:00
}
}
strl = c_InvalidEnumName;
2023-03-03 16:05:32 +08:00
return strl;
2023-02-09 17:16:58 +08:00
}
2023-08-26 20:34:51 +08:00
template<typename _Ty>
std::string GetFlagEnumName(_Ty val, const GeneralReflectionArray<_Ty>& desc) {
2023-03-03 16:05:32 +08:00
std::string strl;
2023-08-26 20:34:51 +08:00
for (auto& item : desc) {
2023-02-09 17:16:58 +08:00
// if it have exacelt same entry, return directly
2023-08-26 20:34:51 +08:00
if (item.first == val) {
strl = item.second.mName;
2023-03-03 16:05:32 +08:00
return strl;
2023-02-09 17:16:58 +08:00
}
// check flag match
2023-08-26 20:34:51 +08:00
if (LibCmo::EnumsHelper::Has(val, item.first)) {
2023-02-09 17:16:58 +08:00
if (strl.size() != 0u) strl += ", ";
2023-08-26 20:34:51 +08:00
strl += item.second.mName;
2023-02-09 17:16:58 +08:00
}
}
2023-08-26 20:34:51 +08:00
// if nothing was gotten. set to undefined
2023-02-09 17:16:58 +08:00
if (strl.size() == 0u) {
strl = c_InvalidEnumName;
2023-08-26 20:34:51 +08:00
}
2023-03-03 16:05:32 +08:00
return strl;
2023-02-09 17:16:58 +08:00
}
2023-03-03 16:05:32 +08:00
std::string GetClassIdName(LibCmo::CK2::CK_CLASSID cls);
std::string GetCkErrorName(LibCmo::CK2::CKERROR err);
std::string GetClassIdHierarchy(LibCmo::CK2::CK_CLASSID cls);
std::string GetCkErrorDescription(LibCmo::CK2::CKERROR err);
2023-02-09 14:12:02 +08:00
2023-08-26 20:34:51 +08:00
std::string GetReadableFileSize(uint64_t size);
namespace EnumDesc {
extern const GeneralReflectionArray<LibCmo::CK2::CK_FILE_WRITEMODE> CK_FILE_WRITEMODE;
extern const GeneralReflectionArray<LibCmo::CK2::CK_FO_OPTIONS> CK_FO_OPTIONS;
extern const GeneralReflectionArray<LibCmo::CK2::CK_STATECHUNK_CHUNKOPTIONS> CK_STATECHUNK_CHUNKOPTIONS;
extern const GeneralReflectionArray<LibCmo::CK2::CK_STATECHUNK_DATAVERSION> CK_STATECHUNK_DATAVERSION;
extern const GeneralReflectionArray<LibCmo::CK2::CK_STATECHUNK_CHUNKVERSION> CK_STATECHUNK_CHUNKVERSION;
}
2023-02-08 22:57:31 +08:00
}
}