goat3dgfx

view src/dataset.h @ 20:d9c8cd19c606

fixed the face index loading bug
author John Tsiombikas <nuclear@member.fsf.org>
date Sun, 08 Dec 2013 03:00:49 +0200
parents 1873dfd13f2d
children dc5918c62a64
line source
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
3 *
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
7 * if not needed.
8 *
9 * Requesting a resource works by simply calling get, example:
10 * ----------------------------------------------------------
11 * \code
12 * Texture *load_texture(const char *fname);
13 * void free_texture(Texture *tex);
14 *
15 * DataSet<Texture*> texman(load_texture, free_texture);
16 * Texture *foo = texman.get("foo.png");
17 * \endcode
18 */
19 #ifndef DATASET_H_
20 #define DATASET_H_
22 #include <string>
23 #include <map>
25 namespace goatgfx {
27 template <typename T>
28 class DataSet {
29 protected:
30 mutable std::map<std::string, T> data;
32 T (*load)(const char*);
33 void (*destroy)(T);
35 public:
36 DataSet(T (*load_func)(const char*), void (*destr_func)(T) = 0);
37 ~DataSet();
39 void clear();
41 T get(const char *name) const;
42 };
44 } // namespace goatgfx
46 #include "dataset.inl"
48 #endif // DATASET_H_