cmCacheManager.h 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. /*=========================================================================
  2. Program: Insight Segmentation & Registration Toolkit
  3. Module: $RCSfile$
  4. Language: C++
  5. Date: $Date$
  6. Version: $Revision$
  7. Copyright (c) 2001 Insight Consortium
  8. All rights reserved.
  9. Redistribution and use in source and binary forms, with or without
  10. modification, are permitted provided that the following conditions are met:
  11. * Redistributions of source code must retain the above copyright notice,
  12. this list of conditions and the following disclaimer.
  13. * Redistributions in binary form must reproduce the above copyright notice,
  14. this list of conditions and the following disclaimer in the documentation
  15. and/or other materials provided with the distribution.
  16. * The name of the Insight Consortium, nor the names of any consortium members,
  17. nor of any contributors, may be used to endorse or promote products derived
  18. from this software without specific prior written permission.
  19. * Modified source versions must be plainly marked as such, and must not be
  20. misrepresented as being the original software.
  21. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER AND CONTRIBUTORS ``AS IS''
  22. AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  23. IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  24. ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE FOR
  25. ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  26. DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  27. SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  28. CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  29. OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  30. OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  31. =========================================================================*/
  32. #ifndef cmCacheManager_h
  33. #define cmCacheManager_h
  34. #include "cmStandardIncludes.h"
  35. class cmMakefile;
  36. /** \class cmCacheManager
  37. * \brief Control class for cmake's cache
  38. *
  39. * Load and Save CMake cache files.
  40. *
  41. */
  42. class cmCacheManager
  43. {
  44. public:
  45. enum CacheEntryType{ BOOL=0, PATH, FILEPATH, STRING, INTERNAL };
  46. struct CacheEntry
  47. {
  48. std::string m_Value;
  49. std::string m_HelpString;
  50. CacheEntryType m_Type;
  51. };
  52. public:
  53. typedef std::map<std::string, CacheEntry> CacheEntryMap;
  54. /**
  55. * Types for the cache entries. These are useful as
  56. * hints for a cache editor program. Path should bring
  57. * up a file chooser, BOOL a check box, and STRING a
  58. * text entry box, FILEPATH is a full path to a file which
  59. * can be different than just a path input
  60. */
  61. static CacheEntryType StringToType(const char*);
  62. //! Singleton pattern get instance of the cmCacheManager.
  63. static cmCacheManager* GetInstance();
  64. //! Load a cache for given makefile. Loads from ouput home.
  65. bool LoadCache(cmMakefile*);
  66. //! Load a cache for given makefile. Loads from path/CMakeCache.txt.
  67. bool LoadCache(const char* path);
  68. //! Save cache for given makefile. Saves to ouput home CMakeCache.txt.
  69. bool SaveCache(cmMakefile*) const;
  70. //! Save cache for given makefile. Saves to ouput path/CMakeCache.txt
  71. bool SaveCache(const char* path) const;
  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. //! Remove an entry from the cache
  78. void RemoveCacheEntry(const char* key);
  79. //! Print the cache to a stream
  80. CacheEntry *GetCacheEntry(const char *key);
  81. //! Get a value from the cache given a key
  82. const char* GetCacheValue(const char* key) const;
  83. //! Test a boolean cache entry to see if it is true or false, returns false
  84. // if no entry.
  85. bool IsOn(const char*) const;
  86. //! Print the cache to a stream
  87. void PrintCache(std::ostream&) const;
  88. //! Get the cache map ivar.
  89. const CacheEntryMap &GetCacheMap() const { return m_Cache; }
  90. private:
  91. static void OutputHelpString(std::ofstream& fout,
  92. const std::string& helpString);
  93. static cmCacheManager* s_Instance;
  94. CacheEntryMap m_Cache;
  95. };
  96. #endif