ENH: keep cleaning up Tcl/Tk modules
[cmake.git] / Source / cmCacheManager.cxx
blob2bbb89eb3439e022969ce583260c24a930883014
1 /*=========================================================================
3 Program: CMake - Cross-Platform Makefile Generator
4 Module: $RCSfile: cmCacheManager.cxx,v $
5 Language: C++
6 Date: $Date: 2007-09-07 15:10:46 $
7 Version: $Revision: 1.98 $
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 =========================================================================*/
18 #include "cmCacheManager.h"
19 #include "cmSystemTools.h"
20 #include "cmCacheManager.h"
21 #include "cmMakefile.h"
22 #include "cmake.h"
23 #include "cmVersion.h"
25 #include <cmsys/Directory.hxx>
26 #include <cmsys/Glob.hxx>
28 #include <cmsys/RegularExpression.hxx>
30 #if defined(_WIN32) || defined(__CYGWIN__)
31 # include <windows.h>
32 #endif // _WIN32
34 const char* cmCacheManagerTypes[] =
35 { "BOOL",
36 "PATH",
37 "FILEPATH",
38 "STRING",
39 "INTERNAL",
40 "STATIC",
41 "UNINITIALIZED",
45 const char* cmCacheManager::TypeToString(cmCacheManager::CacheEntryType type)
47 if ( type > 6 )
49 return cmCacheManagerTypes[6];
51 return cmCacheManagerTypes[type];
54 cmCacheManager::CacheEntryType cmCacheManager::StringToType(const char* s)
56 int i = 0;
57 while(cmCacheManagerTypes[i])
59 if(strcmp(s, cmCacheManagerTypes[i]) == 0)
61 return static_cast<CacheEntryType>(i);
63 ++i;
65 return STRING;
68 bool cmCacheManager::LoadCache(cmMakefile* mf)
70 return this->LoadCache(mf->GetHomeOutputDirectory());
74 bool cmCacheManager::LoadCache(const char* path)
76 return this->LoadCache(path,true);
79 bool cmCacheManager::LoadCache(const char* path,
80 bool internal)
82 std::set<cmStdString> emptySet;
83 return this->LoadCache(path, internal, emptySet, emptySet);
86 bool cmCacheManager::ParseEntry(const char* entry,
87 std::string& var,
88 std::string& value)
90 // input line is: key:type=value
91 static cmsys::RegularExpression reg(
92 "^([^:]*)=(.*[^\r\t ]|[\r\t ]*)[\r\t ]*$");
93 // input line is: "key":type=value
94 static cmsys::RegularExpression regQuoted(
95 "^\"([^\"]*)\"=(.*[^\r\t ]|[\r\t ]*)[\r\t ]*$");
96 bool flag = false;
97 if(regQuoted.find(entry))
99 var = regQuoted.match(1);
100 value = regQuoted.match(2);
101 flag = true;
103 else if (reg.find(entry))
105 var = reg.match(1);
106 value = reg.match(2);
107 flag = true;
110 // if value is enclosed in single quotes ('foo') then remove them
111 // it is used to enclose trailing space or tab
112 if (flag &&
113 value.size() >= 2 &&
114 value[0] == '\'' &&
115 value[value.size() - 1] == '\'')
117 value = value.substr(1,
118 value.size() - 2);
121 return flag;
124 bool cmCacheManager::ParseEntry(const char* entry,
125 std::string& var,
126 std::string& value,
127 CacheEntryType& type)
129 // input line is: key:type=value
130 static cmsys::RegularExpression reg(
131 "^([^:]*):([^=]*)=(.*[^\r\t ]|[\r\t ]*)[\r\t ]*$");
132 // input line is: "key":type=value
133 static cmsys::RegularExpression regQuoted(
134 "^\"([^\"]*)\":([^=]*)=(.*[^\r\t ]|[\r\t ]*)[\r\t ]*$");
135 bool flag = false;
136 if(regQuoted.find(entry))
138 var = regQuoted.match(1);
139 type = cmCacheManager::StringToType(regQuoted.match(2).c_str());
140 value = regQuoted.match(3);
141 flag = true;
143 else if (reg.find(entry))
145 var = reg.match(1);
146 type = cmCacheManager::StringToType(reg.match(2).c_str());
147 value = reg.match(3);
148 flag = true;
151 // if value is enclosed in single quotes ('foo') then remove them
152 // it is used to enclose trailing space or tab
153 if (flag &&
154 value.size() >= 2 &&
155 value[0] == '\'' &&
156 value[value.size() - 1] == '\'')
158 value = value.substr(1,
159 value.size() - 2);
162 return flag;
165 void cmCacheManager::CleanCMakeFiles(const char* path)
167 std::string glob = path;
168 glob += cmake::GetCMakeFilesDirectory();
169 glob += "/*.cmake";
170 cmsys::Glob globIt;
171 globIt.FindFiles(glob);
172 std::vector<std::string> files = globIt.GetFiles();
173 for(std::vector<std::string>::iterator i = files.begin();
174 i != files.end(); ++i)
176 cmSystemTools::RemoveFile(i->c_str());
180 bool cmCacheManager::LoadCache(const char* path,
181 bool internal,
182 std::set<cmStdString>& excludes,
183 std::set<cmStdString>& includes)
185 std::string cacheFile = path;
186 cacheFile += "/CMakeCache.txt";
187 // clear the old cache, if we are reading in internal values
188 if ( internal )
190 this->Cache.clear();
192 if(!cmSystemTools::FileExists(cacheFile.c_str()))
194 this->CleanCMakeFiles(path);
195 return false;
198 std::ifstream fin(cacheFile.c_str());
199 if(!fin)
201 return false;
203 const char *realbuffer;
204 std::string buffer;
205 std::string entryKey;
206 while(fin)
208 // Format is key:type=value
209 CacheEntry e;
210 cmSystemTools::GetLineFromStream(fin, buffer);
211 realbuffer = buffer.c_str();
212 while(*realbuffer != '0' &&
213 (*realbuffer == ' ' ||
214 *realbuffer == '\t' ||
215 *realbuffer == '\r' ||
216 *realbuffer == '\n'))
218 realbuffer++;
220 // skip blank lines and comment lines
221 if(realbuffer[0] == '#' || realbuffer[0] == 0)
223 continue;
225 while(realbuffer[0] == '/' && realbuffer[1] == '/')
227 if ((realbuffer[2] == '\\') && (realbuffer[3]=='n'))
229 e.Properties["HELPSTRING"] += "\n";
230 e.Properties["HELPSTRING"] += &realbuffer[4];
232 else
234 e.Properties["HELPSTRING"] += &realbuffer[2];
236 cmSystemTools::GetLineFromStream(fin, buffer);
237 realbuffer = buffer.c_str();
238 if(!fin)
240 continue;
243 if(cmCacheManager::ParseEntry(realbuffer, entryKey, e.Value, e.Type))
245 if ( excludes.find(entryKey) == excludes.end() )
247 // Load internal values if internal is set.
248 // If the entry is not internal to the cache being loaded
249 // or if it is in the list of internal entries to be
250 // imported, load it.
251 if ( internal || (e.Type != INTERNAL) ||
252 (includes.find(entryKey) != includes.end()) )
254 // If we are loading the cache from another project,
255 // make all loaded entries internal so that it is
256 // not visible in the gui
257 if (!internal)
259 e.Type = INTERNAL;
260 e.Properties["HELPSTRING"] = "DO NOT EDIT, ";
261 e.Properties["HELPSTRING"] += entryKey;
262 e.Properties["HELPSTRING"] += " loaded from external file. "
263 "To change this value edit this file: ";
264 e.Properties["HELPSTRING"] += path;
265 e.Properties["HELPSTRING"] += "/CMakeCache.txt" ;
267 if ( e.Type == cmCacheManager::INTERNAL &&
268 (entryKey.size() > strlen("-ADVANCED")) &&
269 strcmp(entryKey.c_str() + (entryKey.size() -
270 strlen("-ADVANCED")), "-ADVANCED") == 0 )
272 std::string value = e.Value;
273 std::string akey =
274 entryKey.substr(0, (entryKey.size() - strlen("-ADVANCED")));
275 cmCacheManager::CacheIterator it =
276 this->GetCacheIterator(akey.c_str());
277 if ( it.IsAtEnd() )
279 e.Type = cmCacheManager::UNINITIALIZED;
280 this->Cache[akey] = e;
282 if (!it.Find(akey.c_str()))
284 cmSystemTools::Error("Internal CMake error when reading cache");
286 it.SetProperty("ADVANCED", value.c_str());
288 else if ( e.Type == cmCacheManager::INTERNAL &&
289 (entryKey.size() > strlen("-MODIFIED")) &&
290 strcmp(entryKey.c_str() + (entryKey.size() -
291 strlen("-MODIFIED")), "-MODIFIED") == 0 )
293 std::string value = e.Value;
294 std::string akey =
295 entryKey.substr(0, (entryKey.size() - strlen("-MODIFIED")));
296 cmCacheManager::CacheIterator it =
297 this->GetCacheIterator(akey.c_str());
298 if ( it.IsAtEnd() )
300 e.Type = cmCacheManager::UNINITIALIZED;
301 this->Cache[akey] = e;
303 if (!it.Find(akey.c_str()))
305 cmSystemTools::Error("Internal CMake error when reading cache");
307 it.SetProperty("MODIFIED", value.c_str());
309 else
311 e.Initialized = true;
312 this->Cache[entryKey] = e;
317 else
319 cmSystemTools::Error("Parse error in cache file ", cacheFile.c_str(),
320 ". Offending entry: ", realbuffer);
323 // if CMAKE version not found in the list file
324 // add them as version 0.0
325 if(!this->GetCacheValue("CMAKE_CACHE_MINOR_VERSION"))
327 this->AddCacheEntry("CMAKE_CACHE_MINOR_VERSION", "0",
328 "Minor version of cmake used to create the "
329 "current loaded cache", cmCacheManager::INTERNAL);
330 this->AddCacheEntry("CMAKE_CACHE_MAJOR_VERSION", "0",
331 "Major version of cmake used to create the "
332 "current loaded cache", cmCacheManager::INTERNAL);
335 // check to make sure the cache directory has not
336 // been moved
337 if ( internal && this->GetCacheValue("CMAKE_CACHEFILE_DIR") )
339 std::string currentcwd = path;
340 std::string oldcwd = this->GetCacheValue("CMAKE_CACHEFILE_DIR");
341 cmSystemTools::ConvertToUnixSlashes(currentcwd);
342 currentcwd += "/CMakeCache.txt";
343 oldcwd += "/CMakeCache.txt";
344 if(!cmSystemTools::SameFile(oldcwd.c_str(), currentcwd.c_str()))
346 std::string message =
347 std::string("The current CMakeCache.txt directory ") +
348 currentcwd + std::string(" is different than the directory ") +
349 std::string(this->GetCacheValue("CMAKE_CACHEFILE_DIR")) +
350 std::string(" where CMackeCache.txt was created. This may result "
351 "in binaries being created in the wrong place. If you "
352 "are not sure, reedit the CMakeCache.txt");
353 cmSystemTools::Error(message.c_str());
356 return true;
359 bool cmCacheManager::SaveCache(cmMakefile* mf)
361 return this->SaveCache(mf->GetHomeOutputDirectory());
365 bool cmCacheManager::SaveCache(const char* path)
367 std::string cacheFile = path;
368 cacheFile += "/CMakeCache.txt";
369 std::string tempFile = cacheFile;
370 tempFile += ".tmp";
371 std::ofstream fout(tempFile.c_str());
372 if(!fout)
374 cmSystemTools::Error("Unable to open cache file for save. ",
375 cacheFile.c_str());
376 cmSystemTools::ReportLastSystemError("");
377 return false;
379 // before writing the cache, update the version numbers
380 // to the
381 char temp[1024];
382 sprintf(temp, "%d", cmVersion::GetMinorVersion());
383 this->AddCacheEntry("CMAKE_CACHE_MINOR_VERSION", temp,
384 "Minor version of cmake used to create the "
385 "current loaded cache", cmCacheManager::INTERNAL);
386 sprintf(temp, "%d", cmVersion::GetMajorVersion());
387 this->AddCacheEntry("CMAKE_CACHE_MAJOR_VERSION", temp,
388 "Major version of cmake used to create the "
389 "current loaded cache", cmCacheManager::INTERNAL);
391 this->AddCacheEntry("CMAKE_CACHE_RELEASE_VERSION",
392 cmVersion::GetReleaseVersion().c_str(),
393 "Major version of cmake used to create the "
394 "current loaded cache", cmCacheManager::INTERNAL);
396 // Let us store the current working directory so that if somebody
397 // Copies it, he will not be surprised
398 std::string currentcwd = path;
399 if ( currentcwd[0] >= 'A' && currentcwd[0] <= 'Z' &&
400 currentcwd[1] == ':' )
402 currentcwd[0] = currentcwd[0] - 'A' + 'a';
404 cmSystemTools::ConvertToUnixSlashes(currentcwd);
405 this->AddCacheEntry("CMAKE_CACHEFILE_DIR", currentcwd.c_str(),
406 "This is the directory where this CMakeCahe.txt"
407 " was created", cmCacheManager::INTERNAL);
409 fout << "# This is the CMakeCache file.\n"
410 << "# For build in directory: " << currentcwd << "\n";
411 cmCacheManager::CacheEntry* cmakeCacheEntry
412 = this->GetCacheEntry("CMAKE_COMMAND");
413 if ( cmakeCacheEntry )
415 fout << "# It was generated by CMake: " <<
416 cmakeCacheEntry->Value << std::endl;
419 fout << "# You can edit this file to change values found and used by cmake."
420 << std::endl
421 << "# If you do not want to change any of the values, simply exit the "
422 "editor." << std::endl
423 << "# If you do want to change a value, simply edit, save, and exit "
424 "the editor." << std::endl
425 << "# The syntax for the file is as follows:\n"
426 << "# KEY:TYPE=VALUE\n"
427 << "# KEY is the name of a variable in the cache.\n"
428 << "# TYPE is a hint to GUI's for the type of VALUE, DO NOT EDIT "
429 "TYPE!." << std::endl
430 << "# VALUE is the current value for the KEY.\n\n";
432 fout << "########################\n";
433 fout << "# EXTERNAL cache entries\n";
434 fout << "########################\n";
435 fout << "\n";
437 for( std::map<cmStdString, CacheEntry>::const_iterator i =
438 this->Cache.begin(); i != this->Cache.end(); ++i)
440 const CacheEntry& ce = (*i).second;
441 CacheEntryType t = ce.Type;
442 if(!ce.Initialized)
445 // This should be added in, but is not for now.
446 cmSystemTools::Error("Cache entry \"", (*i).first.c_str(),
447 "\" is uninitialized");
450 else if(t != INTERNAL)
452 // Format is key:type=value
453 std::map<cmStdString,cmStdString>::const_iterator it =
454 ce.Properties.find("HELPSTRING");
455 if ( it == ce.Properties.end() )
457 cmCacheManager::OutputHelpString(fout, "Missing description");
459 else
461 cmCacheManager::OutputHelpString(fout, it->second);
463 std::string key;
464 // support : in key name by double quoting
465 if((*i).first.find(':') != std::string::npos ||
466 (*i).first.find("//") == 0)
468 key = "\"";
469 key += i->first;
470 key += "\"";
472 else
474 key = i->first;
476 fout << key.c_str() << ":"
477 << cmCacheManagerTypes[t] << "=";
478 // if value has trailing space or tab, enclose it in single quotes
479 if (ce.Value.size() &&
480 (ce.Value[ce.Value.size() - 1] == ' ' ||
481 ce.Value[ce.Value.size() - 1] == '\t'))
483 fout << '\'' << ce.Value << '\'';
485 else
487 fout << ce.Value;
489 fout << "\n\n";
493 fout << "\n";
494 fout << "########################\n";
495 fout << "# INTERNAL cache entries\n";
496 fout << "########################\n";
497 fout << "\n";
499 for( cmCacheManager::CacheIterator i = this->NewIterator();
500 !i.IsAtEnd(); i.Next())
502 if ( !i.Initialized() )
504 continue;
507 CacheEntryType t = i.GetType();
508 bool advanced = i.PropertyExists("ADVANCED");
509 if ( advanced )
511 // Format is key:type=value
512 std::string key;
513 std::string rkey = i.GetName();
514 std::string helpstring;
515 // If this is advanced variable, we have to do some magic for
516 // backward compatibility
517 helpstring = "Advanced flag for variable: ";
518 helpstring += i.GetName();
519 rkey += "-ADVANCED";
520 cmCacheManager::OutputHelpString(fout, helpstring.c_str());
521 // support : in key name by double quoting
522 if(rkey.find(':') != std::string::npos ||
523 rkey.find("//") == 0)
525 key = "\"";
526 key += rkey;
527 key += "\"";
529 else
531 key = rkey;
533 fout << key.c_str() << ":INTERNAL="
534 << (i.GetPropertyAsBool("ADVANCED") ? "1" : "0") << "\n";
536 bool modified = i.PropertyExists("MODIFIED");
537 if ( modified )
539 // Format is key:type=value
540 std::string key;
541 std::string rkey = i.GetName();
542 std::string helpstring;
543 // If this is advanced variable, we have to do some magic for
544 // backward compatibility
545 helpstring = "Modified flag for variable: ";
546 helpstring += i.GetName();
547 rkey += "-MODIFIED";
548 cmCacheManager::OutputHelpString(fout, helpstring.c_str());
549 // support : in key name by double quoting
550 if(rkey.find(':') != std::string::npos ||
551 rkey.find("//") == 0)
553 key = "\"";
554 key += rkey;
555 key += "\"";
557 else
559 key = rkey;
561 fout << key.c_str() << ":INTERNAL="
562 << (i.GetPropertyAsBool("MODIFIED") ? "1" : "0") << "\n";
564 if(t == cmCacheManager::INTERNAL)
566 // Format is key:type=value
567 std::string key;
568 std::string rkey = i.GetName();
569 std::string helpstring;
570 const char* hs = i.GetProperty("HELPSTRING");
571 if ( hs )
573 helpstring = i.GetProperty("HELPSTRING");
575 else
577 helpstring = "";
579 cmCacheManager::OutputHelpString(fout, helpstring.c_str());
580 // support : in key name by double quoting
581 if(rkey.find(':') != std::string::npos ||
582 rkey.find("//") == 0)
584 key = "\"";
585 key += rkey;
586 key += "\"";
588 else
590 key = rkey;
592 fout << key.c_str() << ":"
593 << cmCacheManagerTypes[t] << "=";
594 // if value has trailing space or tab, enclose it in single quotes
595 std::string value = i.GetValue();
596 if (value.size() &&
597 (value[value.size() - 1] == ' ' ||
598 value[value.size() - 1] == '\t'))
600 fout << '\'' << value << '\'';
602 else
604 fout << value;
606 fout << "\n";
609 fout << "\n";
610 fout.close();
611 cmSystemTools::CopyFileIfDifferent(tempFile.c_str(),
612 cacheFile.c_str());
613 cmSystemTools::RemoveFile(tempFile.c_str());
614 std::string checkCacheFile = path;
615 checkCacheFile += cmake::GetCMakeFilesDirectory();
616 cmSystemTools::MakeDirectory(checkCacheFile.c_str());
617 checkCacheFile += "/cmake.check_cache";
618 std::ofstream checkCache(checkCacheFile.c_str());
619 if(!checkCache)
621 cmSystemTools::Error("Unable to open check cache file for write. ",
622 checkCacheFile.c_str());
623 return false;
625 checkCache << "# This file is generated by cmake for dependency checking "
626 "of the CMakeCache.txt file\n";
627 return true;
630 bool cmCacheManager::DeleteCache(const char* path)
632 std::string cacheFile = path;
633 cmSystemTools::ConvertToUnixSlashes(cacheFile);
634 std::string cmakeFiles = cacheFile;
635 cacheFile += "/CMakeCache.txt";
636 cmSystemTools::RemoveFile(cacheFile.c_str());
637 // now remove the files in the CMakeFiles directory
638 // this cleans up language cache files
639 cmsys::Directory dir;
640 cmakeFiles += cmake::GetCMakeFilesDirectory();
641 dir.Load(cmakeFiles.c_str());
642 for (unsigned long fileNum = 0;
643 fileNum < dir.GetNumberOfFiles();
644 ++fileNum)
646 if(!cmSystemTools::
647 FileIsDirectory(dir.GetFile(fileNum)))
649 std::string fullPath = cmakeFiles;
650 fullPath += "/";
651 fullPath += dir.GetFile(fileNum);
652 cmSystemTools::RemoveFile(fullPath.c_str());
655 return true;
658 void cmCacheManager::OutputHelpString(std::ofstream& fout,
659 const std::string& helpString)
661 std::string::size_type end = helpString.size();
662 if(end == 0)
664 return;
666 std::string oneLine;
667 std::string::size_type pos = 0;
668 for (std::string::size_type i=0; i<=end; i++)
670 if ((i==end)
671 || (helpString[i]=='\n')
672 || ((i-pos >= 60) && (helpString[i]==' ')))
674 fout << "//";
675 if (helpString[pos] == '\n')
677 pos++;
678 fout << "\\n";
680 oneLine = helpString.substr(pos, i - pos);
681 fout << oneLine.c_str() << "\n";
682 pos = i;
687 void cmCacheManager::RemoveCacheEntry(const char* key)
689 CacheEntryMap::iterator i = this->Cache.find(key);
690 if(i != this->Cache.end())
692 this->Cache.erase(i);
694 else
696 std::cerr << "Failed to remove entry:" << key << std::endl;
701 cmCacheManager::CacheEntry *cmCacheManager::GetCacheEntry(const char* key)
703 CacheEntryMap::iterator i = this->Cache.find(key);
704 if(i != this->Cache.end())
706 return &i->second;
708 return 0;
711 cmCacheManager::CacheIterator cmCacheManager::GetCacheIterator(
712 const char *key)
714 return CacheIterator(*this, key);
717 const char* cmCacheManager::GetCacheValue(const char* key) const
719 CacheEntryMap::const_iterator i = this->Cache.find(key);
720 if(i != this->Cache.end() &&
721 i->second.Initialized)
723 return i->second.Value.c_str();
725 return 0;
729 void cmCacheManager::PrintCache(std::ostream& out) const
731 out << "=================================================" << std::endl;
732 out << "CMakeCache Contents:" << std::endl;
733 for(std::map<cmStdString, CacheEntry>::const_iterator i =
734 this->Cache.begin(); i != this->Cache.end(); ++i)
736 if((*i).second.Type != INTERNAL)
738 out << (*i).first.c_str() << " = " << (*i).second.Value.c_str()
739 << std::endl;
742 out << "\n\n";
743 out << "To change values in the CMakeCache, "
744 << std::endl << "edit CMakeCache.txt in your output directory.\n";
745 out << "=================================================" << std::endl;
749 void cmCacheManager::AddCacheEntry(const char* key,
750 const char* value,
751 const char* helpString,
752 CacheEntryType type)
754 CacheEntry& e = this->Cache[key];
755 if ( value )
757 e.Value = value;
758 e.Initialized = true;
760 else
762 e.Value = "";
764 e.Type = type;
765 // make sure we only use unix style paths
766 if(type == FILEPATH || type == PATH)
768 cmSystemTools::ConvertToUnixSlashes(e.Value);
770 if ( helpString )
772 e.Properties["HELPSTRING"] = helpString;
774 else
776 e.Properties["HELPSTRING"] =
777 "(This variable does not exist and should not be used)";
779 this->Cache[key] = e;
782 void cmCacheManager::AddCacheEntry(const char* key, bool v,
783 const char* helpString)
785 if(v)
787 this->AddCacheEntry(key, "ON", helpString, cmCacheManager::BOOL);
789 else
791 this->AddCacheEntry(key, "OFF", helpString, cmCacheManager::BOOL);
795 bool cmCacheManager::CacheIterator::IsAtEnd() const
797 return this->Position == this->Container.Cache.end();
800 void cmCacheManager::CacheIterator::Begin()
802 this->Position = this->Container.Cache.begin();
805 bool cmCacheManager::CacheIterator::Find(const char* key)
807 this->Position = this->Container.Cache.find(key);
808 return !this->IsAtEnd();
811 void cmCacheManager::CacheIterator::Next()
813 if (!this->IsAtEnd())
815 ++this->Position;
819 void cmCacheManager::CacheIterator::SetValue(const char* value)
821 if (this->IsAtEnd())
823 return;
825 CacheEntry* entry = &this->GetEntry();
826 if ( value )
828 entry->Value = value;
829 entry->Initialized = true;
831 else
833 entry->Value = "";
837 const char* cmCacheManager::CacheIterator::GetProperty(
838 const char* property) const
840 // make sure it is not at the end
841 if (this->IsAtEnd())
843 return 0;
846 if ( !strcmp(property, "TYPE") || !strcmp(property, "VALUE") )
848 cmSystemTools::Error("Property \"", property,
849 "\" cannot be accessed through the GetProperty()");
850 return 0;
852 const CacheEntry* ent = &this->GetEntry();
853 std::map<cmStdString,cmStdString>::const_iterator it =
854 ent->Properties.find(property);
855 if ( it == ent->Properties.end() )
857 return 0;
859 return it->second.c_str();
862 void cmCacheManager::CacheIterator::SetProperty(const char* p, const char* v)
864 // make sure it is not at the end
865 if (this->IsAtEnd())
867 return;
870 if ( !strcmp(p, "TYPE") || !strcmp(p, "VALUE") )
872 cmSystemTools::Error("Property \"", p,
873 "\" cannot be accessed through the SetProperty()");
874 return;
876 CacheEntry* ent = &this->GetEntry();
877 ent->Properties[p] = v;
881 bool cmCacheManager::CacheIterator::GetValueAsBool() const
883 return cmSystemTools::IsOn(this->GetEntry().Value.c_str());
886 bool cmCacheManager::CacheIterator::GetPropertyAsBool(
887 const char* property) const
889 // make sure it is not at the end
890 if (this->IsAtEnd())
892 return false;
895 if ( !strcmp(property, "TYPE") || !strcmp(property, "VALUE") )
897 cmSystemTools::Error("Property \"", property,
898 "\" cannot be accessed through the GetPropertyAsBool()");
899 return false;
901 const CacheEntry* ent = &this->GetEntry();
902 std::map<cmStdString,cmStdString>::const_iterator it =
903 ent->Properties.find(property);
904 if ( it == ent->Properties.end() )
906 return false;
908 return cmSystemTools::IsOn(it->second.c_str());
912 void cmCacheManager::CacheIterator::SetProperty(const char* p, bool v)
914 // make sure it is not at the end
915 if (this->IsAtEnd())
917 return;
920 if ( !strcmp(p, "TYPE") || !strcmp(p, "VALUE") )
922 cmSystemTools::Error("Property \"", p,
923 "\" cannot be accessed through the SetProperty()");
924 return;
926 CacheEntry* ent = &this->GetEntry();
927 ent->Properties[p] = v ? "ON" : "OFF";
930 bool cmCacheManager::CacheIterator::PropertyExists(const char* property) const
932 // make sure it is not at the end
933 if (this->IsAtEnd())
935 return false;
938 if ( !strcmp(property, "TYPE") || !strcmp(property, "VALUE") )
940 cmSystemTools::Error("Property \"", property,
941 "\" cannot be accessed through the PropertyExists()");
942 return false;
944 const CacheEntry* ent = &this->GetEntry();
945 std::map<cmStdString,cmStdString>::const_iterator it =
946 ent->Properties.find(property);
947 if ( it == ent->Properties.end() )
949 return false;
951 return true;