diff options
| author | Xanadu <none@none> | 2010-07-20 02:49:28 +0200 |
|---|---|---|
| committer | Xanadu <none@none> | 2010-07-20 02:49:28 +0200 |
| commit | 79622802f397258ee0f34327ba3ae6977ca3e7ff (patch) | |
| tree | 1868946c234ab9ee256a6b7766a15713eae94235 /dep/include/g3dlite/G3D/WeakCache.h | |
| parent | 7dd2dc91816ab8b3bc3b99a1b1c99c7ea314d5a8 (diff) | |
| parent | f906976837502fa5aa81b982b901d1509f5aa0c4 (diff) | |
Merge. Revision history for source files should be all back now.
--HG--
branch : trunk
rename : sql/CMakeLists.txt => sql/tools/CMakeLists.txt
rename : src/server/game/Pools/PoolHandler.cpp => src/server/game/Pools/PoolMgr.cpp
rename : src/server/game/Pools/PoolHandler.h => src/server/game/Pools/PoolMgr.h
rename : src/server/game/PrecompiledHeaders/NixCorePCH.cpp => src/server/game/PrecompiledHeaders/gamePCH.cpp
rename : src/server/game/PrecompiledHeaders/NixCorePCH.h => src/server/game/PrecompiledHeaders/gamePCH.h
Diffstat (limited to 'dep/include/g3dlite/G3D/WeakCache.h')
| -rw-r--r-- | dep/include/g3dlite/G3D/WeakCache.h | 122 |
1 files changed, 0 insertions, 122 deletions
diff --git a/dep/include/g3dlite/G3D/WeakCache.h b/dep/include/g3dlite/G3D/WeakCache.h deleted file mode 100644 index f9fdc4bbd5b..00000000000 --- a/dep/include/g3dlite/G3D/WeakCache.h +++ /dev/null @@ -1,122 +0,0 @@ -/** - @file WeakCache.h - - @maintainer Morgan McGuire, graphics3d.com - - @created 2007-05-16 - @edited 2007-05-16 - - Copyright 2000-2007, Morgan McGuire. - All rights reserved. - */ -#ifndef G3D_WEAKCACHE_H -#define G3D_WEAKCACHE_H - -#include "G3D/ReferenceCount.h" -#include "G3D/Table.h" - -namespace G3D { - -/** - A cache that does not prevent its members from being garbage collected. - Useful to avoid loading or computing an expression twice. Useful - for memoization and dynamic programming. - - Maintains a table of weak pointers. Weak pointers do not prevent - an object from being garbage collected. If the object is garbage - collected, the cache removes its reference. - - There are no "contains" or "iterate" methods because elements can be - flushed from the cache at any time if they are garbage collected. - - Example: - <pre> - WeakCache<std::string, TextureRef> textureCache; - - TextureRef loadTexture(std::string s) { - TextureRef t = textureCache[s]; - - if (t.isNull()) { - t = Texture::fromFile(s); - textureCache.set(s, t); - } - - return t; - } - - - </pre> - */ -template<class Key, class ValueRef> -class WeakCache { - typedef WeakReferenceCountedPointer<typename ValueRef::element_type> ValueWeakRef; - -private: - - Table<Key, ValueWeakRef> table; - -public: - /** - Returns NULL if the object is not in the cache - */ - ValueRef operator[](const Key& k) { - if (table.containsKey(k)) { - ValueWeakRef w = table[k]; - ValueRef s = w.createStrongPtr(); - if (s.isNull()) { - // This object has been collected; clean out its key - table.remove(k); - } - return s; - } else { - return NULL; - } - } - - void set(const Key& k, ValueRef v) { - table.set(k, v); - } - - /** Removes k from the cache or does nothing if it is not currently in the cache.*/ - void remove(const Key& k) { - if (table.containsKey(k)) { - table.remove(k); - } - } -}; - -#if 0 // To turn off all WeakCaching -template<class Key, class ValueRef> -class WeakCache { -private: - - Table<Key, ValueRef> table; - -public: - /** - Returns NULL if the object is not in the cache - */ - ValueRef operator[](const Key& k) { - if (table.containsKey(k)) { - return table[k]; - } else { - return NULL; - } - } - - void set(const Key& k, ValueRef v) { - table.set(k, v); - } - - /** Removes k from the cache or does nothing if it is not currently in the cache.*/ - void remove(const Key& k) { - if (table.containsKey(k)) { - table.remove(k); - } - } -}; -#endif - -} -#endif - |
