goat3dgfx

annotate src/dataset.h @ 3:eb75bff21824

added convenience header file which includes everything else
author John Tsiombikas <nuclear@member.fsf.org>
date Sat, 16 Nov 2013 21:09:16 +0200
parents
children 7d6b667821cf
rev   line source
nuclear@0 1 /** DataSet is a generic resource database with fast O(logn) lookups by name
nuclear@0 2 * it can be used for texture managers, mesh managers, sound effect managers etc
nuclear@0 3 *
nuclear@0 4 * The constructor takes a load function and a destructor function to be called
nuclear@0 5 * when a nonexistent resource is requested and needs to be loaded, and when
nuclear@0 6 * the DataSet is destroyed. The destructor is optional and can be set to null
nuclear@0 7 * if not needed.
nuclear@0 8 *
nuclear@0 9 * Requesting a resource works by simply calling get, example:
nuclear@0 10 * ----------------------------------------------------------
nuclear@0 11 * \code
nuclear@0 12 * Texture *load_texture(const char *fname);
nuclear@0 13 * void free_texture(Texture *tex);
nuclear@0 14 *
nuclear@0 15 * DataSet<Texture*> texman(load_texture, free_texture);
nuclear@0 16 * Texture *foo = texman.get("foo.png");
nuclear@0 17 * \endcode
nuclear@0 18 */
nuclear@0 19 #ifndef DATASET_H_
nuclear@0 20 #define DATASET_H_
nuclear@0 21
nuclear@0 22 #include <string>
nuclear@0 23 #include <map>
nuclear@0 24
nuclear@0 25 template <typename T>
nuclear@0 26 class DataSet {
nuclear@0 27 protected:
nuclear@0 28 mutable std::map<std::string, T> data;
nuclear@0 29
nuclear@0 30 T (*load)(const char*);
nuclear@0 31 void (*destroy)(T);
nuclear@0 32
nuclear@0 33 public:
nuclear@0 34 DataSet(T (*load_func)(const char*), void (*destr_func)(T) = 0);
nuclear@0 35 ~DataSet();
nuclear@0 36
nuclear@0 37 void clear();
nuclear@0 38
nuclear@0 39 T get(const char *name) const;
nuclear@0 40 };
nuclear@0 41
nuclear@0 42 #include "dataset.inl"
nuclear@0 43
nuclear@0 44 #endif // DATASET_H_