#ifndef DATASET_H_
#define DATASET_H_
+#include <vector>
#include <string>
#include <map>
#include <resman.h>
template <typename T>
class DataSet {
+public:
+ typedef void (*LoadedCallbackFunc)(T, void*);
+
protected:
mutable std::map<std::string, T> data;
mutable struct resman *rman;
+ std::vector<std::pair<LoadedCallbackFunc, void*> > loaded_cb;
+
T (*create)();
bool (*load)(T, const char*);
bool (*done)(T);
void update();
T get(const char *name) const;
+
+ void add_loaded_callback(LoadedCallbackFunc func, void *cls = 0);
+ bool remove_loaded_callback(LoadedCallbackFunc func);
};
#include "dataset.inl"
return res;
}
+template <typename T>
+void DataSet<T>::add_loaded_callback(LoadedCallbackFunc func, void *cls)
+{
+ std::pair<LoadedCallbackFunc, void*> cb;
+ cb.first = func;
+ cb.second = cls;
+ loaded_cb.push_back(cb);
+}
+
+template <typename T>
+bool DataSet<T>::remove_loaded_callback(LoadedCallbackFunc func)
+{
+ int numcb = (int)loaded_cb.size();
+ for(int i=0; i<numcb; i++) {
+ if(loaded_cb[i].first == func) {
+ loaded_cb.erase(loaded_cb.begin() + i);
+ return true;
+ }
+ }
+ return false;
+}
+
// --- static functions to pass as callback to resman ---
if(dset->done) {
dset->done(data);
}
+
+ int numcb = (int)dset->loaded_cb.size();
+ for(int i=0; i<numcb; i++) {
+ dset->loaded_cb[i].first(data, dset->loaded_cb[i].second);
+ }
return 0;
}