Skip to content

Instantly share code, notes, and snippets.

@peterix
Created July 4, 2014 21:37
Show Gist options
  • Select an option

  • Save peterix/2308bce470788866d465 to your computer and use it in GitHub Desktop.

Select an option

Save peterix/2308bce470788866d465 to your computer and use it in GitHub Desktop.
A key value store. With locking. Can't go any simpler than that.
template <typename K, typename V>
class RWStorage
{
public:
void add(K key, V value)
{
QWriteLocker l(&lock);
cache[key] = value;
}
V get(K key) const
{
QReadLocker l(&lock);
if(cache.contains(key))
{
return cache[key];
}
else return V();
}
void clear()
{
QWriteLocker l(&lock);
cache.clear();
}
private:
QReadWriteLock lock;
QMap<K, V> cache;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment