2020-08-04 12:31:33 +08:00
|
|
|
#include "GObjectPool.h"
|
|
|
|
#include "GObject.h"
|
|
|
|
#include "UIPackage.h"
|
|
|
|
|
|
|
|
NS_FGUI_BEGIN
|
2022-07-11 17:50:21 +08:00
|
|
|
USING_NS_AX;
|
2020-08-04 12:31:33 +08:00
|
|
|
|
|
|
|
GObjectPool::GObjectPool()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
GObjectPool::~GObjectPool()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
GObject* GObjectPool::getObject(const std::string & url)
|
|
|
|
{
|
|
|
|
std::string url2 = UIPackage::normalizeURL(url);
|
|
|
|
if (url2.length() == 0)
|
|
|
|
return nullptr;
|
|
|
|
|
|
|
|
GObject* ret;
|
|
|
|
Vector<GObject*>& arr = _pool[url2];
|
|
|
|
if (!arr.empty())
|
|
|
|
{
|
|
|
|
ret = arr.back();
|
|
|
|
ret->retain();
|
|
|
|
arr.popBack();
|
|
|
|
ret->autorelease();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
ret = UIPackage::createObjectFromURL(url2);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
void GObjectPool::returnObject(GObject* obj)
|
|
|
|
{
|
|
|
|
_pool[obj->getResourceURL()].pushBack(obj);
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_FGUI_END
|