]> git.treefish.org Git - phys/latlib.git/blob - configcache.h
...
[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
9 #include <boost/iostreams/filtering_streambuf.hpp>
10 #include <boost/iostreams/stream.hpp>
11 #include <boost/iostreams/filter/bzip2.hpp>
12 #include <boost/iostreams/device/array.hpp>
13 #include <boost/iostreams/copy.hpp>
14
15 #include "writeout.h"
16
17 #define CACHE_MODE_DISABLED 0
18 #define CACHE_MODE_READ 1
19 #define CACHE_MODE_FULL 2
20
21 using namespace std;
22
23 struct parameter{
24   string id;
25   double val;
26 };
27
28 struct infiledesc {
29   string filename;
30   int nequi;
31   int nskip;
32   bool doVirtualEquilibration;
33   bool extended;
34 };
35
36 class configcache{
37  public:
38   ~configcache();
39   configcache(const string& cacheid, const int& nequi, const int& nskip, const string& datadir, char **configmem, const int& configMemSize, 
40               const int& cachemode=CACHE_MODE_FULL, writeout *out_a=NULL);
41   bool readConfig();
42   void writeConfig();
43   void addPara(const string& parid, const double& val=0);
44   void setPara(const string& parid, const double& value);
45   void writeHeader(char *header, const int& size);
46   void *getHeader();
47   
48  private:
49   infiledesc openFileDesc;
50   void finishOutFile();
51   int getParIndex(const string& parid);
52   int NEQUI;
53   int NSKIP;
54   string DATADIR;
55   string CACHEID;
56   int MODE;
57   string getFileId(const bool& shortid=false);
58
59   ofstream outFile;
60   ifstream inFile;
61
62   writeout *out;
63
64   stringstream outFileName;
65
66   int readnum;
67
68   boost::iostreams::filtering_istreambuf *inBuffer;
69   boost::iostreams::filtering_ostreambuf *outBuffer;
70
71   int inSize;
72
73   int configSize;
74   char *configMem;
75   char *tmpConfig;
76
77   bool refetchDataFiles;
78
79   void fetchDataFiles();
80   
81   bool isValidInFile(const string& infile, infiledesc *filedesc);
82
83   vector<infiledesc> inFiles;
84
85   vector<parameter> Paras;
86
87   int readDataToMem(char *tmpData, long unsigned int dataSize);
88
89   void openOutFile();
90   bool openInFile();
91
92   char *headerData;
93
94   void readHeader();
95 };
96
97 #endif