1 #include "hypercache.h"
3 hypercache::defaults *hypercache::Defaults = NULL;
4 configcache *hypercache::O = NULL;
5 configcache *hypercache::C = NULL;
7 void hypercache::initCache(configcache *cache,
8 const string& cacheid, const int& nequi, const int& nskip, const string& datadir,
9 char **configmem, const int& configMemSize, const int& cachemode, writeout *out_a) {
11 bool allInitBefore = true;
13 if (O == NULL || C == NULL)
14 allInitBefore = false;
16 cache = new configcache(cacheid, nequi, nskip, datadir, configmem, configMemSize, cachemode, out_a);
18 if (Defaults == NULL) {
19 Defaults = new defaults;
20 Defaults->nequi = nequi;
21 Defaults->nskip = nskip;
22 Defaults->datadir = datadir;
23 Defaults->out = out_a;
26 if (O != NULL && C != NULL && !allInitBefore) {
27 for (vector<para>::iterator parit=delayedParaAdd.begin(); parit != delayedParaAdd.end(); ++parit) {
28 O->addPara(parit->parid, parit->val);
29 C->addPara(parit->parid, parit->val);
31 for (vector<para>::iterator parit=delayedParaSet.begin(); parit != delayedParaSet.end(); ++parit) {
32 O->setPara(parit->parid, parit->val);
33 C->setPara(parit->parid, parit->val);
38 void hypercache::initCache(configcache *cache, const string& subdir,
39 const string& cacheid, char **configmem, const int& configMemSize, const int& cachemode) {
40 if (Defaults == NULL) {
41 cerr << "Defaults were not initialized prior to short initialization!" << endl;
45 initCache(cache, cacheid, Defaults->nequi, Defaults->nskip, Defaults->datadir + "/" + subdir,
46 configmem, configMemSize, cachemode, Defaults->out);
49 void hypercache::addPara(const string& parid, const double& val) {
50 if (O == NULL || C == NULL) {
52 newpara.parid = parid;
54 delayedParaAdd.push_back(newpara);
57 O->addPara(parid, val);
58 C->addPara(parid, val);
62 void hypercache::setPara(const string& parid, const double& val) {
63 if (O == NULL || C == NULL) {
65 newpara.parid = parid;
67 delayedParaSet.push_back(newpara);
70 O->setPara(parid, val);
71 C->setPara(parid, val);