cmCacheManager.h 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  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. public:
  34. typedef std::map<cmStdString, CacheEntry> CacheEntryMap;
  35. /**
  36. * Types for the cache entries. These are useful as
  37. * hints for a cache editor program. Path should bring
  38. * up a file chooser, BOOL a check box, and STRING a
  39. * text entry box, FILEPATH is a full path to a file which
  40. * can be different than just a path input
  41. */
  42. static CacheEntryType StringToType(const char*);
  43. ///! Singleton pattern get instance of the cmCacheManager.
  44. static cmCacheManager* GetInstance();
  45. ///! Load a cache for given makefile. Loads from ouput home.
  46. bool LoadCache(cmMakefile*);
  47. ///! Load a cache for given makefile. Loads from path/CMakeCache.txt.
  48. bool LoadCache(const char* path);
  49. bool LoadCache(const char* path, bool internal);
  50. bool LoadCache(const char* path, bool internal,
  51. std::set<std::string>& excludes,
  52. std::set<std::string>& includes);
  53. ///! Save cache for given makefile. Saves to ouput home CMakeCache.txt.
  54. bool SaveCache(cmMakefile*) ;
  55. ///! Save cache for given makefile. Saves to ouput path/CMakeCache.txt
  56. bool SaveCache(const char* path) ;
  57. ///! Print the cache to a stream
  58. void PrintCache(std::ostream&) const;
  59. ///! Get the cache map ivar.
  60. const CacheEntryMap &GetCacheMap() const { return m_Cache; }
  61. ///! Get a cache entry object for a key
  62. CacheEntry *GetCacheEntry(const char *key);
  63. bool IsAdvanced(const char* key);
  64. ///! Remove an entry from the cache
  65. void RemoveCacheEntry(const char* key);
  66. ///! Break up a line like VAR:type="value" into var, type and value
  67. static bool ParseEntry(const char* entry,
  68. std::string& var,
  69. std::string& value,
  70. CacheEntryType& type);
  71. protected:
  72. ///! Add an entry into the cache
  73. void AddCacheEntry(const char* key, const char* value,
  74. const char* helpString, CacheEntryType type);
  75. ///! Add a BOOL entry into the cache
  76. void AddCacheEntry(const char* key, bool, const char* helpString);
  77. ///! Get a value from the cache given a key
  78. const char* GetCacheValue(const char* key) const;
  79. private:
  80. static void OutputHelpString(std::ofstream& fout,
  81. const std::string& helpString);
  82. static cmCacheManager* s_Instance;
  83. CacheEntryMap m_Cache;
  84. // Only cmake and cmMakefile should be able to add cache values
  85. // the commands should never use the cmCacheManager directly
  86. friend class cmMakefile; // allow access to add cache values
  87. friend class cmake; // allow access to add cache values
  88. friend class cmakewizard; // allow access to add cache values
  89. };
  90. #endif