ENH: keep cleaning up Tcl/Tk modules
[cmake.git] / Source / cmCacheManager.h
blob72baec3b909340c9a16349c0e7f22e06e14f1fb6
1 /*=========================================================================
3 Program: CMake - Cross-Platform Makefile Generator
4 Module: $RCSfile: cmCacheManager.h,v $
5 Language: C++
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"
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 class CacheIterator;
34 friend class cmCacheManager::CacheIterator;
35 enum CacheEntryType{ BOOL=0, PATH, FILEPATH, STRING, INTERNAL,STATIC,
36 UNINITIALIZED };
38 private:
39 struct CacheEntry
41 std::string Value;
42 CacheEntryType Type;
43 std::map<cmStdString,cmStdString> Properties;
44 bool Initialized;
45 CacheEntry() : Value(""), Type(UNINITIALIZED), Initialized(false)
49 public:
50 class CacheIterator
52 public:
53 void Begin();
54 bool Find(const char*);
55 bool IsAtEnd() const;
56 void Next();
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) {
72 this->Begin();
74 CacheIterator(cmCacheManager &cm, const char* key) : Container(cm)
76 if ( key )
78 this->Find(key);
81 private:
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);
92 /**
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
129 int GetSize() {
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,
134 std::string& var,
135 std::string& value,
136 CacheEntryType& type);
138 static bool ParseEntry(const char* entry,
139 std::string& var,
140 std::string& value);
142 ///! Get a value from the cache given a key
143 const char* GetCacheValue(const char* key) const;
145 protected:
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);
158 private:
159 typedef std::map<cmStdString, CacheEntry> CacheEntryMap;
160 static void OutputHelpString(std::ofstream& fout,
161 const std::string& helpString);
162 CacheEntryMap Cache;
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
171 #endif