cmCacheManager.h 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. /*=========================================================================
  2. Program: Insight Segmentation & Registration Toolkit
  3. Module: $RCSfile$
  4. Language: C++
  5. Date: $Date$
  6. Version: $Revision$
  7. Copyright (c) 2002 Insight Consortium. All rights reserved.
  8. See ITKCopyright.txt or http://www.itk.org/HTML/Copyright.htm 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 cmCacheManager_h
  14. #define cmCacheManager_h
  15. #include "cmStandardIncludes.h"
  16. class cmMakefile;
  17. /** \class cmCacheManager
  18. * \brief Control class for cmake's cache
  19. *
  20. * Load and Save CMake cache files.
  21. *
  22. */
  23. class cmCacheManager
  24. {
  25. public:
  26. enum CacheEntryType{ BOOL=0, PATH, FILEPATH, STRING, INTERNAL,STATIC };
  27. struct CacheEntry
  28. {
  29. std::string m_Value;
  30. std::string m_HelpString;
  31. CacheEntryType m_Type;
  32. };
  33. class CacheIterator
  34. {
  35. public:
  36. void Begin();
  37. bool IsAtEnd();
  38. void Next();
  39. const char *GetName() {
  40. return position->first.c_str(); }
  41. CacheEntry const &GetEntry() {
  42. return position->second; }
  43. cmCacheManager const &m_Container;
  44. std::map<cmStdString, CacheEntry>::const_iterator position;
  45. CacheIterator(cmCacheManager const &foo) : m_Container(foo) {
  46. this->Begin();
  47. }
  48. };
  49. friend class cmCacheManager::CacheIterator;
  50. ///! return an iterator to iterate through the cache map
  51. cmCacheManager::CacheIterator NewIterator()
  52. {
  53. return CacheIterator(*this);
  54. }
  55. typedef std::map<cmStdString, CacheEntry> CacheEntryMap;
  56. /**
  57. * Types for the cache entries. These are useful as
  58. * hints for a cache editor program. Path should bring
  59. * up a file chooser, BOOL a check box, and STRING a
  60. * text entry box, FILEPATH is a full path to a file which
  61. * can be different than just a path input
  62. */
  63. static CacheEntryType StringToType(const char*);
  64. ///! Singleton pattern get instance of the cmCacheManager.
  65. static cmCacheManager* GetInstance();
  66. static void DeleteInstance();
  67. ///! Load a cache for given makefile. Loads from ouput home.
  68. bool LoadCache(cmMakefile*);
  69. ///! Load a cache for given makefile. Loads from path/CMakeCache.txt.
  70. bool LoadCache(const char* path);
  71. bool LoadCache(const char* path, bool internal);
  72. bool LoadCache(const char* path, bool internal,
  73. std::set<std::string>& excludes,
  74. std::set<std::string>& includes);
  75. ///! Save cache for given makefile. Saves to ouput home CMakeCache.txt.
  76. bool SaveCache(cmMakefile*) ;
  77. ///! Save cache for given makefile. Saves to ouput path/CMakeCache.txt
  78. bool SaveCache(const char* path) ;
  79. ///! Print the cache to a stream
  80. void PrintCache(std::ostream&) const;
  81. ///! Get a cache entry object for a key
  82. CacheEntry *GetCacheEntry(const char *key);
  83. bool IsAdvanced(const char* key);
  84. ///! Remove an entry from the cache
  85. void RemoveCacheEntry(const char* key);
  86. ///! Get the number of entries in the cache
  87. int GetSize() {
  88. return static_cast<int>(m_Cache.size()); }
  89. ///! Break up a line like VAR:type="value" into var, type and value
  90. static bool ParseEntry(const char* entry,
  91. std::string& var,
  92. std::string& value,
  93. CacheEntryType& type);
  94. protected:
  95. ///! Add an entry into the cache
  96. void AddCacheEntry(const char* key, const char* value,
  97. const char* helpString, CacheEntryType type);
  98. ///! Add a BOOL entry into the cache
  99. void AddCacheEntry(const char* key, bool, const char* helpString);
  100. ///! Get a value from the cache given a key
  101. const char* GetCacheValue(const char* key) const;
  102. private:
  103. static void OutputHelpString(std::ofstream& fout,
  104. const std::string& helpString);
  105. static cmCacheManager* s_Instance;
  106. CacheEntryMap m_Cache;
  107. // Only cmake and cmMakefile should be able to add cache values
  108. // the commands should never use the cmCacheManager directly
  109. friend class cmMakefile; // allow access to add cache values
  110. friend class cmake; // allow access to add cache values
  111. friend class cmakewizard; // allow access to add cache values
  112. };
  113. #endif