1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54
|
// Author: Yuan Li
#include "RegionTypeMap.hpp"
std::string RegionTypeMap::ToString(RegionType rt) {
assert(RegionTypeToString.find(rt) != RegionTypeToString.end());
return RegionTypeToString.find(rt)->second;
}
RegionType RegionTypeMap::ToRegionType(const std::string & str) {
if (StringToRegionType.find(str) == StringToRegionType.end()) {
std::cout << "Unsupported RegionType " << str << std::endl;
assert(false);
}
return StringToRegionType.find(str)->second;
}
int RegionTypeMap::ToIndex(const std::string & typeStr, const std::vector<std::string> & typeStrs) {
auto it = std::find(typeStrs.begin(), typeStrs.end(), typeStr);
if (it == typeStrs.end()) {
std::cout << "Could not find RegionType " << typeStr << std::endl;
assert(false);
} else {
return std::distance(typeStrs.begin(), it);
}
}
int RegionTypeMap::ToIndex(RegionType rt, const std::vector<std::string> & typeStrs) {
return RegionTypeMap::ToIndex(RegionTypeMap::ToString(rt), typeStrs);
}
int RegionTypeMap::ToIndex(RegionType rt, const std::vector<RegionType> & regionTypes) {
auto it = std::find(regionTypes.begin(), regionTypes.end(), rt);
if (it == regionTypes.end()) {
std::cout << "Could not find RegionType " << RegionTypeMap::ToString(rt) << std::endl;
assert(false);
} else {
return std::distance(regionTypes.begin(), it);
}
}
const std::map<RegionType, std::string> RegionTypeMap::RegionTypeToString = {
{Adapter, "Adapter"},
{Insert, "Insert"},
{HQRegion, "HQRegion"},
{BarCode, "Barcode"}
};
const std::map<std::string, RegionType> RegionTypeMap::StringToRegionType = {
{"Adapter", Adapter},
{"Insert", Insert},
{"HQRegion", HQRegion},
{"Barcode", BarCode},
};
|