]> git.treefish.org Git - phys/latlib.git/blob - configcache.h
Made c++11 standard dependency obsolete.
[phys/latlib.git] / configcache.h
1 #ifndef CONFIGCACHE_H
2 #define CONFIGCACHE_H
3
4 #include <vector>
5 #include <string>
6 #include <fstream>
7 #include <sstream>
8 #include <ostream>
9
10 #include "datread.h"
11
12 #define CACHE_MODE_OO 0
13 #define CACHE_MODE_RO 1
14 #define CACHE_MODE_WO 2
15 #define CACHE_MODE_RW 3
16
17 using namespace std;
18
19 struct parameter{
20   string id;
21   double val;
22 };
23
24 struct infiledesc {
25   string filename;
26   int nequi;
27   int nskip;
28   bool extended;
29   bool superextended;
30 };
31
32 class configcache{
33  public:
34   ~configcache();
35   configcache(const string& cacheid, const int& nequi, const int& nskip, const string& datadir, char **configmem, const int& configMemSize, 
36               const int& cachemode=CACHE_MODE_RW, ostream *_log=NULL);
37   void readConfig(bool *readnewconfig, int *nequileft, vector<unsigned long> *excludeFileHashes=NULL);
38   void writeConfig(int actnequi);
39   void addPara(const string& parid, const double& val=0);
40   void setPara(const string& parid, const double& value);
41   void writeHeader(const string& headerid, const char *header, long unsigned int size, int actnequi);
42   void * getHeader(const string& headerid);
43   string getOutFileName() { return outFileName.str(); }
44   string getInFileName() { return DATADIR + "/" + openFileDesc.filename; }
45   static unsigned long hash(const string& str);
46   void closeInFile() { dataReader->closeFile(); }
47   int inFilesLeft() { return inFiles.size(); }
48   char* getConfigMem() { return configMem; }
49   int getConfigSize() { return configSize; }
50   bool isOutFileOpen () { return outFile.is_open(); }
51   void finishOutFile();
52
53  private:
54   struct iobuffers;
55   iobuffers *ioBuffers;
56
57   ostream* log;
58   infiledesc openFileDesc;
59   int getParIndex(const string& parid);
60   int NEQUI;
61   int NSKIP;
62   string DATADIR;
63   string CACHEID;
64   int MODE;
65   string getFileId(int actnequi, const bool& superextended=true, const bool& shortid=false);
66
67   ofstream outFile;
68
69   stringstream outFileName;
70
71   int readnum;
72
73   int inSize;
74
75   int configSize;
76   char *configMem;
77   char *tmpConfig;
78
79   bool refetchDataFiles;
80
81   void fetchDataFiles();
82   
83   bool isValidInFile(const string& infile, infiledesc *filedesc);
84
85   vector<infiledesc> inFiles;
86
87   vector<parameter> Paras;
88
89   void openOutFile(int actnequi);
90
91   int readHeader();
92
93   bool headerWritten;
94
95   bool readAllHeaders();
96
97   vector<infiledesc>::iterator getNextInfile(vector<unsigned long> *excludeFileHashes);
98
99   int nequileft_internal;
100
101   bool doVirtualEquilibration, firstUsedConfig;
102
103   string paraString();
104
105   datread *dataReader;
106 };
107
108 #endif