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");
30 typedef void (*LoadedCallbackFunc)(T, void*);
33 mutable std::map<std::string, T> data;
34 mutable struct resman *rman;
36 std::vector<std::pair<LoadedCallbackFunc, void*> > loaded_cb;
39 bool (*load)(T, const char*);
43 static int dataset_load_func(const char *fname, int id, void *cls);
44 static int dataset_done_func(int id, void *cls);
45 static void dataset_destroy_func(int id, void *cls);
48 DataSet(T (*create_func)(), bool (*load_func)(T, const char*), bool (*done_func)(T) = 0, void (*destr_func)(T) = 0);
54 T get(const char *name) const;
56 void add_loaded_callback(LoadedCallbackFunc func, void *cls = 0);
57 bool remove_loaded_callback(LoadedCallbackFunc func);
60 #include "dataset.inl"