设为首页 加入收藏

TOP

POCO C++库学习和分析 -- Cache(二)
2014-11-24 03:30:38 】 浏览:4265
Tags:POCO 学习 分析 Cache
Replace -= Delegate(&_strategy, &TStrategy::onReplace);
}
void doAdd(const TKey& key, const TValue& val)
/// Adds the key value pair to the cache.
/// If for the key already an entry exists, it will be overwritten.
{
Iterator it = _data.find(key);
doRemove(it);
KeyValueArgs args(key, val);
Add.notify(this, args);
_data.insert(std::make_pair(key, SharedPtr(new TValue(val))));
doReplace();
}
void doAdd(const TKey& key, SharedPtr& val)
/// Adds the key value pair to the cache.
/// If for the key already an entry exists, it will be overwritten.
{
Iterator it = _data.find(key);
doRemove(it);
KeyValueArgs args(key, *val);
Add.notify(this, args);
_data.insert(std::make_pair(key, val));
doReplace();
}
void doUpdate(const TKey& key, const TValue& val)
/// Adds the key value pair to the cache.
/// If for the key already an entry exists, it will be overwritten.
{
KeyValueArgs args(key, val);
Iterator it = _data.find(key);
if (it == _data.end())
{
Add.notify(this, args);
_data.insert(std::make_pair(key, SharedPtr(new TValue(val))));
}
else
{
Update.notify(this, args);
it->second = SharedPtr(new TValue(val));
}
doReplace();
}
void doUpdate(const TKey& key, SharedPtr& val)
/// Adds the key value pair to the cache.
/// If for the key already an entry exists, it will be overwritten.
{
KeyValueArgs args(key, *val);
Iterator it = _data.find(key);
if (it == _data.end())
{
Add.notify(this, args);
_data.insert(std::make_pair(key, val));
}
else
{
Update.notify(this, args);
it->second = val;
}
doReplace();
}
void doRemove(Iterator it)
/// Removes an entry from the cache. If the entry is not found
/// the remove is ignored.
{
if (it != _data.end())
{
Remove.notify(this, it->first);
_data.erase(it);
}
}
bool doHas(const TKey& key) const
/// Returns true if the cache contains a value for the key
{
// ask the strategy if the key is valid
ConstIterator it = _data.find(key);
bool result = false;
if (it != _data.end())
{
ValidArgs args(key);
IsValid.notify(this, args);
result = args.isValid();
}
return result;
}
SharedPtr doGet(const TKey& key)
/// Returns a SharedPtr of the cache entry, returns 0 if for
/// the key no value was found
{
Iterator it = _data.find(key);
SharedPtr result;
if (it != _data.end())
{
// inform all strategies that a read-access to an element happens
Get.notify(this, key);
// ask all strategies if the key is valid
ValidArgs args(key);
IsValid.notify(this, args);
if (!args.isValid())
{
doRemove(it)
首页 上一页 1 2 3 4 下一页 尾页 2/4/4
】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
上一篇查看Objective-C函数与参数 下一篇刨根问底系列之C++ 类型转换挖掘

最新文章

热门文章

Hot 文章

Python

C 语言

C++基础

大数据基础

linux编程基础

C/C++面试题目