CScriptLayer: Make use of ranged for

This commit is contained in:
Lioncash 2020-06-21 02:18:06 -04:00
parent ff848428b7
commit 46b9a6eeb3
1 changed files with 23 additions and 24 deletions

View File

@ -4,6 +4,7 @@
#include "CScriptObject.h" #include "CScriptObject.h"
#include "Core/Resource/CDependencyGroup.h" #include "Core/Resource/CDependencyGroup.h"
#include <Common/BasicTypes.h> #include <Common/BasicTypes.h>
#include <algorithm>
#include <string> #include <string>
#include <vector> #include <vector>
@ -22,8 +23,8 @@ public:
~CScriptLayer() ~CScriptLayer()
{ {
for (auto it = mInstances.begin(); it != mInstances.end(); it++) for (auto* instance : mInstances)
delete *it; delete instance;
} }
// Data Manipulation // Data Manipulation
@ -43,14 +44,13 @@ public:
void RemoveInstance(CScriptObject *pInstance) void RemoveInstance(CScriptObject *pInstance)
{ {
for (auto it = mInstances.begin(); it != mInstances.end(); ++it) const auto it = std::find_if(mInstances.cbegin(), mInstances.cend(),
{ [pInstance](const auto* instance) { return instance == pInstance; });
if (*it == pInstance)
{ if (it == mInstances.cend())
mInstances.erase(it); return;
break;
} mInstances.erase(it);
}
} }
void RemoveInstanceByIndex(uint32 Index) void RemoveInstanceByIndex(uint32 Index)
@ -60,14 +60,13 @@ public:
void RemoveInstanceByID(uint32 ID) void RemoveInstanceByID(uint32 ID)
{ {
for (auto it = mInstances.begin(); it != mInstances.end(); ++it) const auto it = std::find_if(mInstances.cbegin(), mInstances.cend(),
{ [ID](const auto* instance) { return instance->InstanceID() == ID; });
if ((*it)->InstanceID() == ID)
{ if (it == mInstances.cend())
mInstances.erase(it); return;
break;
} mInstances.erase(it);
}
} }
void Reserve(uint32 Amount) void Reserve(uint32 Amount)
@ -85,13 +84,13 @@ public:
CScriptObject* InstanceByID(uint32 ID) const CScriptObject* InstanceByID(uint32 ID) const
{ {
for (auto it = mInstances.begin(); it != mInstances.end(); ++it) const auto it = std::find_if(mInstances.begin(), mInstances.end(),
{ [ID](const auto* instance) { return instance->InstanceID() == ID; });
if ((*it)->InstanceID() == ID)
return *it;
}
return nullptr; if (it == mInstances.cbegin())
return nullptr;
return *it;
} }
void SetName(TString rkName) { mLayerName = std::move(rkName); } void SetName(TString rkName) { mLayerName = std::move(rkName); }