Files
winix/plugins/menu/cache.cpp
Tomasz Sowa a45fb30e0a rewritten: plugin 'menu'
now we have a cache for the plugin
           (this limits the number of database requests)
added:     to plugin 'menu'
           menu_dir_tab can have a 'current' parameter (first argument)
           (it uses the last path from the previous menu_dir_tab) 
changed:   updated to the new EZC api
added:     new message to plugins: WINIX_DIR_ADDED


git-svn-id: svn://ttmath.org/publicrep/winix/trunk@808 e52654a7-88a9-db11-a3e9-0013d4bc506e
2012-02-24 12:09:38 +00:00

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