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

emcache.cpp

Go to the documentation of this file.
00001 
00005 /*
00006  * Author: Steven Ludtke, 04/10/2003 (sludtke@bcm.edu)
00007  * Copyright (c) 2000-2006 Baylor College of Medicine
00008  * 
00009  * This software is issued under a joint BSD/GNU license. You may use the
00010  * source code in this file under either license. However, note that the
00011  * complete EMAN2 and SPARX software packages have some GPL dependencies,
00012  * so you are responsible for compliance with the licenses of these packages
00013  * if you opt to use BSD licensing. The warranty disclaimer below holds
00014  * in either instance.
00015  * 
00016  * This complete copyright notice must be included in any revised version of the
00017  * source code. Additional authorship citations may be added, but existing
00018  * author citations must be preserved.
00019  * 
00020  * This program is free software; you can redistribute it and/or modify
00021  * it under the terms of the GNU General Public License as published by
00022  * the Free Software Foundation; either version 2 of the License, or
00023  * (at your option) any later version.
00024  * 
00025  * This program is distributed in the hope that it will be useful,
00026  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00027  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
00028  * GNU General Public License for more details.
00029  * 
00030  * You should have received a copy of the GNU General Public License
00031  * along with this program; if not, write to the Free Software
00032  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
00033  * 
00034  * */
00035  
00036 #include "emcache.h"
00037 #include "imageio.h"
00038 #include "util.h"
00039 
00040 #ifdef WIN32
00041 #define access _access
00042 #define F_OK 00
00043 #else
00044 #include <unistd.h>
00045 #endif
00046 
00047 
00048 using namespace EMAN;
00049 
00050 GlobalCache *GlobalCache::global_cache = 0;
00051 
00052 GlobalCache::GlobalCache()
00053 {
00054         imageio_cache = new EMCache < ImageIO > (8);
00055 }
00056 
00057 GlobalCache::GlobalCache(const GlobalCache &)
00058 {
00059 }
00060 
00061 GlobalCache::~GlobalCache()
00062 {
00063         if(imageio_cache)
00064         {
00065                 delete imageio_cache;
00066                 imageio_cache = 0;
00067         }
00068 }
00069 
00070 
00071 GlobalCache *GlobalCache::instance()
00072 {
00073         if (!global_cache) {
00074                 global_cache = new GlobalCache();
00075         }
00076         return global_cache;
00077 }
00078 
00079 ImageIO *GlobalCache::get_imageio(const string & filename, int rw_mode)
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 }
00108 
00109 
00110 void GlobalCache::add_imageio(const string & filename, int rw_mode, ImageIO * io)
00111 {
00112         if (io) {
00113                 file_rw_dict[filename] = rw_mode;
00114                 imageio_cache->add(filename, io);
00115         }
00116 }
00117 

Generated on Tue Jun 11 13:40:37 2013 for EMAN2 by  doxygen 1.3.9.1