2002-01-21 20:30:43 +00:00
|
|
|
/*=========================================================================
|
|
|
|
|
2002-10-23 22:03:27 +00:00
|
|
|
Program: CMake - Cross-Platform Makefile Generator
|
2002-01-21 20:30:43 +00:00
|
|
|
Module: $RCSfile$
|
|
|
|
Language: C++
|
|
|
|
Date: $Date$
|
|
|
|
Version: $Revision$
|
|
|
|
|
2002-10-23 22:03:27 +00:00
|
|
|
Copyright (c) 2002 Kitware, Inc., Insight Consortium. All rights reserved.
|
|
|
|
See Copyright.txt or http://www.cmake.org/HTML/Copyright.html for details.
|
2002-01-21 20:30:43 +00:00
|
|
|
|
|
|
|
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.
|
|
|
|
|
|
|
|
=========================================================================*/
|
2001-08-28 22:28:31 +00:00
|
|
|
#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)
|
|
|
|
{
|
2002-04-11 21:02:10 +00:00
|
|
|
if(!cmSystemTools::FileExists(path))
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2001-08-28 22:28:31 +00:00
|
|
|
std::ifstream fin(path);
|
|
|
|
if(!fin)
|
|
|
|
{
|
2002-04-11 21:02:10 +00:00
|
|
|
cmSystemTools::Error("cmListFileCache: error can not open file ", path);
|
2001-08-28 22:28:31 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
cmListFile inFile;
|
|
|
|
inFile.m_ModifiedTime = cmSystemTools::ModifiedTime(path);
|
2001-11-29 21:44:22 +00:00
|
|
|
bool parseError;
|
2001-08-28 22:28:31 +00:00
|
|
|
while ( fin )
|
|
|
|
{
|
|
|
|
cmListFileFunction inFunction;
|
|
|
|
if(cmSystemTools::ParseFunction(fin,
|
|
|
|
inFunction.m_Name,
|
2001-10-02 21:28:55 +00:00
|
|
|
inFunction.m_Arguments,
|
2001-11-29 21:44:22 +00:00
|
|
|
path, parseError))
|
2001-08-28 22:28:31 +00:00
|
|
|
{
|
|
|
|
inFile.m_Functions.push_back(inFunction);
|
|
|
|
}
|
2001-11-29 21:44:22 +00:00
|
|
|
if (parseError)
|
|
|
|
{
|
|
|
|
inFile.m_ModifiedTime = 0;
|
|
|
|
}
|
2001-08-28 22:28:31 +00:00
|
|
|
}
|
|
|
|
m_ListFileCache[path] = inFile;
|
|
|
|
return true;
|
|
|
|
}
|
2002-09-19 18:34:15 +00:00
|
|
|
|
|
|
|
void cmListFileCache::FlushCache(const char* path)
|
|
|
|
{
|
|
|
|
ListFileMap::iterator it = m_ListFileCache.find(path);
|
|
|
|
if ( it != m_ListFileCache.end() )
|
|
|
|
{
|
|
|
|
m_ListFileCache.erase(it);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|