]> git.treefish.org Git - phys/latlib.git/blob - configcache.h
refined exceptions.
[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   string openFileName;
40   void finishOutFile();
41   int getParIndex(const string& parid);
42   int NEQUI;
43   int NSKIP;
44   string DATADIR;
45   string CACHEID;
46   int MODE;
47   string getFileId(const bool& shortid=false);
48
49   ofstream outFile;
50   ifstream inFile;
51
52   writeout *out;
53
54   stringstream outFileName;
55
56   int readnum;
57
58   boost::iostreams::filtering_istreambuf *inBuffer;
59   boost::iostreams::filtering_ostreambuf *outBuffer;
60
61   int inSize;
62
63   int configSize;
64   char *configMem;
65   char *tmpConfig;
66
67   bool refetchDataFiles;
68
69   void fetchDataFiles();
70   
71   bool isValidInFile(const string& infile);
72
73   vector<string> inFiles;
74
75   vector<parameter> Paras;
76 };
77
78 #endif