Resource *ResourceManager::get(std::string const &idPath, generator fun, void *data) { // Check if the id exists, and return the value if it does. ResourceIterator resIter = mResources.find(idPath); if (resIter != mResources.end()) { resIter->second->incRef(); return resIter->second; } resIter = mOrphanedResources.find(idPath); if (resIter != mOrphanedResources.end()) { Resource *res = resIter->second; mResources.insert(*resIter); mOrphanedResources.erase(resIter); res->incRef(); return res; } Resource *resource = fun(data); if (resource) { resource->incRef(); resource->mIdPath = idPath; mResources[idPath] = resource; cleanOrphans(); } // Returns NULL if the object could not be created. return resource; }
int editShell(){ char src[512]; int ret; if(!arglist[AEDIT].subarg){ printf("Edit> "); while(fgets(src,512,stdin)){ tlist = lex(src); fullcmd=NULL; ret=yyparse(); if(!ret) ret=runEditAction(fullcmd); else ret=HARP_RET_ERR; printf("Edit> "); } } else{ tlist = lex(arglist[AEDIT].subarg); fullcmd=NULL; ret=yyparse(); if(!ret) ret=runEditAction(fullcmd); else ret=HARP_RET_ERR; } cleanOrphans(); return ret; }
void ResourceManager::cleanUp(Resource *const res) { if (!res) return; if (res->mRefCount > 0) { logger->log("ResourceManager::~ResourceManager() cleaning up %u " "reference%s to %s", res->mRefCount, (res->mRefCount == 1) ? "" : "s", res->mIdPath.c_str()); } delete res; #ifdef DEBUG_LEAKS cleanOrphans(true); #endif // DEBUG_LEAKS }