| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121 |
- /*=========================================================================
- Program: Insight Segmentation & Registration Toolkit
- Module: $RCSfile$
- Language: C++
- Date: $Date$
- Version: $Revision$
- Copyright (c) 2002 Insight Consortium. All rights reserved.
- See ITKCopyright.txt or http://www.itk.org/HTML/Copyright.htm for details.
- This software is distributed WITHOUT ANY WARRANTY; without even
- the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
- PURPOSE. See the above copyright notices for more information.
- =========================================================================*/
- #include "cmListFileCache.h"
- #include "cmSystemTools.h"
- cmListFileCache* cmListFileCache::Instance = 0;
- cmListFileCache* cmListFileCache::GetInstance()
- {
- if(!cmListFileCache::Instance)
- {
- cmListFileCache::Instance = new cmListFileCache;
- }
- return cmListFileCache::Instance;
- }
- void cmListFileCache::ClearCache()
- {
- delete cmListFileCache::Instance;
- cmListFileCache::Instance = 0;
- }
- cmListFile* cmListFileCache::GetFileCache(const char* path)
- {
- ListFileMap::iterator sl = m_ListFileCache.find(path);
- if (sl == m_ListFileCache.end())
- {
- // if not already in the map, then parse and store the
- // file
- if(!this->CacheFile(path))
- {
- return 0;
- }
- sl = m_ListFileCache.find(path);
- if (sl == m_ListFileCache.end())
- {
- cmSystemTools::Error("Fatal error, in cmListFileCache CacheFile failed",
- path);
- return 0;
- }
- }
- cmListFile& ret = sl->second;
- if(cmSystemTools::ModifiedTime(path) > ret.m_ModifiedTime )
- {
- if(!this->CacheFile(path))
- {
- return 0;
- }
- else
- {
- sl = m_ListFileCache.find(path);
- return &sl->second;
- }
- }
- return &ret;
- }
- bool cmListFileCache::CacheFile(const char* path)
- {
- if(!cmSystemTools::FileExists(path))
- {
- return false;
- }
-
- std::ifstream fin(path);
- if(!fin)
- {
- cmSystemTools::Error("cmListFileCache: error can not open file ", path);
- return false;
- }
- cmListFile inFile;
- inFile.m_ModifiedTime = cmSystemTools::ModifiedTime(path);
- bool parseError;
- while ( fin )
- {
- cmListFileFunction inFunction;
- if(cmSystemTools::ParseFunction(fin,
- inFunction.m_Name,
- inFunction.m_Arguments,
- path, parseError))
- {
- inFile.m_Functions.push_back(inFunction);
- }
- if (parseError)
- {
- inFile.m_ModifiedTime = 0;
- }
- }
- m_ListFileCache[path] = inFile;
- return true;
- }
- void cmListFileCache::FlushCache(const char* path)
- {
- ListFileMap::iterator it = m_ListFileCache.find(path);
- if ( it != m_ListFileCache.end() )
- {
- m_ListFileCache.erase(it);
- return;
- }
- }
|