diff options
author | Petr Mrázek <peterix@gmail.com> | 2014-07-06 11:15:15 +0200 |
---|---|---|
committer | Petr Mrázek <peterix@gmail.com> | 2014-07-06 11:15:15 +0200 |
commit | cc499488dbab9167870e6088f9a1793f95894c79 (patch) | |
tree | d6efb25086f4c2c6cb3c0a3dc8ad5a5a80985286 /logic/RWStorage.h | |
parent | a218d7b7f6a9e30671be72b756104302637eb33d (diff) | |
download | PrismLauncher-cc499488dbab9167870e6088f9a1793f95894c79.tar.gz PrismLauncher-cc499488dbab9167870e6088f9a1793f95894c79.tar.bz2 PrismLauncher-cc499488dbab9167870e6088f9a1793f95894c79.zip |
Fix liteloader, some cleanups.
Diffstat (limited to 'logic/RWStorage.h')
-rw-r--r-- | logic/RWStorage.h | 60 |
1 files changed, 60 insertions, 0 deletions
diff --git a/logic/RWStorage.h b/logic/RWStorage.h new file mode 100644 index 00000000..b1598ca4 --- /dev/null +++ b/logic/RWStorage.h @@ -0,0 +1,60 @@ +#pragma once +template <typename K, typename V> +class RWStorage +{ +public: + void add(K key, V value) + { + QWriteLocker l(&lock); + cache[key] = value; + stale_entries.remove(key); + } + V get(K key) + { + QReadLocker l(&lock); + if(cache.contains(key)) + { + return cache[key]; + } + else return V(); + } + bool get(K key, V& value) + { + QReadLocker l(&lock); + if(cache.contains(key)) + { + value = cache[key]; + return true; + } + else return false; + } + bool has(K key) + { + QReadLocker l(&lock); + return cache.contains(key); + } + bool stale(K key) + { + QReadLocker l(&lock); + if(!cache.contains(key)) + return true; + return stale_entries.contains(key); + } + void setStale(K key) + { + QReadLocker l(&lock); + if(cache.contains(key)) + { + stale_entries.insert(key); + } + } + void clear() + { + QWriteLocker l(&lock); + cache.clear(); + } +private: + QReadWriteLock lock; + QMap<K, V> cache; + QSet<K> stale_entries; +};
\ No newline at end of file |