CResTypeInfo: Make use of ranged for where applicable
Same behavior, better readability
This commit is contained in:
parent
a612751cb0
commit
8f70b20312
|
@ -12,17 +12,13 @@ CResTypeInfo::CResTypeInfo(EResourceType Type, const TString& rkTypeName, const
|
||||||
#if !PUBLIC_RELEASE
|
#if !PUBLIC_RELEASE
|
||||||
ASSERT(smTypeMap.find(Type) == smTypeMap.end());
|
ASSERT(smTypeMap.find(Type) == smTypeMap.end());
|
||||||
#endif
|
#endif
|
||||||
smTypeMap[Type] = std::unique_ptr<CResTypeInfo>(this);
|
smTypeMap.insert_or_assign(Type, std::unique_ptr<CResTypeInfo>(this));
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CResTypeInfo::IsInGame(EGame Game) const
|
bool CResTypeInfo::IsInGame(EGame Game) const
|
||||||
{
|
{
|
||||||
for (uint32 iGame = 0; iGame < mCookedExtensions.size(); iGame++)
|
return std::any_of(mCookedExtensions.cbegin(), mCookedExtensions.cend(),
|
||||||
{
|
[Game](const auto& entry) { return entry.Game == Game; });
|
||||||
if (mCookedExtensions[iGame].Game == Game)
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
CFourCC CResTypeInfo::CookedExtension(EGame Game) const
|
CFourCC CResTypeInfo::CookedExtension(EGame Game) const
|
||||||
|
@ -31,24 +27,24 @@ CFourCC CResTypeInfo::CookedExtension(EGame Game) const
|
||||||
if (Game == EGame::Invalid)
|
if (Game == EGame::Invalid)
|
||||||
Game = EGame::Prime;
|
Game = EGame::Prime;
|
||||||
|
|
||||||
for (uint32 iGame = 0; iGame < mCookedExtensions.size(); iGame++)
|
const auto iter = std::find_if(mCookedExtensions.cbegin(), mCookedExtensions.cend(),
|
||||||
{
|
[Game](const auto& entry) { return entry.Game == Game; });
|
||||||
if (mCookedExtensions[iGame].Game == Game)
|
|
||||||
return mCookedExtensions[iGame].CookedExt;
|
|
||||||
}
|
|
||||||
|
|
||||||
return "NONE";
|
if (iter == mCookedExtensions.cend())
|
||||||
|
return "NONE";
|
||||||
|
|
||||||
|
return iter->CookedExt;
|
||||||
}
|
}
|
||||||
|
|
||||||
// ************ STATIC ************
|
// ************ STATIC ************
|
||||||
void CResTypeInfo::GetAllTypesInGame(EGame Game, std::list<CResTypeInfo*>& rOut)
|
void CResTypeInfo::GetAllTypesInGame(EGame Game, std::list<CResTypeInfo*>& rOut)
|
||||||
{
|
{
|
||||||
for (auto Iter = smTypeMap.begin(); Iter != smTypeMap.end(); Iter++)
|
for (const auto& entry : smTypeMap)
|
||||||
{
|
{
|
||||||
CResTypeInfo *pType = Iter->second.get();
|
auto& type = entry.second;
|
||||||
|
|
||||||
if (pType->IsInGame(Game))
|
if (type->IsInGame(Game))
|
||||||
rOut.push_back(pType);
|
rOut.push_back(type.get());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -68,19 +64,19 @@ CResTypeInfo* CResTypeInfo::TypeForCookedExtension(EGame Game, CFourCC Ext)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Is this type cached?
|
// Is this type cached?
|
||||||
auto Iter = sCachedTypeMap.find(Ext);
|
const auto Iter = sCachedTypeMap.find(Ext);
|
||||||
if (Iter != sCachedTypeMap.end())
|
if (Iter != sCachedTypeMap.cend())
|
||||||
return Iter->second;
|
return Iter->second;
|
||||||
|
|
||||||
// Not cached - do a slow lookup
|
// Not cached - do a slow lookup
|
||||||
for (auto Iter = smTypeMap.begin(); Iter != smTypeMap.end(); Iter++)
|
for (auto& entry : smTypeMap)
|
||||||
{
|
{
|
||||||
CResTypeInfo *pType = Iter->second.get();
|
auto* type = entry.second.get();
|
||||||
|
|
||||||
if (pType->CookedExtension(Game) == Ext)
|
if (type->CookedExtension(Game) == Ext)
|
||||||
{
|
{
|
||||||
sCachedTypeMap[Ext] = pType;
|
sCachedTypeMap.insert_or_assign(Ext, type);
|
||||||
return pType;
|
return type;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -91,14 +87,18 @@ CResTypeInfo* CResTypeInfo::TypeForCookedExtension(EGame Game, CFourCC Ext)
|
||||||
errorf("Failed to find resource type for cooked extension: %s", *Ext.ToString());
|
errorf("Failed to find resource type for cooked extension: %s", *Ext.ToString());
|
||||||
DEBUG_BREAK;
|
DEBUG_BREAK;
|
||||||
}
|
}
|
||||||
sCachedTypeMap[Ext] = nullptr;
|
sCachedTypeMap.insert_or_assign(Ext, nullptr);
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
CResTypeInfo* CResTypeInfo::FindTypeInfo(EResourceType Type)
|
CResTypeInfo* CResTypeInfo::FindTypeInfo(EResourceType Type)
|
||||||
{
|
{
|
||||||
auto Iter = smTypeMap.find(Type);
|
const auto iter = smTypeMap.find(Type);
|
||||||
return (Iter == smTypeMap.end() ? nullptr : Iter->second.get());
|
|
||||||
|
if (iter == smTypeMap.cend())
|
||||||
|
return nullptr;
|
||||||
|
|
||||||
|
return iter->second.get();
|
||||||
}
|
}
|
||||||
|
|
||||||
// ************ SERIALIZATION ************
|
// ************ SERIALIZATION ************
|
||||||
|
|
Loading…
Reference in New Issue