1 /*=========================================================================
3 Program: Insight Segmentation & Registration Toolkit
4 Module: $RCSfile: cmCacheManager.h,v $
6 Date: $Date: 2002-09-17 15:48:52 $
7 Version: $Revision: 1.32 $
9 Copyright (c) 2002 Insight Consortium. All rights reserved.
10 See ITKCopyright.txt or http://www.itk.org/HTML/Copyright.htm 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"
23 /** \class cmCacheManager
24 * \brief Control class for cmake's cache
26 * Load and Save CMake cache files.
33 friend class cmCacheManager::CacheIterator
;
34 enum CacheEntryType
{ BOOL
=0, PATH
, FILEPATH
, STRING
, INTERNAL
,STATIC
,UNINITIALIZED
};
40 CacheEntryType m_Type
;
41 std::map
<cmStdString
,cmStdString
> m_Properties
;
49 bool Find(const char*);
52 const char *GetName() const {
53 return m_Position
->first
.c_str(); }
54 const char* GetProperty(const char*) const ;
55 bool GetPropertyAsBool(const char*) const ;
56 bool PropertyExists(const char*) const;
57 void SetProperty(const char* property
, const char* value
);
58 void SetProperty(const char* property
, bool value
);
59 const char* GetValue() const { return this->GetEntry().m_Value
.c_str(); }
60 void SetValue(const char*);
61 CacheEntryType
GetType() const { return this->GetEntry().m_Type
; }
62 cmCacheManager
&m_Container
;
63 std::map
<cmStdString
, CacheEntry
>::iterator m_Position
;
64 CacheIterator(cmCacheManager
&foo
) : m_Container(foo
) {
67 CacheIterator(cmCacheManager
&foo
, const char* key
) : m_Container(foo
) {
71 CacheEntry
const& GetEntry() const { return m_Position
->second
; }
72 CacheEntry
& GetEntry() { return m_Position
->second
; }
75 ///! return an iterator to iterate through the cache map
76 cmCacheManager::CacheIterator
NewIterator()
78 return CacheIterator(*this);
82 * Types for the cache entries. These are useful as
83 * hints for a cache editor program. Path should bring
84 * up a file chooser, BOOL a check box, and STRING a
85 * text entry box, FILEPATH is a full path to a file which
86 * can be different than just a path input
88 static CacheEntryType
StringToType(const char*);
90 ///! Load a cache for given makefile. Loads from ouput home.
91 bool LoadCache(cmMakefile
*);
92 ///! Load a cache for given makefile. Loads from path/CMakeCache.txt.
93 bool LoadCache(const char* path
);
94 bool LoadCache(const char* path
, bool internal
);
95 bool LoadCache(const char* path
, bool internal
,
96 std::set
<std::string
>& excludes
,
97 std::set
<std::string
>& includes
);
99 ///! Save cache for given makefile. Saves to ouput home CMakeCache.txt.
100 bool SaveCache(cmMakefile
*) ;
101 ///! Save cache for given makefile. Saves to ouput path/CMakeCache.txt
102 bool SaveCache(const char* path
) ;
104 ///! Print the cache to a stream
105 void PrintCache(std::ostream
&) const;
107 ///! Get the iterator for an entry with a given key.
108 cmCacheManager::CacheIterator
GetCacheIterator(const char *key
);
110 ///! Remove an entry from the cache
111 void RemoveCacheEntry(const char* key
);
113 ///! Get the number of entries in the cache
115 return static_cast<int>(m_Cache
.size()); }
117 ///! Break up a line like VAR:type="value" into var, type and value
118 static bool ParseEntry(const char* entry
,
121 CacheEntryType
& type
);
123 ///! Get a value from the cache given a key
124 const char* GetCacheValue(const char* key
) const;
127 ///! Add an entry into the cache
128 void AddCacheEntry(const char* key
, const char* value
,
129 const char* helpString
, CacheEntryType type
);
131 ///! Add a BOOL entry into the cache
132 void AddCacheEntry(const char* key
, bool, const char* helpString
);
134 ///! Get a cache entry object for a key
135 CacheEntry
*GetCacheEntry(const char *key
);
138 typedef std::map
<cmStdString
, CacheEntry
> CacheEntryMap
;
139 static void OutputHelpString(std::ofstream
& fout
,
140 const std::string
& helpString
);
141 CacheEntryMap m_Cache
;
142 // Only cmake and cmMakefile should be able to add cache values
143 // the commands should never use the cmCacheManager directly
144 friend class cmMakefile
; // allow access to add cache values
145 friend class cmake
; // allow access to add cache values
146 friend class cmakewizard
; // allow access to add cache values