goat3dgfx

annotate src/dataset.inl @ 18:6f82b9b6d6c3

added the ability to render in fixed function with the mesh class
author John Tsiombikas <nuclear@member.fsf.org>
date Sun, 08 Dec 2013 01:35:30 +0200
parents 18879c956eb1
children dc5918c62a64
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@15 5 namespace goatgfx {
nuclear@15 6
nuclear@0 7 template <typename T>
nuclear@0 8 DataSet<T>::DataSet(T (*load_func)(const char*), void (*destr_func)(T))
nuclear@0 9 {
nuclear@0 10 load = load_func;
nuclear@0 11 destroy = destr_func;
nuclear@0 12 }
nuclear@0 13
nuclear@0 14 template <typename T>
nuclear@0 15 DataSet<T>::~DataSet()
nuclear@0 16 {
nuclear@0 17 clear();
nuclear@0 18 }
nuclear@0 19
nuclear@0 20 template <typename T>
nuclear@0 21 void DataSet<T>::clear()
nuclear@0 22 {
nuclear@0 23 if(destroy) {
nuclear@0 24 typename std::map<std::string, T>::iterator it = data.begin();
nuclear@0 25 while(it != data.end()) {
nuclear@0 26 destroy(it++->second);
nuclear@0 27 }
nuclear@0 28 }
nuclear@0 29 data.clear();
nuclear@0 30 }
nuclear@0 31
nuclear@0 32 template <typename T>
nuclear@0 33 T DataSet<T>::get(const char *name) const
nuclear@0 34 {
nuclear@0 35 typename std::map<std::string, T>::const_iterator iter = data.find(name);
nuclear@0 36 if(iter != data.end()) {
nuclear@0 37 return iter->second;
nuclear@0 38 }
nuclear@0 39
nuclear@15 40 std::string path = goatgfx::datafile_path(name);
nuclear@0 41 if(path.empty()) {
nuclear@0 42 fprintf(stderr, "can't find data file: %s\n", name);
nuclear@0 43 return 0;
nuclear@0 44 }
nuclear@0 45
nuclear@0 46 T res = load(path.c_str());
nuclear@0 47 if(res) {
nuclear@0 48 data[name] = res;
nuclear@0 49 }
nuclear@0 50 return res;
nuclear@0 51 }
nuclear@15 52
nuclear@15 53 } // namespace goatgfx