goat3dgfx
annotate src/dataset.inl @ 9:25b911c7c35c
fixed some line endings
fixed the cubemap2.jpg file in examples/cubemap/data which was resized improperly causing seams...
author | John Tsiombikas <nuclear@member.fsf.org> |
---|---|
date | Mon, 18 Nov 2013 04:10:19 +0200 |
parents | 1873dfd13f2d |
children | 7d6b667821cf |
rev | line source |
---|---|
nuclear@0 | 1 #include <stdio.h> |
nuclear@0 | 2 #include <string.h> |
nuclear@0 | 3 #include "datapath.h" |
nuclear@0 | 4 |
nuclear@0 | 5 template <typename T> |
nuclear@0 | 6 DataSet<T>::DataSet(T (*load_func)(const char*), void (*destr_func)(T)) |
nuclear@0 | 7 { |
nuclear@0 | 8 load = load_func; |
nuclear@0 | 9 destroy = destr_func; |
nuclear@0 | 10 } |
nuclear@0 | 11 |
nuclear@0 | 12 template <typename T> |
nuclear@0 | 13 DataSet<T>::~DataSet() |
nuclear@0 | 14 { |
nuclear@0 | 15 clear(); |
nuclear@0 | 16 } |
nuclear@0 | 17 |
nuclear@0 | 18 template <typename T> |
nuclear@0 | 19 void DataSet<T>::clear() |
nuclear@0 | 20 { |
nuclear@0 | 21 if(destroy) { |
nuclear@0 | 22 typename std::map<std::string, T>::iterator it = data.begin(); |
nuclear@0 | 23 while(it != data.end()) { |
nuclear@0 | 24 destroy(it++->second); |
nuclear@0 | 25 } |
nuclear@0 | 26 } |
nuclear@0 | 27 data.clear(); |
nuclear@0 | 28 } |
nuclear@0 | 29 |
nuclear@0 | 30 template <typename T> |
nuclear@0 | 31 T DataSet<T>::get(const char *name) const |
nuclear@0 | 32 { |
nuclear@0 | 33 typename std::map<std::string, T>::const_iterator iter = data.find(name); |
nuclear@0 | 34 if(iter != data.end()) { |
nuclear@0 | 35 return iter->second; |
nuclear@0 | 36 } |
nuclear@0 | 37 |
nuclear@5 | 38 std::string path = datafile_path(name); |
nuclear@0 | 39 if(path.empty()) { |
nuclear@0 | 40 fprintf(stderr, "can't find data file: %s\n", name); |
nuclear@0 | 41 return 0; |
nuclear@0 | 42 } |
nuclear@0 | 43 |
nuclear@0 | 44 T res = load(path.c_str()); |
nuclear@0 | 45 if(res) { |
nuclear@0 | 46 data[name] = res; |
nuclear@0 | 47 } |
nuclear@0 | 48 return res; |
nuclear@0 | 49 } |