Recovered from microbel
This commit is contained in:
66
common/lib/geometry/cache.C
Normal file
66
common/lib/geometry/cache.C
Normal file
@@ -0,0 +1,66 @@
|
||||
/*
|
||||
* PVVMUD a 3D MUD
|
||||
* Copyright (C) 1998-1999 Programvareverkstedet (pvv@pvv.org)
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*
|
||||
*/
|
||||
#include "pvvmud.H"
|
||||
#include "cache.H"
|
||||
|
||||
CCache::CCache(){
|
||||
cache = new CObjectList();
|
||||
}
|
||||
|
||||
CObject * CCache::failFunc(int id){
|
||||
return NULL;
|
||||
}
|
||||
|
||||
CObject* CCache::add(int id, CObject * item){
|
||||
CObjectListItem * listItem = cache->getFirst();
|
||||
|
||||
while ( listItem != NULL ){
|
||||
CCacheItem * cacheItem = (CCacheItem*)listItem->getObject();
|
||||
if (cacheItem->getId() == id){
|
||||
return cacheItem->setItem(item);
|
||||
}
|
||||
listItem = listItem->getNext();
|
||||
}
|
||||
|
||||
CCacheItem * newItem = new CCacheItem(id,item);
|
||||
cache->addLast((CObject*)newItem);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
CObject * CCache::get(int id){
|
||||
CObjectListItem * item = cache->getFirst();
|
||||
|
||||
while ( item != NULL ){
|
||||
CCacheItem * cacheItem = (CCacheItem*)item->getObject();
|
||||
if (cacheItem->getId() == id) return cacheItem->getItem();
|
||||
item = item->getNext();
|
||||
}
|
||||
|
||||
// Failed to find object in cache calling failFunc
|
||||
CObject * newObject = failFunc(id);
|
||||
if (newObject != NULL) add(id,newObject);
|
||||
|
||||
return newObject;
|
||||
}
|
||||
|
||||
void CCache::clear(){
|
||||
cache->deleteAll();
|
||||
}
|
Reference in New Issue
Block a user