summaryrefslogtreecommitdiffstats
path: root/Source/CursesDialog
diff options
context:
space:
mode:
authorBrad King <brad.king@kitware.com>2015-04-07 21:14:41 (GMT)
committerBrad King <brad.king@kitware.com>2015-04-07 21:15:04 (GMT)
commit3347c5e4f9fcdd36c06067d6c7cd5a985a9c5d94 (patch)
treed0372265c5b1f07f9b1a8a6cc9bedf96bed2dbcb /Source/CursesDialog
parent9410e24a4ad3a21b2c27d057798f723e88d14d45 (diff)
downloadCMake-3347c5e4f9fcdd36c06067d6c7cd5a985a9c5d94.zip
CMake-3347c5e4f9fcdd36c06067d6c7cd5a985a9c5d94.tar.gz
CMake-3347c5e4f9fcdd36c06067d6c7cd5a985a9c5d94.tar.bz2
Revert topic 'refactor-cache-api'
This topic was never tested without some follow-up commits. The GetCacheEntryValue API returns a pointer to memory freed on return. It will have to be revised along with the rest of the original topic.
Diffstat (limited to 'Source/CursesDialog')
-rw-r--r--Source/CursesDialog/cmCursesCacheEntryComposite.cxx35
-rw-r--r--Source/CursesDialog/cmCursesCacheEntryComposite.h2
-rw-r--r--Source/CursesDialog/cmCursesMainForm.cxx151
3 files changed, 77 insertions, 111 deletions
diff --git a/Source/CursesDialog/cmCursesCacheEntryComposite.cxx b/Source/CursesDialog/cmCursesCacheEntryComposite.cxx
index 4f028c4..682f95f 100644
--- a/Source/CursesDialog/cmCursesCacheEntryComposite.cxx
+++ b/Source/CursesDialog/cmCursesCacheEntryComposite.cxx
@@ -18,9 +18,6 @@
#include "cmCursesFilePathWidget.h"
#include "cmCursesDummyWidget.h"
#include "../cmSystemTools.h"
-#include "../cmake.h"
-
-#include <assert.h>
cmCursesCacheEntryComposite::cmCursesCacheEntryComposite(
const std::string& key,
@@ -35,7 +32,7 @@ cmCursesCacheEntryComposite::cmCursesCacheEntryComposite(
}
cmCursesCacheEntryComposite::cmCursesCacheEntryComposite(
- const std::string& key, cmake *cm, bool isNew,
+ const std::string& key, const cmCacheManager::CacheIterator& it, bool isNew,
int labelwidth, int entrywidth)
: Key(key), LabelWidth(labelwidth), EntryWidth(entrywidth)
{
@@ -50,13 +47,11 @@ cmCursesCacheEntryComposite::cmCursesCacheEntryComposite(
}
this->Entry = 0;
- const char* value = cm->GetCacheManager()->GetCacheEntryValue(key);
- assert(value);
- switch (cm->GetCacheManager()->GetCacheEntryType(key))
+ switch ( it.GetType() )
{
- case cmCacheManager::BOOL:
+ case cmCacheManager::BOOL:
this->Entry = new cmCursesBoolWidget(this->EntryWidth, 1, 1, 1);
- if (cmSystemTools::IsOn(value))
+ if (cmSystemTools::IsOn(it.GetValue().c_str()))
{
static_cast<cmCursesBoolWidget*>(this->Entry)->SetValueAsBool(true);
}
@@ -67,40 +62,40 @@ cmCursesCacheEntryComposite::cmCursesCacheEntryComposite(
break;
case cmCacheManager::PATH:
this->Entry = new cmCursesPathWidget(this->EntryWidth, 1, 1, 1);
- static_cast<cmCursesPathWidget*>(this->Entry)->SetString(value);
+ static_cast<cmCursesPathWidget*>(this->Entry)->SetString(
+ it.GetValue());
break;
case cmCacheManager::FILEPATH:
this->Entry = new cmCursesFilePathWidget(this->EntryWidth, 1, 1, 1);
- static_cast<cmCursesFilePathWidget*>(this->Entry)->SetString(value);
+ static_cast<cmCursesFilePathWidget*>(this->Entry)->SetString(
+ it.GetValue());
break;
case cmCacheManager::STRING:
- {
- const char* stringsProp = cm->GetCacheManager()
- ->GetCacheEntryProperty(key, "STRINGS");
- if(stringsProp)
+ if(it.PropertyExists("STRINGS"))
{
cmCursesOptionsWidget* ow =
new cmCursesOptionsWidget(this->EntryWidth, 1, 1, 1);
this->Entry = ow;
std::vector<std::string> options;
- cmSystemTools::ExpandListArgument(stringsProp, options);
+ cmSystemTools::ExpandListArgument(
+ std::string(it.GetProperty("STRINGS")), options);
for(std::vector<std::string>::iterator
si = options.begin(); si != options.end(); ++si)
{
ow->AddOption(*si);
}
- ow->SetOption(value);
+ ow->SetOption(it.GetValue());
}
else
{
this->Entry = new cmCursesStringWidget(this->EntryWidth, 1, 1, 1);
- static_cast<cmCursesStringWidget*>(this->Entry)->SetString(value);
+ static_cast<cmCursesStringWidget*>(this->Entry)->SetString(
+ it.GetValue());
}
break;
- }
case cmCacheManager::UNINITIALIZED:
cmSystemTools::Error("Found an undefined variable: ",
- key.c_str());
+ it.GetName().c_str());
break;
default:
// TODO : put warning message here
diff --git a/Source/CursesDialog/cmCursesCacheEntryComposite.h b/Source/CursesDialog/cmCursesCacheEntryComposite.h
index dc4ee4af..7cdf13b 100644
--- a/Source/CursesDialog/cmCursesCacheEntryComposite.h
+++ b/Source/CursesDialog/cmCursesCacheEntryComposite.h
@@ -21,7 +21,7 @@ public:
cmCursesCacheEntryComposite(const std::string& key, int labelwidth,
int entrywidth);
cmCursesCacheEntryComposite(const std::string& key,
- cmake *cm,
+ const cmCacheManager::CacheIterator& it,
bool isNew, int labelwidth, int entrywidth);
~cmCursesCacheEntryComposite();
const char* GetValue();
diff --git a/Source/CursesDialog/cmCursesMainForm.cxx b/Source/CursesDialog/cmCursesMainForm.cxx
index 833d540..d60062e 100644
--- a/Source/CursesDialog/cmCursesMainForm.cxx
+++ b/Source/CursesDialog/cmCursesMainForm.cxx
@@ -111,17 +111,13 @@ void cmCursesMainForm::InitializeUI()
// Count non-internal and non-static entries
int count=0;
- std::vector<std::string> cacheKeys =
- this->CMakeInstance->GetCacheManager()->GetCacheEntryKeys();
-
- for(std::vector<std::string>::const_iterator it = cacheKeys.begin();
- it != cacheKeys.end(); ++it)
+ for(cmCacheManager::CacheIterator i =
+ this->CMakeInstance->GetCacheManager()->NewIterator();
+ !i.IsAtEnd(); i.Next())
{
- cmCacheManager::CacheEntryType t = this->CMakeInstance->GetCacheManager()
- ->GetCacheEntryType(*it);
- if (t != cmCacheManager::INTERNAL &&
- t != cmCacheManager::STATIC &&
- t != cmCacheManager::UNINITIALIZED)
+ if ( i.GetType() != cmCacheManager::INTERNAL &&
+ i.GetType() != cmCacheManager::STATIC &&
+ i.GetType() != cmCacheManager::UNINITIALIZED)
{
++count;
}
@@ -143,49 +139,45 @@ void cmCursesMainForm::InitializeUI()
// Create the composites.
// First add entries which are new
- for(std::vector<std::string>::const_iterator it = cacheKeys.begin();
- it != cacheKeys.end(); ++it)
+ for(cmCacheManager::CacheIterator i =
+ this->CMakeInstance->GetCacheManager()->NewIterator();
+ !i.IsAtEnd(); i.Next())
{
- std::string key = *it;
- cmCacheManager::CacheEntryType t = this->CMakeInstance->GetCacheManager()
- ->GetCacheEntryType(*it);
- if (t == cmCacheManager::INTERNAL ||
- t == cmCacheManager::STATIC ||
- t == cmCacheManager::UNINITIALIZED )
+ std::string key = i.GetName();
+ if ( i.GetType() == cmCacheManager::INTERNAL ||
+ i.GetType() == cmCacheManager::STATIC ||
+ i.GetType() == cmCacheManager::UNINITIALIZED )
{
continue;
}
if (!this->LookForCacheEntry(key))
{
- newEntries->push_back(new cmCursesCacheEntryComposite(key,
- this->CMakeInstance,
- true, 30,
- entrywidth));
+ newEntries->push_back(new cmCursesCacheEntryComposite(key, i,
+ true, 30,
+ entrywidth));
this->OkToGenerate = false;
}
}
// then add entries which are old
- for(std::vector<std::string>::const_iterator it = cacheKeys.begin();
- it != cacheKeys.end(); ++it)
+ for(cmCacheManager::CacheIterator i =
+ this->CMakeInstance->GetCacheManager()->NewIterator();
+ !i.IsAtEnd(); i.Next())
{
- std::string key = *it;
- cmCacheManager::CacheEntryType t = this->CMakeInstance->GetCacheManager()
- ->GetCacheEntryType(*it);
- if (t == cmCacheManager::INTERNAL ||
- t == cmCacheManager::STATIC ||
- t == cmCacheManager::UNINITIALIZED )
+ std::string key = i.GetName();
+ if ( i.GetType() == cmCacheManager::INTERNAL ||
+ i.GetType() == cmCacheManager::STATIC ||
+ i.GetType() == cmCacheManager::UNINITIALIZED )
{
continue;
}
if (this->LookForCacheEntry(key))
{
- newEntries->push_back(new cmCursesCacheEntryComposite(key,
- this->CMakeInstance,
- false, 30,
- entrywidth));
+ newEntries->push_back(new cmCursesCacheEntryComposite(key, i,
+ false, 30,
+ entrywidth));
}
}
}
@@ -224,13 +216,10 @@ void cmCursesMainForm::RePost()
std::vector<cmCursesCacheEntryComposite*>::iterator it;
for (it = this->Entries->begin(); it != this->Entries->end(); ++it)
{
- const char* existingValue =
- this->CMakeInstance->GetCacheManager()
- ->GetCacheEntryValue((*it)->GetValue());
- bool advanced =
- this->CMakeInstance->GetCacheManager()
- ->GetCacheEntryPropertyAsBool((*it)->GetValue(), "ADVANCED");
- if (!existingValue || (!this->AdvancedMode && advanced))
+ cmCacheManager::CacheIterator mit =
+ this->CMakeInstance->GetCacheManager()->GetCacheIterator((*it)->GetValue());
+ if (mit.IsAtEnd() ||
+ (!this->AdvancedMode && mit.GetPropertyAsBool("ADVANCED")))
{
continue;
}
@@ -256,13 +245,10 @@ void cmCursesMainForm::RePost()
std::vector<cmCursesCacheEntryComposite*>::iterator it;
for (it = this->Entries->begin(); it != this->Entries->end(); ++it)
{
- const char* existingValue =
- this->CMakeInstance->GetCacheManager()
- ->GetCacheEntryValue((*it)->GetValue());
- bool advanced =
- this->CMakeInstance->GetCacheManager()
- ->GetCacheEntryPropertyAsBool((*it)->GetValue(), "ADVANCED");
- if (!existingValue || (!this->AdvancedMode && advanced))
+ cmCacheManager::CacheIterator mit =
+ this->CMakeInstance->GetCacheManager()->GetCacheIterator((*it)->GetValue());
+ if (mit.IsAtEnd() ||
+ (!this->AdvancedMode && mit.GetPropertyAsBool("ADVANCED")))
{
continue;
}
@@ -328,13 +314,10 @@ void cmCursesMainForm::Render(int left, int top, int width, int height)
std::vector<cmCursesCacheEntryComposite*>::iterator it;
for (it = this->Entries->begin(); it != this->Entries->end(); ++it)
{
- const char* existingValue =
- this->CMakeInstance->GetCacheManager()
- ->GetCacheEntryValue((*it)->GetValue());
- bool advanced =
- this->CMakeInstance->GetCacheManager()
- ->GetCacheEntryPropertyAsBool((*it)->GetValue(), "ADVANCED");
- if (!existingValue || (!this->AdvancedMode && advanced))
+ cmCacheManager::CacheIterator mit =
+ this->CMakeInstance->GetCacheManager()->GetCacheIterator((*it)->GetValue());
+ if (mit.IsAtEnd() ||
+ (!this->AdvancedMode && mit.GetPropertyAsBool("ADVANCED")))
{
continue;
}
@@ -351,13 +334,10 @@ void cmCursesMainForm::Render(int left, int top, int width, int height)
std::vector<cmCursesCacheEntryComposite*>::iterator it;
for (it = this->Entries->begin(); it != this->Entries->end(); ++it)
{
- const char* existingValue =
- this->CMakeInstance->GetCacheManager()
- ->GetCacheEntryValue((*it)->GetValue());
- bool advanced =
- this->CMakeInstance->GetCacheManager()
- ->GetCacheEntryPropertyAsBool((*it)->GetValue(), "ADVANCED");
- if (!existingValue || (!this->AdvancedMode && advanced))
+ cmCacheManager::CacheIterator mit =
+ this->CMakeInstance->GetCacheManager()->GetCacheIterator((*it)->GetValue());
+ if (mit.IsAtEnd() ||
+ (!this->AdvancedMode && mit.GetPropertyAsBool("ADVANCED")))
{
continue;
}
@@ -515,12 +495,11 @@ void cmCursesMainForm::UpdateStatusBar(const char* message)
// Get the help string of the current entry
// and add it to the help string
- const char* existingValue =
- this->CMakeInstance->GetCacheManager()->GetCacheEntryValue(curField);
- if (existingValue)
+ cmCacheManager::CacheIterator it =
+ this->CMakeInstance->GetCacheManager()->GetCacheIterator(curField);
+ if (!it.IsAtEnd())
{
- const char* hs = this->CMakeInstance->GetCacheManager()
- ->GetCacheEntryProperty(curField, "HELPSTRING");
+ const char* hs = it.GetProperty("HELPSTRING");
if ( hs )
{
strncpy(help, hs, 127);
@@ -660,7 +639,7 @@ int cmCursesMainForm::Configure(int noconfigure)
// always save the current gui values to disk
this->FillCacheManagerFromUI();
- this->CMakeInstance->SaveCache(
+ this->CMakeInstance->GetCacheManager()->SaveCache(
this->CMakeInstance->GetHomeOutputDirectory());
this->LoadCache(0);
@@ -813,28 +792,23 @@ void cmCursesMainForm::FillCacheManagerFromUI()
size_t size = this->Entries->size();
for(size_t i=0; i < size; i++)
{
- std::string cacheKey = (*this->Entries)[i]->Key;
- const char* existingValue = this->CMakeInstance->GetCacheManager()
- ->GetCacheEntryValue(cacheKey);
- if (existingValue)
+ cmCacheManager::CacheIterator it =
+ this->CMakeInstance->GetCacheManager()->GetCacheIterator(
+ (*this->Entries)[i]->Key.c_str());
+ if (!it.IsAtEnd())
{
- std::string oldValue = existingValue;
+ std::string oldValue = it.GetValue();
std::string newValue = (*this->Entries)[i]->Entry->GetValue();
std::string fixedOldValue;
std::string fixedNewValue;
- cmCacheManager::CacheEntryType t =
- this->CMakeInstance->GetCacheManager()
- ->GetCacheEntryType(cacheKey);
- this->FixValue(t, oldValue, fixedOldValue);
- this->FixValue(t, newValue, fixedNewValue);
+ this->FixValue(it.GetType(), oldValue, fixedOldValue);
+ this->FixValue(it.GetType(), newValue, fixedNewValue);
if(!(fixedOldValue == fixedNewValue))
{
// The user has changed the value. Mark it as modified.
- this->CMakeInstance->GetCacheManager()
- ->SetCacheEntryBoolProperty(cacheKey, "MODIFIED", true);
- this->CMakeInstance->GetCacheManager()
- ->SetCacheEntryValue(cacheKey, fixedNewValue);
+ it.SetProperty("MODIFIED", true);
+ it.SetValue(fixedNewValue.c_str());
}
}
}
@@ -1043,15 +1017,12 @@ void cmCursesMainForm::HandleInput()
cmCursesWidget* lbl = reinterpret_cast<cmCursesWidget*>(field_userptr(
this->Fields[findex-2]));
const char* curField = lbl->GetValue();
- const char* helpString = 0;
-
- const char* existingValue =
- this->CMakeInstance->GetCacheManager()
- ->GetCacheEntryValue(curField);
- if (existingValue)
+ const char* helpString=0;
+ cmCacheManager::CacheIterator it =
+ this->CMakeInstance->GetCacheManager()->GetCacheIterator(curField);
+ if (!it.IsAtEnd())
{
- helpString = this->CMakeInstance->GetCacheManager()
- ->GetCacheEntryProperty(curField, "HELPSTRING");
+ helpString = it.GetProperty("HELPSTRING");
}
if (helpString)
{