Resync
[CMakeLuaTailorHgBridge.git] / CMakeLua / Source / cmCacheManager.h
blobbe9dbe817f7d15570d53d7ac5956219fbda1e2aa
1 /*=========================================================================
3 Program: CMake - Cross-Platform Makefile Generator
4 Module: $RCSfile: cmCacheManager.h,v $
5 Language: C++
6 Date: $Date: 2008-03-07 16:43:47 $
7 Version: $Revision: 1.49 $
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 class cmMakefile;
22 class cmMarkAsAdvancedCommand;
24 /** \class cmCacheManager
25 * \brief Control class for cmake's cache
27 * Load and Save CMake cache files.
30 class cmCacheManager
32 public:
33 cmCacheManager();
34 class CacheIterator;
35 friend class cmCacheManager::CacheIterator;
36 enum CacheEntryType{ BOOL=0, PATH, FILEPATH, STRING, INTERNAL,STATIC,
37 UNINITIALIZED };
39 private:
40 struct CacheEntry
42 std::string Value;
43 CacheEntryType Type;
44 std::map<cmStdString,cmStdString> Properties;
45 bool Initialized;
46 CacheEntry() : Value(""), Type(UNINITIALIZED), Initialized(false)
50 public:
51 class CacheIterator
53 public:
54 void Begin();
55 bool Find(const char*);
56 bool IsAtEnd() const;
57 void Next();
58 const char *GetName() const {
59 return this->Position->first.c_str(); }
60 const char* GetProperty(const char*) const ;
61 bool GetPropertyAsBool(const char*) const ;
62 bool PropertyExists(const char*) const;
63 void SetProperty(const char* property, const char* value);
64 void SetProperty(const char* property, bool value);
65 const char* GetValue() const { return this->GetEntry().Value.c_str(); }
66 bool GetValueAsBool() const;
67 void SetValue(const char*);
68 CacheEntryType GetType() const { return this->GetEntry().Type; }
69 void SetType(CacheEntryType ty) { this->GetEntry().Type = ty; }
70 bool Initialized() { return this->GetEntry().Initialized; }
71 cmCacheManager &Container;
72 std::map<cmStdString, CacheEntry>::iterator Position;
73 CacheIterator(cmCacheManager &cm) : Container(cm) {
74 this->Begin();
76 CacheIterator(cmCacheManager &cm, const char* key) : Container(cm)
78 if ( key )
80 this->Find(key);
83 private:
84 CacheEntry const& GetEntry() const { return this->Position->second; }
85 CacheEntry& GetEntry() { return this->Position->second; }
88 ///! return an iterator to iterate through the cache map
89 cmCacheManager::CacheIterator NewIterator()
91 return CacheIterator(*this);
94 /**
95 * Types for the cache entries. These are useful as
96 * hints for a cache editor program. Path should bring
97 * up a file chooser, BOOL a check box, and STRING a
98 * text entry box, FILEPATH is a full path to a file which
99 * can be different than just a path input
101 static CacheEntryType StringToType(const char*);
102 static const char* TypeToString(CacheEntryType);
104 ///! Load a cache for given makefile. Loads from ouput home.
105 bool LoadCache(cmMakefile*);
106 ///! Load a cache for given makefile. Loads from path/CMakeCache.txt.
107 bool LoadCache(const char* path);
108 bool LoadCache(const char* path, bool internal);
109 bool LoadCache(const char* path, bool internal,
110 std::set<cmStdString>& excludes,
111 std::set<cmStdString>& includes);
113 ///! Save cache for given makefile. Saves to ouput home CMakeCache.txt.
114 bool SaveCache(cmMakefile*) ;
115 ///! Save cache for given makefile. Saves to ouput path/CMakeCache.txt
116 bool SaveCache(const char* path) ;
118 ///! Delete the cache given
119 bool DeleteCache(const char* path);
121 ///! Print the cache to a stream
122 void PrintCache(std::ostream&) const;
124 ///! Get the iterator for an entry with a given key.
125 cmCacheManager::CacheIterator GetCacheIterator(const char *key=0);
127 ///! Remove an entry from the cache
128 void RemoveCacheEntry(const char* key);
130 ///! Get the number of entries in the cache
131 int GetSize() {
132 return static_cast<int>(this->Cache.size()); }
134 ///! Break up a line like VAR:type="value" into var, type and value
135 static bool ParseEntry(const char* entry,
136 std::string& var,
137 std::string& value,
138 CacheEntryType& type);
140 static bool ParseEntry(const char* entry,
141 std::string& var,
142 std::string& value);
144 ///! Get a value from the cache given a key
145 const char* GetCacheValue(const char* key) const;
147 /** Get the version of CMake that wrote the cache. */
148 unsigned int GetCacheMajorVersion() { return this->CacheMajorVersion; }
149 unsigned int GetCacheMinorVersion() { return this->CacheMinorVersion; }
150 bool NeedCacheCompatibility(int major, int minor);
152 protected:
153 ///! Add an entry into the cache
154 void AddCacheEntry(const char* key, const char* value,
155 const char* helpString, CacheEntryType type);
157 ///! Add a BOOL entry into the cache
158 void AddCacheEntry(const char* key, bool, const char* helpString);
160 ///! Get a cache entry object for a key
161 CacheEntry *GetCacheEntry(const char *key);
162 ///! Clean out the CMakeFiles directory if no CMakeCache.txt
163 void CleanCMakeFiles(const char* path);
165 // Cache version info
166 unsigned int CacheMajorVersion;
167 unsigned int CacheMinorVersion;
168 private:
169 typedef std::map<cmStdString, CacheEntry> CacheEntryMap;
170 static void OutputHelpString(std::ofstream& fout,
171 const std::string& helpString);
172 CacheEntryMap Cache;
173 // Only cmake and cmMakefile should be able to add cache values
174 // the commands should never use the cmCacheManager directly
175 friend class cmMakefile; // allow access to add cache values
176 friend class cmake; // allow access to add cache values
177 friend class cmakewizard; // allow access to add cache values
178 friend class cmMarkAsAdvancedCommand; // allow access to add cache values
181 #endif