Main Page | Modules | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members

EMAN::GlobalCache Class Reference

GlobalCache is a Singleton class that handles cache across EMAN. More...

#include <emcache.h>

Collaboration diagram for EMAN::GlobalCache:

Collaboration graph
[legend]
List of all members.

Public Member Functions

ImageIOget_imageio (const string &filename, int rw_mode)
void add_imageio (const string &filename, int rw_mode, ImageIO *io)

Static Public Member Functions

GlobalCacheinstance ()

Private Member Functions

 GlobalCache ()
 GlobalCache (const GlobalCache &gc)
 ~GlobalCache ()

Private Attributes

EMCache< ImageIO > * imageio_cache
map< string, int > file_rw_dict

Static Private Attributes

GlobalCacheglobal_cache = 0

Detailed Description

GlobalCache is a Singleton class that handles cache across EMAN.

It uses EMCache template in its internal implementation.

Definition at line 165 of file emcache.h.


Constructor & Destructor Documentation

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]
 

Definition at line 57 of file emcache.cpp.

00058 {
00059 }

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 }


Member Function Documentation

void GlobalCache::add_imageio const string &  filename,
int  rw_mode,
ImageIO io
 

Definition at line 110 of file emcache.cpp.

References EMAN::EMCache< T >::add(), 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, EMAN::EMCache< T >::get(), imageio_cache, EMAN::Util::is_file_exist(), and EMAN::EMCache< T >::remove().

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 }


Member Data Documentation

map< string, int > EMAN::GlobalCache::file_rw_dict [private]
 

Definition at line 176 of file emcache.h.

Referenced by add_imageio(), and get_imageio().

GlobalCache * GlobalCache::global_cache = 0 [static, private]
 

Definition at line 50 of file emcache.cpp.

Referenced by instance().

EMCache< ImageIO >* EMAN::GlobalCache::imageio_cache [private]
 

Definition at line 174 of file emcache.h.

Referenced by add_imageio(), get_imageio(), GlobalCache(), and ~GlobalCache().


The documentation for this class was generated from the following files:
Generated on Tue Jun 11 13:48:00 2013 for EMAN2 by  doxygen 1.3.9.1