PrimeWorldEditor/src/Core/Resource/CDependencyGroup.h
Lioncash 84a42cd3c2 CWorld: Make use of size_t where applicable
Plays nicer with standard types and prevents type truncations.
2020-06-15 20:14:17 -04:00

66 lines
1.6 KiB
C++

#ifndef CDEPENDENCYGROUP
#define CDEPENDENCYGROUP
#include "CResource.h"
class CDependencyGroup : public CResource
{
DECLARE_RESOURCE_TYPE(DependencyGroup)
std::vector<CAssetID> mDependencies;
public:
explicit CDependencyGroup(CResourceEntry *pEntry = nullptr) : CResource(pEntry) {}
void Clear() { mDependencies.clear(); }
uint32 NumDependencies() const { return mDependencies.size(); }
CAssetID DependencyByIndex(size_t Index) const { return mDependencies[Index]; }
void AddDependency(const CAssetID& rkID)
{
if (!HasDependency(rkID))
mDependencies.push_back(rkID);
}
void AddDependency(CResource *pRes)
{
if ( pRes && !HasDependency(pRes->ID()) )
mDependencies.push_back(pRes->ID());
}
void RemoveDependency(const CAssetID& rkID)
{
for (auto Iter = mDependencies.begin(); Iter != mDependencies.end(); Iter++)
{
if (*Iter == rkID)
{
mDependencies.erase(Iter);
return;
}
}
}
bool HasDependency(const CAssetID &rkID) const
{
for (uint32 iDep = 0; iDep < mDependencies.size(); iDep++)
{
if (mDependencies[iDep] == rkID)
return true;
}
return false;
}
std::unique_ptr<CDependencyTree> BuildDependencyTree() const
{
auto pTree = std::make_unique<CDependencyTree>();
for (const auto& dep : mDependencies)
pTree->AddDependency(dep);
return pTree;
}
};
#endif // CDEPENDENCYGROUP