winix/plugins/menu/cache.cpp

97 lines
1.0 KiB
C++
Executable File

/*
* This file is a part of Winix
* and is not publicly distributed
*
* Copyright (c) 2012, Tomasz Sowa
* All rights reserved.
*
*/
#include "cache.h"
#include "core/misc.h"
namespace Menu
{
void Cache::SetDirs(Dirs * pdirs)
{
dirs = pdirs;
}
CacheItem * Cache::Get(long dir_id, int param)
{
Tab::iterator i;
for(i=tab.begin() ; i!=tab.end() ; ++i)
{
if( i->dir_id == dir_id && i->param == param )
{
return &(*i);
}
}
return 0;
}
CacheItem * Cache::Insert(long dir_id, int param)
{
empty_cache_item.dir_id = dir_id;
empty_cache_item.param = param;
empty_cache_item.menu_items.clear();
if( !dirs->MakePath(dir_id, empty_cache_item.dir) )
empty_cache_item.dir.clear();
NoLastSlash(empty_cache_item.dir);
tab.push_back(empty_cache_item);
return &tab.back();
}
void Cache::Remove(long dir_id)
{
Tab::iterator i;
for(i=tab.begin() ; i!=tab.end() ; )
{
if( i->dir_id == dir_id )
{
tab.erase(i++);
}
else
{
++i;
}
}
}
void Cache::Clear()
{
tab.clear();
}
} // namespace