#include <emcache.h>
Collaboration diagram for EMAN::GlobalCache:
Public Member Functions | |
ImageIO * | get_imageio (const string &filename, int rw_mode) |
void | add_imageio (const string &filename, int rw_mode, ImageIO *io) |
Static Public Member Functions | |
static GlobalCache * | instance () |
Private Member Functions | |
GlobalCache () | |
GlobalCache (const GlobalCache &gc) | |
~GlobalCache () | |
Private Attributes | |
EMCache< ImageIO > * | imageio_cache |
map< string, int > | file_rw_dict |
Static Private Attributes | |
static GlobalCache * | global_cache = 0 |
It uses EMCache template in its internal implementation.
Definition at line 165 of file emcache.h.
GlobalCache::GlobalCache | ( | ) | [private] |
Definition at line 52 of file emcache.cpp.
References imageio_cache.
Referenced by instance().
00053 { 00054 imageio_cache = new EMCache < ImageIO > (8); 00055 }
GlobalCache::GlobalCache | ( | const GlobalCache & | gc | ) | [private] |
GlobalCache::~GlobalCache | ( | ) | [private] |
Definition at line 61 of file emcache.cpp.
References imageio_cache.
00062 { 00063 if(imageio_cache) 00064 { 00065 delete imageio_cache; 00066 imageio_cache = 0; 00067 } 00068 }
void GlobalCache::add_imageio | ( | const string & | filename, | |
int | rw_mode, | |||
ImageIO * | io | |||
) |
Definition at line 110 of file emcache.cpp.
References file_rw_dict, and imageio_cache.
Referenced by EMAN::EMUtil::get_imageio().
00111 { 00112 if (io) { 00113 file_rw_dict[filename] = rw_mode; 00114 imageio_cache->add(filename, io); 00115 } 00116 }
ImageIO * GlobalCache::get_imageio | ( | const string & | filename, | |
int | rw_mode | |||
) |
Definition at line 79 of file emcache.cpp.
References file_rw_dict, imageio_cache, EMAN::Util::is_file_exist(), EMAN::ImageIO::READ_ONLY, and EMAN::ImageIO::WRITE_ONLY.
Referenced by EMAN::EMUtil::get_imageio().
00080 { 00081 ImageIO *io = imageio_cache->get(filename); 00082 if (io) { 00083 bool need_remove = false; 00084 00085 int old_rw = file_rw_dict[filename]; 00086 00087 if (rw_mode == ImageIO::READ_ONLY) { 00088 if (old_rw == ImageIO::WRITE_ONLY) { 00089 need_remove = true; 00090 } 00091 } 00092 else if (rw_mode != old_rw) { 00093 need_remove = true; 00094 } 00095 else { 00096 if (!Util::is_file_exist(filename)) { 00097 need_remove = true; 00098 } 00099 } 00100 if (need_remove) { 00101 imageio_cache->remove(filename); 00102 io = 0; 00103 } 00104 } 00105 00106 return io; 00107 }
GlobalCache * GlobalCache::instance | ( | ) | [static] |
Definition at line 71 of file emcache.cpp.
References global_cache, and GlobalCache().
Referenced by EMAN::EMUtil::get_imageio().
00072 { 00073 if (!global_cache) { 00074 global_cache = new GlobalCache(); 00075 } 00076 return global_cache; 00077 }
map< string, int > EMAN::GlobalCache::file_rw_dict [private] |
GlobalCache * GlobalCache::global_cache = 0 [static, private] |
EMCache< ImageIO >* EMAN::GlobalCache::imageio_cache [private] |
Definition at line 174 of file emcache.h.
Referenced by add_imageio(), get_imageio(), GlobalCache(), and ~GlobalCache().