1 /** DataSet is a generic resource database with fast O(logn) lookups by name
2 * it can be used for texture managers, mesh managers, sound effect managers etc
4 * The constructor takes a load function and a destructor function to be called
5 * when a nonexistent resource is requested and needs to be loaded, and when
6 * the DataSet is destroyed. The destructor is optional and can be set to null
9 * Requesting a resource works by simply calling get, example:
10 * ----------------------------------------------------------
12 * Texture *load_texture(const char *fname);
13 * void free_texture(Texture *tex);
15 * DataSet<Texture*> texman(load_texture, free_texture);
16 * Texture *foo = texman.get("foo.png");
29 mutable std::map<std::string, T> data;
30 mutable struct resman *rman;
33 bool (*load)(T, const char*);
37 static int dataset_load_func(const char *fname, int id, void *cls);
38 static int dataset_done_func(int id, void *cls);
39 static void dataset_destroy_func(int id, void *cls);
42 DataSet(T (*create_func)(), bool (*load_func)(T, const char*), bool (*done_func)(T) = 0, void (*destr_func)(T) = 0);
48 T get(const char *name) const;
51 #include "dataset.inl"