2015-08-17 22:05:00 +00:00
|
|
|
#include "CSimplePool.hpp"
|
2015-08-22 01:58:41 +00:00
|
|
|
#include "IVParamObj.hpp"
|
2016-02-05 01:27:03 +00:00
|
|
|
#include "CToken.hpp"
|
2015-08-17 22:05:00 +00:00
|
|
|
|
2016-02-13 09:02:47 +00:00
|
|
|
namespace pshag
|
2015-08-17 22:05:00 +00:00
|
|
|
{
|
|
|
|
|
2016-02-05 01:27:03 +00:00
|
|
|
CSimplePool::CSimplePool(IFactory& factory)
|
|
|
|
: x30_factory(factory), x34_paramXfer(new TObjOwnerParam<IObjectStore*>(this))
|
|
|
|
{}
|
|
|
|
|
2016-02-05 05:52:05 +00:00
|
|
|
CToken CSimplePool::GetObj(const SObjectTag& tag, const CVParamTransfer& paramXfer)
|
2016-02-05 01:27:03 +00:00
|
|
|
{
|
2016-02-05 05:52:05 +00:00
|
|
|
auto iter = std::find_if(x4_resources.begin(), x4_resources.end(), [&tag](std::pair<SObjectTag, CObjectReference*> pair)->bool{
|
|
|
|
return pair.first == tag;
|
|
|
|
});
|
|
|
|
|
|
|
|
if (iter != x4_resources.end())
|
2016-02-05 05:57:46 +00:00
|
|
|
return CToken(iter->second);
|
2016-02-05 05:52:05 +00:00
|
|
|
// TODO: There is some logic missing here, need to figure out what it's doing
|
2016-02-05 05:57:46 +00:00
|
|
|
CObjectReference* ret = new CObjectReference(*this, x30_factory.Build(tag, paramXfer), tag, paramXfer);
|
2016-02-05 05:52:05 +00:00
|
|
|
|
|
|
|
return CToken(ret);
|
2016-02-05 01:27:03 +00:00
|
|
|
}
|
|
|
|
|
2016-02-05 05:52:05 +00:00
|
|
|
CToken CSimplePool::GetObj(const SObjectTag& tag)
|
2016-02-05 01:27:03 +00:00
|
|
|
{
|
2016-02-05 05:52:05 +00:00
|
|
|
return GetObj(tag, x34_paramXfer);
|
2016-02-05 01:27:03 +00:00
|
|
|
}
|
|
|
|
|
2016-02-05 05:52:05 +00:00
|
|
|
CToken CSimplePool::GetObj(char const* resourceName)
|
2016-02-05 01:27:03 +00:00
|
|
|
{
|
2016-02-05 05:52:05 +00:00
|
|
|
return GetObj(resourceName, x34_paramXfer);
|
2016-02-05 01:27:03 +00:00
|
|
|
}
|
|
|
|
|
2016-02-05 05:52:05 +00:00
|
|
|
CToken CSimplePool::GetObj(char const* resourceName, const CVParamTransfer& paramXfer)
|
2016-02-05 01:27:03 +00:00
|
|
|
{
|
2016-02-05 05:52:05 +00:00
|
|
|
const SObjectTag* tag = x30_factory.GetResourceIdByName(resourceName);
|
|
|
|
return GetObj(*tag, paramXfer);
|
2016-02-05 01:27:03 +00:00
|
|
|
}
|
|
|
|
|
2016-02-05 05:52:05 +00:00
|
|
|
bool CSimplePool::HasObject(const SObjectTag& tag) const
|
2016-02-05 01:27:03 +00:00
|
|
|
{
|
2016-02-05 05:52:05 +00:00
|
|
|
auto iter = std::find_if(x4_resources.begin(), x4_resources.end(), [&tag](std::pair<SObjectTag, CObjectReference*> pair)->bool{
|
|
|
|
return pair.first == tag;
|
|
|
|
});
|
|
|
|
|
|
|
|
return iter != x4_resources.end();
|
2016-02-05 01:27:03 +00:00
|
|
|
}
|
|
|
|
|
2016-02-05 05:52:05 +00:00
|
|
|
bool CSimplePool::ObjectIsLive(const SObjectTag&) const
|
2016-02-05 01:27:03 +00:00
|
|
|
{
|
2016-02-05 05:52:05 +00:00
|
|
|
return false;
|
2016-02-05 01:27:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void CSimplePool::Flush()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2016-02-05 05:52:05 +00:00
|
|
|
void CSimplePool::ObjectUnreferenced(const SObjectTag& tag)
|
2016-02-05 01:27:03 +00:00
|
|
|
{
|
2016-02-05 05:52:05 +00:00
|
|
|
auto iter = std::find_if(x4_resources.begin(), x4_resources.end(), [&tag](std::pair<SObjectTag, CObjectReference*> pair)->bool{
|
|
|
|
return pair.first == tag;
|
|
|
|
});
|
|
|
|
if (iter != x4_resources.end())
|
|
|
|
x4_resources.erase(iter);
|
2016-02-05 01:27:03 +00:00
|
|
|
}
|
|
|
|
|
2015-08-17 22:05:00 +00:00
|
|
|
}
|