32#ifndef eman__hdf_filecache__h__
33#define eman__hdf_filecache__h__ 1
45using std::binary_function;
47const static int CHECK_INTERVAL = 5;
48const static int ACCESS_TIME_THRESHOLD = 30;
49const static int ACCESS_WRITE_TIME_THRESHOLD = 5;
62 FileItem(
const string& fpath, ImageIO*
const fimageio,
const time_t& ftimestamp,
bool freadonly);
68 int set_imgio(ImageIO*
const fimageio);
69 ImageIO * get_imgio()
const;
71 int set_timestamp(
const time_t& ftimestamp);
72 time_t get_timestamp()
const;
74 int set_readonly(
bool freadonly);
75 bool get_readonly()
const;
88 static HDFCache *instance();
91 FileItem * get_file(
const string& filename);
93 int add_file(FileItem * newfile);
97 HDFCache(
const HDFCache&);
100 static HDFCache * _instance;
103 typedef boost::unordered_map<string, FileItem *> MyHashtable;
104 MyHashtable file_pool;
107 vector<FileItem *> file_pool2;
109 boost::thread _thread;
110 boost::mutex m_mutex;
117 void cache_routine();
118 int close_file(
const string& filename);
121 struct least_access :
public binary_function<FileItem *, FileItem *, bool>{
123 return x->get_timestamp() <
y->get_timestamp();
128 struct access_time_cmp :
public binary_function<FileItem *, int, bool>{
129 bool operator()(FileItem * f,
int interval)
const {
130 return f->get_timestamp() < time(0)-ACCESS_TIME_THRESHOLD;
float & operator()(const int ix, const int iy, const int iz) const
Overload operator() for array indexing.