diff options
Diffstat (limited to 'project2/common/instanceStore.h')
-rw-r--r-- | project2/common/instanceStore.h | 52 |
1 files changed, 0 insertions, 52 deletions
diff --git a/project2/common/instanceStore.h b/project2/common/instanceStore.h deleted file mode 100644 index 4fd4519..0000000 --- a/project2/common/instanceStore.h +++ /dev/null @@ -1,52 +0,0 @@ -#ifndef INSTANCESTORE_H -#define INSTANCESTORE_H - -#include <boost/function.hpp> -#include <set> -#include <map> -#include <safeMapFind.h> - -/// A static collection of any type, specifically with automatically cleaned up storage of a function static variable -// which makes it safe to use in constructor functions. -template <class Type, class StoreType> -class InstanceStore { - public: - static const StoreType & GetAll(); - static void Add(const typename StoreType::value_type & p); - - protected: - static void prune(); - static StoreType * & getInstances(); -}; - -/// Keyed collection of instances -template <class Type, class KeyType> -class InstanceMap : public InstanceStore<Type, std::map<KeyType, boost::shared_ptr<Type>>> { - public: - typedef std::map<KeyType, boost::shared_ptr<Type>> Store; - typedef InstanceStore<Type, std::map<KeyType, boost::shared_ptr<Type>>> IStore; - typedef typename Store::value_type Value; - - static void Add(const KeyType & k, Type * p); - static void Add(const KeyType & k, const boost::shared_ptr<Type> & p); - static void Remove(const KeyType &); - - template <class E> static boost::shared_ptr<Type> Get(const KeyType & n) - { - return AdHoc::safeMapLookup<E>(InstanceStore<Type, Store>::GetAll(), n); - } - - static void OnEach(const boost::function<void(const Value &)> & func); -}; - -/// Anonymous collection of instances -template <class Type> -class InstanceSet : public InstanceStore<Type, std::set<boost::shared_ptr<Type>>> { - public: - typedef InstanceStore<Type, std::set<boost::shared_ptr<Type>>> IStore; - static void OnAll(const boost::function<void(Type *)> & func); - static void Remove(const boost::shared_ptr<Type> &); -}; - -#endif - |