1 /*=========================================================================
3 Program: Insight Segmentation & Registration Toolkit
4 Module: $RCSfile: cmListFileCache.cxx,v $
6 Date: $Date: 2002-04-11 21:02:10 $
7 Version: $Revision: 1.5 $
9 Copyright (c) 2002 Insight Consortium. All rights reserved.
10 See ITKCopyright.txt or http://www.itk.org/HTML/Copyright.htm for details.
12 This software is distributed WITHOUT ANY WARRANTY; without even
13 the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
14 PURPOSE. See the above copyright notices for more information.
16 =========================================================================*/
17 #include "cmListFileCache.h"
18 #include "cmSystemTools.h"
21 cmListFileCache
* cmListFileCache::Instance
= 0;
24 cmListFileCache
* cmListFileCache::GetInstance()
26 if(!cmListFileCache::Instance
)
28 cmListFileCache::Instance
= new cmListFileCache
;
30 return cmListFileCache::Instance
;
34 void cmListFileCache::ClearCache()
36 delete cmListFileCache::Instance
;
37 cmListFileCache::Instance
= 0;
42 cmListFile
* cmListFileCache::GetFileCache(const char* path
)
44 ListFileMap::iterator sl
= m_ListFileCache
.find(path
);
45 if (sl
== m_ListFileCache
.end())
47 // if not already in the map, then parse and store the
49 if(!this->CacheFile(path
))
53 sl
= m_ListFileCache
.find(path
);
54 if (sl
== m_ListFileCache
.end())
56 cmSystemTools::Error("Fatal error, in cmListFileCache CacheFile failed",
61 cmListFile
& ret
= sl
->second
;
62 if(cmSystemTools::ModifiedTime(path
) > ret
.m_ModifiedTime
)
64 if(!this->CacheFile(path
))
70 sl
= m_ListFileCache
.find(path
);
78 bool cmListFileCache::CacheFile(const char* path
)
80 if(!cmSystemTools::FileExists(path
))
85 std::ifstream
fin(path
);
88 cmSystemTools::Error("cmListFileCache: error can not open file ", path
);
92 std::vector
<std::string
> arguments
;
94 inFile
.m_ModifiedTime
= cmSystemTools::ModifiedTime(path
);
98 cmListFileFunction inFunction
;
99 if(cmSystemTools::ParseFunction(fin
,
101 inFunction
.m_Arguments
,
104 inFile
.m_Functions
.push_back(inFunction
);
108 inFile
.m_ModifiedTime
= 0;
111 m_ListFileCache
[path
] = inFile
;