goat3dgfx
view src/dataset.inl @ 22:92bfb0206969
- made all XFormNode functions virtual
- added XFormNode::get_parent()
author | John Tsiombikas <nuclear@member.fsf.org> |
---|---|
date | Sat, 28 Dec 2013 06:48:23 +0200 |
parents | 18879c956eb1 |
children | dc5918c62a64 |
line source
1 #include <stdio.h>
2 #include <string.h>
3 #include "datapath.h"
5 namespace goatgfx {
7 template <typename T>
8 DataSet<T>::DataSet(T (*load_func)(const char*), void (*destr_func)(T))
9 {
10 load = load_func;
11 destroy = destr_func;
12 }
14 template <typename T>
15 DataSet<T>::~DataSet()
16 {
17 clear();
18 }
20 template <typename T>
21 void DataSet<T>::clear()
22 {
23 if(destroy) {
24 typename std::map<std::string, T>::iterator it = data.begin();
25 while(it != data.end()) {
26 destroy(it++->second);
27 }
28 }
29 data.clear();
30 }
32 template <typename T>
33 T DataSet<T>::get(const char *name) const
34 {
35 typename std::map<std::string, T>::const_iterator iter = data.find(name);
36 if(iter != data.end()) {
37 return iter->second;
38 }
40 std::string path = goatgfx::datafile_path(name);
41 if(path.empty()) {
42 fprintf(stderr, "can't find data file: %s\n", name);
43 return 0;
44 }
46 T res = load(path.c_str());
47 if(res) {
48 data[name] = res;
49 }
50 return res;
51 }
53 } // namespace goatgfx