Resync
[CMakeLuaTailorHgBridge.git] / CMakeLua / Source / cmCacheManager.h
blob6852b443ade3dbe1ea1d2f50e1a3de382b69b541
1 /*=========================================================================
3 Program: CMake - Cross-Platform Makefile Generator
4 Module: $RCSfile: cmCacheManager.h,v $
5 Language: C++
6 Date: $Date: 2009-03-13 14:53:43 $
7 Version: $Revision: 1.54 $
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"
21 #include "cmPropertyMap.h"
22 class cmMakefile;
23 class cmMarkAsAdvancedCommand;
24 class cmake;
26 /** \class cmCacheManager
27 * \brief Control class for cmake's cache
29 * Load and Save CMake cache files.
32 class cmCacheManager
34 public:
35 cmCacheManager(cmake* cm);
36 class CacheIterator;
37 friend class cmCacheManager::CacheIterator;
38 enum CacheEntryType{ BOOL=0, PATH, FILEPATH, STRING, INTERNAL,STATIC,
39 UNINITIALIZED };
41 private:
42 struct CacheEntry
44 std::string Value;
45 CacheEntryType Type;
46 cmPropertyMap Properties;
47 const char* GetProperty(const char*) const;
48 void SetProperty(const char* property, const char* value);
49 void AppendProperty(const char* property, const char* value);
50 bool Initialized;
51 CacheEntry() : Value(""), Type(UNINITIALIZED), Initialized(false)
55 public:
56 class CacheIterator
58 public:
59 void Begin();
60 bool Find(const char*);
61 bool IsAtEnd() const;
62 void Next();
63 const char *GetName() const {
64 return this->Position->first.c_str(); }
65 const char* GetProperty(const char*) const ;
66 bool GetPropertyAsBool(const char*) const ;
67 bool PropertyExists(const char*) const;
68 void SetProperty(const char* property, const char* value);
69 void AppendProperty(const char* property, const char* value);
70 void SetProperty(const char* property, bool value);
71 const char* GetValue() const { return this->GetEntry().Value.c_str(); }
72 bool GetValueAsBool() const;
73 void SetValue(const char*);
74 CacheEntryType GetType() const { return this->GetEntry().Type; }
75 void SetType(CacheEntryType ty) { this->GetEntry().Type = ty; }
76 bool Initialized() { return this->GetEntry().Initialized; }
77 cmCacheManager &Container;
78 std::map<cmStdString, CacheEntry>::iterator Position;
79 CacheIterator(cmCacheManager &cm) : Container(cm) {
80 this->Begin();
82 CacheIterator(cmCacheManager &cm, const char* key) : Container(cm)
84 if ( key )
86 this->Find(key);
89 private:
90 CacheEntry const& GetEntry() const { return this->Position->second; }
91 CacheEntry& GetEntry() { return this->Position->second; }
94 ///! return an iterator to iterate through the cache map
95 cmCacheManager::CacheIterator NewIterator()
97 return CacheIterator(*this);
101 * Types for the cache entries. These are useful as
102 * hints for a cache editor program. Path should bring
103 * up a file chooser, BOOL a check box, and STRING a
104 * text entry box, FILEPATH is a full path to a file which
105 * can be different than just a path input
107 static CacheEntryType StringToType(const char*);
108 static const char* TypeToString(CacheEntryType);
109 static bool IsType(const char*);
111 ///! Load a cache for given makefile. Loads from ouput home.
112 bool LoadCache(cmMakefile*);
113 ///! Load a cache for given makefile. Loads from path/CMakeCache.txt.
114 bool LoadCache(const char* path);
115 bool LoadCache(const char* path, bool internal);
116 bool LoadCache(const char* path, bool internal,
117 std::set<cmStdString>& excludes,
118 std::set<cmStdString>& includes);
120 ///! Save cache for given makefile. Saves to ouput home CMakeCache.txt.
121 bool SaveCache(cmMakefile*) ;
122 ///! Save cache for given makefile. Saves to ouput path/CMakeCache.txt
123 bool SaveCache(const char* path) ;
125 ///! Delete the cache given
126 bool DeleteCache(const char* path);
128 ///! Print the cache to a stream
129 void PrintCache(std::ostream&) const;
131 ///! Get the iterator for an entry with a given key.
132 cmCacheManager::CacheIterator GetCacheIterator(const char *key=0);
134 ///! Remove an entry from the cache
135 void RemoveCacheEntry(const char* key);
137 ///! Get the number of entries in the cache
138 int GetSize() {
139 return static_cast<int>(this->Cache.size()); }
141 ///! Break up a line like VAR:type="value" into var, type and value
142 static bool ParseEntry(const char* entry,
143 std::string& var,
144 std::string& value,
145 CacheEntryType& type);
147 static bool ParseEntry(const char* entry,
148 std::string& var,
149 std::string& value);
151 ///! Get a value from the cache given a key
152 const char* GetCacheValue(const char* key) const;
154 /** Get the version of CMake that wrote the cache. */
155 unsigned int GetCacheMajorVersion() { return this->CacheMajorVersion; }
156 unsigned int GetCacheMinorVersion() { return this->CacheMinorVersion; }
157 bool NeedCacheCompatibility(int major, int minor);
159 /** Define and document CACHE entry properties. */
160 static void DefineProperties(cmake *cm);
162 protected:
163 ///! Add an entry into the cache
164 void AddCacheEntry(const char* key, const char* value,
165 const char* helpString, CacheEntryType type);
167 ///! Add a BOOL entry into the cache
168 void AddCacheEntry(const char* key, bool, const char* helpString);
170 ///! Get a cache entry object for a key
171 CacheEntry *GetCacheEntry(const char *key);
172 ///! Clean out the CMakeFiles directory if no CMakeCache.txt
173 void CleanCMakeFiles(const char* path);
175 // Cache version info
176 unsigned int CacheMajorVersion;
177 unsigned int CacheMinorVersion;
178 private:
179 cmake* CMakeInstance;
180 typedef std::map<cmStdString, CacheEntry> CacheEntryMap;
181 static void OutputHelpString(std::ostream& fout,
182 const std::string& helpString);
183 static void OutputKey(std::ostream& fout, std::string const& key);
184 static void OutputValue(std::ostream& fout, std::string const& value);
186 static const char* PersistentProperties[];
187 bool ReadPropertyEntry(std::string const& key, CacheEntry& e);
188 void WritePropertyEntries(std::ostream& os, CacheIterator const& i);
190 CacheEntryMap Cache;
191 // Only cmake and cmMakefile should be able to add cache values
192 // the commands should never use the cmCacheManager directly
193 friend class cmMakefile; // allow access to add cache values
194 friend class cmake; // allow access to add cache values
195 friend class cmakewizard; // allow access to add cache values
196 friend class cmMarkAsAdvancedCommand; // allow access to add cache values
199 #endif