goat3dgfx
view src/dataset.inl @ 5:18879c956eb1
- skycube example
- added fatal_log
- changed the dataset to keep the whole path while searching for data files
author | John Tsiombikas <nuclear@member.fsf.org> |
---|---|
date | Sun, 17 Nov 2013 03:22:40 +0200 |
parents | 1873dfd13f2d |
children | 7d6b667821cf |
line source
1 #include <stdio.h>
2 #include <string.h>
3 #include "datapath.h"
5 template <typename T>
6 DataSet<T>::DataSet(T (*load_func)(const char*), void (*destr_func)(T))
7 {
8 load = load_func;
9 destroy = destr_func;
10 }
12 template <typename T>
13 DataSet<T>::~DataSet()
14 {
15 clear();
16 }
18 template <typename T>
19 void DataSet<T>::clear()
20 {
21 if(destroy) {
22 typename std::map<std::string, T>::iterator it = data.begin();
23 while(it != data.end()) {
24 destroy(it++->second);
25 }
26 }
27 data.clear();
28 }
30 template <typename T>
31 T DataSet<T>::get(const char *name) const
32 {
33 typename std::map<std::string, T>::const_iterator iter = data.find(name);
34 if(iter != data.end()) {
35 return iter->second;
36 }
38 std::string path = datafile_path(name);
39 if(path.empty()) {
40 fprintf(stderr, "can't find data file: %s\n", name);
41 return 0;
42 }
44 T res = load(path.c_str());
45 if(res) {
46 data[name] = res;
47 }
48 return res;
49 }