libcmo21/Unvirt/AccessibleValue.hpp

73 lines
1.9 KiB
C++
Raw Normal View History

2023-02-08 22:57:31 +08:00
#pragma once
2023-02-25 17:39:39 +08:00
#include <CKEnums.hpp>
2023-02-26 21:48:03 +08:00
#include <VTUtils.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
#pragma region universal enum name
2023-02-09 14:12:02 +08:00
template<typename TEnum>
using EnumDescPairArray = std::vector<std::pair<TEnum, const char*>>;
2023-02-08 22:57:31 +08:00
2023-02-09 14:12:02 +08:00
namespace EnumDesc {
2023-02-26 21:48:03 +08:00
extern const EnumDescPairArray<LibCmo::CK2::CK_FILE_WRITEMODE> CK_FILE_WRITEMODE;
extern const EnumDescPairArray<LibCmo::CK2::CK_LOAD_FLAGS> CK_LOAD_FLAGS;
extern const EnumDescPairArray<LibCmo::CK2::CK_FO_OPTIONS> CK_FO_OPTIONS;
extern const EnumDescPairArray<LibCmo::CK2::CK_PLUGIN_TYPE> CK_PLUGIN_TYPE;
2023-02-09 14:12:02 +08:00
}
template<typename TEnum>
2023-03-03 16:05:32 +08:00
std::string GetEnumName(const EnumDescPairArray<TEnum>& desc, TEnum val) {
std::string strl;
2023-02-09 17:16:58 +08:00
for (auto it = desc.begin(); it != desc.end(); ++it) {
if ((*it).first == val) {
strl = (*it).second;
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-02-09 14:12:02 +08:00
template<typename TEnum>
2023-03-03 16:05:32 +08:00
std::string GetFlagEnumName(const EnumDescPairArray<TEnum>& desc, TEnum val) {
std::string strl;
2023-02-09 17:16:58 +08:00
for (auto it = desc.begin(); it != desc.end(); ++it) {
// if it have exacelt same entry, return directly
if ((*it).first == val) {
strl = (*it).second;
2023-03-03 16:05:32 +08:00
return strl;
2023-02-09 17:16:58 +08:00
}
// check flag match
2023-02-25 17:39:39 +08:00
if (LibCmo::EnumsHelper::FlagEnumHas(val, (*it).first)) {
2023-02-09 17:16:58 +08:00
// matched, add it
if (strl.size() != 0u) strl += ", ";
strl += (*it).second;
}
}
if (strl.size() == 0u) {
// nothing was gotten. set to undefined
strl = c_InvalidEnumName;
} // otherwise return directly
2023-03-03 16:05:32 +08:00
return strl;
2023-02-09 17:16:58 +08:00
}
#pragma endregion
2023-02-08 22:57:31 +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-03-03 16:05:32 +08:00
std::string GetAccessibleFileSize(uint64_t size);
2023-02-08 22:57:31 +08:00
}
}