1 /*=========================================================================
3 Program: CMake - Cross-Platform Makefile Generator
4 Module: $RCSfile: cmCacheManager.h,v $
6 Date: $Date: 2007-04-10 20:03:10 $
7 Version: $Revision: 1.46 $
9 Copyright (c) 2002 Kitware, Inc., Insight Consortium. All rights reserved.
10 See Copyright.txt or http://www.cmake.org/HTML/Copyright.html 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 #ifndef cmCacheManager_h
18 #define cmCacheManager_h
20 #include "cmStandardIncludes.h"
22 class cmMarkAsAdvancedCommand
;
24 /** \class cmCacheManager
25 * \brief Control class for cmake's cache
27 * Load and Save CMake cache files.
34 friend class cmCacheManager::CacheIterator
;
35 enum CacheEntryType
{ BOOL
=0, PATH
, FILEPATH
, STRING
, INTERNAL
,STATIC
,
43 std::map
<cmStdString
,cmStdString
> Properties
;
45 CacheEntry() : Value(""), Type(UNINITIALIZED
), Initialized(false)
54 bool Find(const char*);
57 const char *GetName() const {
58 return this->Position
->first
.c_str(); }
59 const char* GetProperty(const char*) const ;
60 bool GetPropertyAsBool(const char*) const ;
61 bool PropertyExists(const char*) const;
62 void SetProperty(const char* property
, const char* value
);
63 void SetProperty(const char* property
, bool value
);
64 const char* GetValue() const { return this->GetEntry().Value
.c_str(); }
65 bool GetValueAsBool() const;
66 void SetValue(const char*);
67 CacheEntryType
GetType() const { return this->GetEntry().Type
; }
68 bool Initialized() { return this->GetEntry().Initialized
; }
69 cmCacheManager
&Container
;
70 std::map
<cmStdString
, CacheEntry
>::iterator Position
;
71 CacheIterator(cmCacheManager
&cm
) : Container(cm
) {
74 CacheIterator(cmCacheManager
&cm
, const char* key
) : Container(cm
)
82 CacheEntry
const& GetEntry() const { return this->Position
->second
; }
83 CacheEntry
& GetEntry() { return this->Position
->second
; }
86 ///! return an iterator to iterate through the cache map
87 cmCacheManager::CacheIterator
NewIterator()
89 return CacheIterator(*this);
93 * Types for the cache entries. These are useful as
94 * hints for a cache editor program. Path should bring
95 * up a file chooser, BOOL a check box, and STRING a
96 * text entry box, FILEPATH is a full path to a file which
97 * can be different than just a path input
99 static CacheEntryType
StringToType(const char*);
100 static const char* TypeToString(CacheEntryType
);
102 ///! Load a cache for given makefile. Loads from ouput home.
103 bool LoadCache(cmMakefile
*);
104 ///! Load a cache for given makefile. Loads from path/CMakeCache.txt.
105 bool LoadCache(const char* path
);
106 bool LoadCache(const char* path
, bool internal
);
107 bool LoadCache(const char* path
, bool internal
,
108 std::set
<cmStdString
>& excludes
,
109 std::set
<cmStdString
>& includes
);
111 ///! Save cache for given makefile. Saves to ouput home CMakeCache.txt.
112 bool SaveCache(cmMakefile
*) ;
113 ///! Save cache for given makefile. Saves to ouput path/CMakeCache.txt
114 bool SaveCache(const char* path
) ;
116 ///! Delete the cache given
117 bool DeleteCache(const char* path
);
119 ///! Print the cache to a stream
120 void PrintCache(std::ostream
&) const;
122 ///! Get the iterator for an entry with a given key.
123 cmCacheManager::CacheIterator
GetCacheIterator(const char *key
=0);
125 ///! Remove an entry from the cache
126 void RemoveCacheEntry(const char* key
);
128 ///! Get the number of entries in the cache
130 return static_cast<int>(this->Cache
.size()); }
132 ///! Break up a line like VAR:type="value" into var, type and value
133 static bool ParseEntry(const char* entry
,
136 CacheEntryType
& type
);
138 static bool ParseEntry(const char* entry
,
142 ///! Get a value from the cache given a key
143 const char* GetCacheValue(const char* key
) const;
146 ///! Add an entry into the cache
147 void AddCacheEntry(const char* key
, const char* value
,
148 const char* helpString
, CacheEntryType type
);
150 ///! Add a BOOL entry into the cache
151 void AddCacheEntry(const char* key
, bool, const char* helpString
);
153 ///! Get a cache entry object for a key
154 CacheEntry
*GetCacheEntry(const char *key
);
155 ///! Clean out the CMakeFiles directory if no CMakeCache.txt
156 void CleanCMakeFiles(const char* path
);
159 typedef std::map
<cmStdString
, CacheEntry
> CacheEntryMap
;
160 static void OutputHelpString(std::ofstream
& fout
,
161 const std::string
& helpString
);
163 // Only cmake and cmMakefile should be able to add cache values
164 // the commands should never use the cmCacheManager directly
165 friend class cmMakefile
; // allow access to add cache values
166 friend class cmake
; // allow access to add cache values
167 friend class cmakewizard
; // allow access to add cache values
168 friend class cmMarkAsAdvancedCommand
; // allow access to add cache values