cmListFileCache.h 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. /*=========================================================================
  2. Program: CMake - Cross-Platform Makefile Generator
  3. Module: $RCSfile$
  4. Language: C++
  5. Date: $Date$
  6. Version: $Revision$
  7. Copyright (c) 2002 Kitware, Inc., Insight Consortium. All rights reserved.
  8. See Copyright.txt or http://www.cmake.org/HTML/Copyright.html for details.
  9. This software is distributed WITHOUT ANY WARRANTY; without even
  10. the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
  11. PURPOSE. See the above copyright notices for more information.
  12. =========================================================================*/
  13. #ifndef cmListFileCache_h
  14. #define cmListFileCache_h
  15. #include "cmStandardIncludes.h"
  16. /** \class cmListFileCache
  17. * \brief A class to cache list file contents.
  18. *
  19. * cmListFileCache is a class used to cache the contents of parsed
  20. * cmake list files.
  21. */
  22. struct cmListFileArgument
  23. {
  24. cmListFileArgument(): Value(), Quoted(false), FilePath(0), Line(0) {}
  25. cmListFileArgument(const cmListFileArgument& r):
  26. Value(r.Value), Quoted(r.Quoted), FilePath(r.FilePath), Line(r.Line) {}
  27. cmListFileArgument(const std::string& v, bool q, const char* file,
  28. long line): Value(v), Quoted(q),
  29. FilePath(file), Line(line) {}
  30. bool operator == (const cmListFileArgument& r) const
  31. {
  32. return (this->Value == r.Value) && (this->Quoted == r.Quoted);
  33. }
  34. bool operator != (const cmListFileArgument& r) const
  35. {
  36. return !(*this == r);
  37. }
  38. std::string Value;
  39. bool Quoted;
  40. const char* FilePath;
  41. long Line;
  42. };
  43. struct cmListFileFunction
  44. {
  45. std::string m_Name;
  46. std::vector<cmListFileArgument> m_Arguments;
  47. const char* m_FilePath;
  48. long m_Line;
  49. };
  50. struct cmListFile
  51. {
  52. cmListFile()
  53. :m_ModifiedTime(0)
  54. {
  55. }
  56. long int m_ModifiedTime;
  57. std::vector<cmListFileFunction> m_Functions;
  58. };
  59. class cmListFileCache
  60. {
  61. public:
  62. static cmListFileCache* GetInstance();
  63. static void ClearCache();
  64. /** Return the cached version of the given file.
  65. * If the file is not already in the cache, a cache entry
  66. * will be made. If there is an error loading the file,
  67. * NULL is returned. If requireProjectCommand is true,
  68. * then a PROJECT(Project) command will be added to the file
  69. * if it does not have a PROJECT command in it.
  70. */
  71. cmListFile* GetFileCache(const char* path, bool requireProjectCommand);
  72. //! Flush cache file out of cache.
  73. void FlushCache(const char* path);
  74. ~cmListFileCache();
  75. private:
  76. // Cache the file
  77. bool CacheFile(const char* path, bool requireProjectCommand);
  78. // private data
  79. typedef std::map<cmStdString, cmListFile> ListFileMap;
  80. ListFileMap m_ListFileCache; // file name to ListFile map
  81. typedef std::map<cmStdString, char*> UniqueStrings;
  82. UniqueStrings m_UniqueStrings;
  83. const char* GetUniqueStringPointer(const char* name);
  84. static cmListFileCache* Instance; // singelton pointer
  85. };
  86. #endif