00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 #ifndef TOXIC_DRIVER_REPOSITORY_H
00024 #define TOXIC_DRIVER_REPOSITORY_H
00025
00026 #include "renderer/globals.h"
00027
00028 #include <map>
00029 #include <string>
00030
00031 namespace toxic {
00032
00033 #define DEFINE_EXCEPTION(e) \
00034 struct e { \
00035 e(const std::string &key) : \
00036 m_key(key) {} \
00037 std::string m_key; \
00038 };
00039
00040 template<typename T>
00041 class Repository {
00042 public:
00043 DEFINE_EXCEPTION(DuplicateKeyException);
00044 DEFINE_EXCEPTION(InvalidKeyException);
00045
00046 virtual ~Repository() {}
00047
00048 virtual void Insert(const std::string &key, const T &object)
00049 throw(DuplicateKeyException);
00050
00051 virtual void Remove(const std::string &key)
00052 throw(InvalidKeyException);
00053
00054 virtual T &Find(const std::string &key)
00055 throw(InvalidKeyException);
00056
00057 virtual const T &Find(const std::string &key) const
00058 throw(InvalidKeyException);
00059
00060 virtual bool Contains(const std::string &key) const;
00061
00062 protected:
00063 typedef std::map<std::string, T> object_map;
00064
00065 object_map m_objects;
00066 };
00067
00068 #undef DEFINE_EXCEPTION
00069
00070 #include "repository.inl"
00071
00072 }
00073
00074 #endif // !TOXIC_DRIVER_REPOSITORY_H