erpt: actually support non-sequential ids, nintendo why
This commit is contained in:
@@ -58,34 +58,88 @@ namespace ams::erpt::srv {
|
||||
};
|
||||
#undef STRINGIZE_HANDLER
|
||||
|
||||
#define GET_FIELD_CATEGORY(FIELD, ID, CATEGORY, TYPE, FLAG) [FieldId_##FIELD] = CategoryId_##CATEGORY,
|
||||
constexpr inline const CategoryId FieldToCategoryMap[] = {
|
||||
#define GET_FIELD_CATEGORY(FIELD, ID, CATEGORY, TYPE, FLAG) CategoryId_##CATEGORY,
|
||||
constexpr inline const CategoryId FieldIndexToCategoryMap[] = {
|
||||
AMS_ERPT_FOREACH_FIELD(GET_FIELD_CATEGORY)
|
||||
};
|
||||
#undef GET_FIELD_CATEGORY
|
||||
|
||||
#define GET_FIELD_TYPE(FIELD, ID, CATEGORY, TYPE, FLAG) [FieldId_##FIELD] = TYPE,
|
||||
constexpr inline const FieldType FieldToTypeMap[] = {
|
||||
#define GET_FIELD_TYPE(FIELD, ID, CATEGORY, TYPE, FLAG) TYPE,
|
||||
constexpr inline const FieldType FieldIndexToTypeMap[] = {
|
||||
AMS_ERPT_FOREACH_FIELD(GET_FIELD_TYPE)
|
||||
};
|
||||
#undef GET_FIELD_TYPE
|
||||
|
||||
#define GET_FIELD_FLAG(FIELD, ID, CATEGORY, TYPE, FLAG) [FieldId_##FIELD] = FLAG,
|
||||
constexpr inline const FieldFlag FieldToFlagMap[] = {
|
||||
#define GET_FIELD_FLAG(FIELD, ID, CATEGORY, TYPE, FLAG) FLAG,
|
||||
constexpr inline const FieldFlag FieldIndexToFlagMap[] = {
|
||||
AMS_ERPT_FOREACH_FIELD(GET_FIELD_FLAG)
|
||||
};
|
||||
#undef GET_FIELD_FLAG
|
||||
|
||||
inline CategoryId ConvertFieldToCategory(FieldId id) {
|
||||
return FieldToCategoryMap[id];
|
||||
#define GET_FIELD_ID(FIELD, ...) FieldId_##FIELD,
|
||||
constexpr inline const FieldId FieldIndexToFieldIdMap[] = {
|
||||
AMS_ERPT_FOREACH_FIELD(GET_FIELD_ID)
|
||||
};
|
||||
#undef GET_FIELD_ID
|
||||
|
||||
#define GET_CATEGORY_ID(CATEGORY, ...) CategoryId_##CATEGORY,
|
||||
constexpr inline const CategoryId CategoryIndexToCategoryIdMap[] = {
|
||||
AMS_ERPT_FOREACH_CATEGORY(GET_CATEGORY_ID)
|
||||
};
|
||||
#undef GET_CATEGORY_ID
|
||||
|
||||
constexpr util::optional<size_t> FindFieldIndex(FieldId id) {
|
||||
if (std::is_constant_evaluated()) {
|
||||
for (size_t i = 0; i < util::size(FieldIndexToFieldIdMap); ++i) {
|
||||
if (FieldIndexToFieldIdMap[i] == id) {
|
||||
return i;
|
||||
}
|
||||
}
|
||||
|
||||
return util::nullopt;
|
||||
} else {
|
||||
if (const auto it = std::lower_bound(std::begin(FieldIndexToFieldIdMap), std::end(FieldIndexToFieldIdMap), id); it != std::end(FieldIndexToFieldIdMap) && *it == id) {
|
||||
return std::distance(FieldIndexToFieldIdMap, it);
|
||||
} else {
|
||||
return util::nullopt;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
inline FieldType ConvertFieldToType(FieldId id) {
|
||||
return FieldToTypeMap[id];
|
||||
constexpr util::optional<size_t> FindCategoryIndex(CategoryId id) {
|
||||
if (std::is_constant_evaluated()) {
|
||||
for (size_t i = 0; i < util::size(CategoryIndexToCategoryIdMap); ++i) {
|
||||
if (CategoryIndexToCategoryIdMap[i] == id) {
|
||||
return i;
|
||||
}
|
||||
}
|
||||
|
||||
return util::nullopt;
|
||||
} else {
|
||||
if (const auto it = std::lower_bound(std::begin(CategoryIndexToCategoryIdMap), std::end(CategoryIndexToCategoryIdMap), id); it != std::end(CategoryIndexToCategoryIdMap) && *it == id) {
|
||||
return std::distance(CategoryIndexToCategoryIdMap, it);
|
||||
} else {
|
||||
return util::nullopt;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
inline FieldFlag ConvertFieldToFlag(FieldId id) {
|
||||
return FieldToFlagMap[id];
|
||||
constexpr inline CategoryId ConvertFieldToCategory(FieldId id) {
|
||||
const auto index = FindFieldIndex(id);
|
||||
AMS_ASSERT(index.has_value());
|
||||
return FieldIndexToCategoryMap[index.value()];
|
||||
}
|
||||
|
||||
constexpr inline FieldType ConvertFieldToType(FieldId id) {
|
||||
const auto index = FindFieldIndex(id);
|
||||
AMS_ASSERT(index.has_value());
|
||||
return FieldIndexToTypeMap[index.value()];
|
||||
}
|
||||
|
||||
constexpr inline FieldFlag ConvertFieldToFlag(FieldId id) {
|
||||
const auto index = FindFieldIndex(id);
|
||||
AMS_ASSERT(index.has_value());
|
||||
return FieldIndexToFlagMap[index.value()];
|
||||
}
|
||||
|
||||
constexpr inline ReportFlagSet MakeNoReportFlags() {
|
||||
|
||||
Reference in New Issue
Block a user