]> 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 class configcache{
29  public:
30   ~configcache();
31   configcache(const string& cacheid, const int& nequi, const int& nskip, const string& datadir, char **configmem, const int& configMemSize, 
32               const int& cachemode=CACHE_MODE_FULL, writeout *out_a=NULL);
33   bool readConfig();
34   void writeConfig();
35   void addPara(const string& parid, const double& val=0);
36   void setPara(const string& parid, const double& value);
37   
38  private:
39   void finishOutFile();
40   int getParIndex(const string& parid);
41   int NEQUI;
42   int NSKIP;
43   string DATADIR;
44   string CACHEID;
45   int MODE;
46   string getFileId(const bool& shortid=false);
47
48   ofstream outFile;
49   ifstream inFile;
50
51   writeout *out;
52
53   stringstream outFileName;
54
55   int readnum;
56
57   boost::iostreams::filtering_istreambuf *inBuffer;
58   boost::iostreams::filtering_ostreambuf *outBuffer;
59
60   int inSize;
61
62   int configSize;
63   char *configMem;
64   char *tmpConfig;
65
66   bool refetchDataFiles;
67
68   void fetchDataFiles();
69   
70   bool isValidInFile(const string& infile);
71
72   vector<string> inFiles;
73
74   vector<parameter> Paras;
75 };
76
77 #endif