Couple of changes: cache variables now have a map of properties. ADVANCED and HELPSTRING are now properties of cache variable, IsAdvanced is gone, so is GetCacheEntry, since cache entries are now all private. To access them, you use the iterator. -ADVANCED cache entries are gone and are replaced by the property of cache variables. The cache file still looks the same, but the -ADVANCED cache entries are created when writing file. MarkAsAdvanced and VariableRequires are fixed. So are curses gui and wizard

This commit is contained in:
Andy Cedilnik 2002-09-11 14:05:45 -04:00
parent bfdf8f7dcd
commit bef93dc5c1
12 changed files with 336 additions and 155 deletions

View File

@ -34,7 +34,7 @@ cmCursesCacheEntryComposite::cmCursesCacheEntryComposite(const char* key,
} }
cmCursesCacheEntryComposite::cmCursesCacheEntryComposite( cmCursesCacheEntryComposite::cmCursesCacheEntryComposite(
const char* key, const cmCacheManager::CacheEntry& value, bool isNew, const char* key, const cmCacheManager::CacheIterator& it, bool isNew,
int labelwidth, int entrywidth) int labelwidth, int entrywidth)
: m_Key(key), m_LabelWidth(labelwidth), m_EntryWidth(entrywidth) : m_Key(key), m_LabelWidth(labelwidth), m_EntryWidth(entrywidth)
{ {
@ -49,11 +49,11 @@ cmCursesCacheEntryComposite::cmCursesCacheEntryComposite(
} }
m_Entry = 0; m_Entry = 0;
switch ( value.m_Type ) switch ( it.GetType() )
{ {
case cmCacheManager::BOOL: case cmCacheManager::BOOL:
m_Entry = new cmCursesBoolWidget(m_EntryWidth, 1, 1, 1); m_Entry = new cmCursesBoolWidget(m_EntryWidth, 1, 1, 1);
if (cmSystemTools::IsOn(value.m_Value.c_str())) if (cmSystemTools::IsOn(it.GetValue()))
{ {
static_cast<cmCursesBoolWidget*>(m_Entry)->SetValueAsBool(true); static_cast<cmCursesBoolWidget*>(m_Entry)->SetValueAsBool(true);
} }
@ -65,17 +65,20 @@ cmCursesCacheEntryComposite::cmCursesCacheEntryComposite(
case cmCacheManager::PATH: case cmCacheManager::PATH:
m_Entry = new cmCursesPathWidget(m_EntryWidth, 1, 1, 1); m_Entry = new cmCursesPathWidget(m_EntryWidth, 1, 1, 1);
static_cast<cmCursesPathWidget*>(m_Entry)->SetString( static_cast<cmCursesPathWidget*>(m_Entry)->SetString(
value.m_Value.c_str()); it.GetValue());
break; break;
case cmCacheManager::FILEPATH: case cmCacheManager::FILEPATH:
m_Entry = new cmCursesFilePathWidget(m_EntryWidth, 1, 1, 1); m_Entry = new cmCursesFilePathWidget(m_EntryWidth, 1, 1, 1);
static_cast<cmCursesFilePathWidget*>(m_Entry)->SetString( static_cast<cmCursesFilePathWidget*>(m_Entry)->SetString(
value.m_Value.c_str()); it.GetValue());
break; break;
case cmCacheManager::STRING: case cmCacheManager::STRING:
m_Entry = new cmCursesStringWidget(m_EntryWidth, 1, 1, 1); m_Entry = new cmCursesStringWidget(m_EntryWidth, 1, 1, 1);
static_cast<cmCursesStringWidget*>(m_Entry)->SetString( static_cast<cmCursesStringWidget*>(m_Entry)->SetString(
value.m_Value.c_str()); it.GetValue());
break;
case cmCacheManager::UNINITIALIZED:
cmSystemTools::Error("Found an undefined variable: ", it.GetName());
break; break;
default: default:
// TODO : put warning message here // TODO : put warning message here

View File

@ -25,7 +25,7 @@ class cmCursesCacheEntryComposite
public: public:
cmCursesCacheEntryComposite(const char* key, int labelwidth, int entrywidth); cmCursesCacheEntryComposite(const char* key, int labelwidth, int entrywidth);
cmCursesCacheEntryComposite(const char* key, cmCursesCacheEntryComposite(const char* key,
const cmCacheManager::CacheEntry& value, const cmCacheManager::CacheIterator& it,
bool isNew, int labelwidth, int entrywidth); bool isNew, int labelwidth, int entrywidth);
~cmCursesCacheEntryComposite(); ~cmCursesCacheEntryComposite();
const char* GetValue(); const char* GetValue();

View File

@ -117,9 +117,9 @@ void cmCursesMainForm::InitializeUI()
this->m_CMakeInstance->GetCacheManager()->NewIterator(); this->m_CMakeInstance->GetCacheManager()->NewIterator();
!i.IsAtEnd(); i.Next()) !i.IsAtEnd(); i.Next())
{ {
const cmCacheManager::CacheEntry& value = i.GetEntry(); if ( i.GetType() != cmCacheManager::INTERNAL &&
if ( value.m_Type != cmCacheManager::INTERNAL && i.GetType() != cmCacheManager::STATIC &&
value.m_Type != cmCacheManager::STATIC ) i.GetType() != cmCacheManager::UNINITIALIZED)
{ {
++count; ++count;
} }
@ -146,16 +146,16 @@ void cmCursesMainForm::InitializeUI()
!i.IsAtEnd(); i.Next()) !i.IsAtEnd(); i.Next())
{ {
const char* key = i.GetName(); const char* key = i.GetName();
const cmCacheManager::CacheEntry& value = i.GetEntry(); if ( i.GetType() == cmCacheManager::INTERNAL ||
if ( value.m_Type == cmCacheManager::INTERNAL || i.GetType() == cmCacheManager::STATIC ||
value.m_Type == cmCacheManager::STATIC ) i.GetType() == cmCacheManager::UNINITIALIZED )
{ {
continue; continue;
} }
if (!this->LookForCacheEntry(key)) if (!this->LookForCacheEntry(key))
{ {
newEntries->push_back(new cmCursesCacheEntryComposite(key, value, newEntries->push_back(new cmCursesCacheEntryComposite(key, i,
true, 30, true, 30,
entrywidth)); entrywidth));
m_OkToGenerate = false; m_OkToGenerate = false;
@ -168,16 +168,16 @@ void cmCursesMainForm::InitializeUI()
!i.IsAtEnd(); i.Next()) !i.IsAtEnd(); i.Next())
{ {
const char* key = i.GetName(); const char* key = i.GetName();
const cmCacheManager::CacheEntry& value = i.GetEntry(); if ( i.GetType() == cmCacheManager::INTERNAL ||
if ( value.m_Type == cmCacheManager::INTERNAL || i.GetType() == cmCacheManager::STATIC ||
value.m_Type == cmCacheManager::STATIC ) i.GetType() == cmCacheManager::UNINITIALIZED )
{ {
continue; continue;
} }
if (this->LookForCacheEntry(key)) if (this->LookForCacheEntry(key))
{ {
newEntries->push_back(new cmCursesCacheEntryComposite(key, value, newEntries->push_back(new cmCursesCacheEntryComposite(key, i,
false, 30, false, 30,
entrywidth)); entrywidth));
} }
@ -224,9 +224,9 @@ void cmCursesMainForm::RePost()
std::vector<cmCursesCacheEntryComposite*>::iterator it; std::vector<cmCursesCacheEntryComposite*>::iterator it;
for (it = m_Entries->begin(); it != m_Entries->end(); ++it) for (it = m_Entries->begin(); it != m_Entries->end(); ++it)
{ {
if (!m_AdvancedMode && cmCacheManager::CacheIterator mit =
this->m_CMakeInstance->GetCacheManager()->IsAdvanced( this->m_CMakeInstance->GetCacheManager()->GetCacheIterator((*it)->GetValue());
(*it)->GetValue())) if (mit.IsAtEnd() || !m_AdvancedMode && mit.GetPropertyAsBool("ADVANCED"))
{ {
continue; continue;
} }
@ -243,8 +243,9 @@ void cmCursesMainForm::RePost()
std::vector<cmCursesCacheEntryComposite*>::iterator it; std::vector<cmCursesCacheEntryComposite*>::iterator it;
for (it = m_Entries->begin(); it != m_Entries->end(); ++it) for (it = m_Entries->begin(); it != m_Entries->end(); ++it)
{ {
if (!m_AdvancedMode && cmCacheManager::CacheIterator mit =
this->m_CMakeInstance->GetCacheManager()->IsAdvanced((*it)->GetValue())) this->m_CMakeInstance->GetCacheManager()->GetCacheIterator((*it)->GetValue());
if (mit.IsAtEnd() || !m_AdvancedMode && mit.GetPropertyAsBool("ADVANCED"))
{ {
continue; continue;
} }
@ -302,9 +303,10 @@ void cmCursesMainForm::Render(int left, int top, int width, int height)
std::vector<cmCursesCacheEntryComposite*>::iterator it; std::vector<cmCursesCacheEntryComposite*>::iterator it;
for (it = m_Entries->begin(); it != m_Entries->end(); ++it) for (it = m_Entries->begin(); it != m_Entries->end(); ++it)
{ {
if (!m_AdvancedMode && this->m_CMakeInstance->GetCacheManager()->IsAdvanced( cmCacheManager::CacheIterator mit =
(*it)->GetValue())) this->m_CMakeInstance->GetCacheManager()->GetCacheIterator((*it)->GetValue());
{ if (mit.IsAtEnd() || !m_AdvancedMode && mit.GetPropertyAsBool("ADVANCED"))
{
continue; continue;
} }
m_NumberOfVisibleEntries++; m_NumberOfVisibleEntries++;
@ -318,8 +320,9 @@ void cmCursesMainForm::Render(int left, int top, int width, int height)
std::vector<cmCursesCacheEntryComposite*>::iterator it; std::vector<cmCursesCacheEntryComposite*>::iterator it;
for (it = m_Entries->begin(); it != m_Entries->end(); ++it) for (it = m_Entries->begin(); it != m_Entries->end(); ++it)
{ {
if (!m_AdvancedMode && this->m_CMakeInstance->GetCacheManager()->IsAdvanced( cmCacheManager::CacheIterator mit =
(*it)->GetValue())) this->m_CMakeInstance->GetCacheManager()->GetCacheIterator((*it)->GetValue());
if (mit.IsAtEnd() || !m_AdvancedMode && mit.GetPropertyAsBool("ADVANCED"))
{ {
continue; continue;
} }
@ -453,14 +456,20 @@ void cmCursesMainForm::UpdateStatusBar()
// Get the help string of the current entry // Get the help string of the current entry
// and add it to the help string // and add it to the help string
char help[128]; char help[128];
const char* helpString; cmCacheManager::CacheIterator it =
cmCacheManager::CacheEntry *entry = this->m_CMakeInstance->GetCacheManager()->GetCacheIterator(curField);
this->m_CMakeInstance->GetCacheManager()->GetCacheEntry(curField); if (!it.IsAtEnd())
if (entry)
{ {
helpString = entry->m_HelpString.c_str(); const char* hs = it.GetProperty("HELPSTRING");
strncpy(help, helpString, 127); if ( hs )
help[127] = '\0'; {
strncpy(help, hs, 127);
help[127] = '\0';
}
else
{
help[0] = 0;
}
} }
else else
{ {
@ -686,23 +695,22 @@ void cmCursesMainForm::FillCacheManagerFromUI()
int size = m_Entries->size(); int size = m_Entries->size();
for(int i=0; i < size; i++) for(int i=0; i < size; i++)
{ {
cmCacheManager::CacheEntry *entry = cmCacheManager::CacheIterator it =
this->m_CMakeInstance->GetCacheManager()->GetCacheEntry( this->m_CMakeInstance->GetCacheManager()->GetCacheIterator(
(*m_Entries)[i]->m_Key.c_str()); (*m_Entries)[i]->m_Key.c_str());
if (entry) if (!it.IsAtEnd())
{ {
tmpString = (*m_Entries)[i]->m_Entry->GetValue(); tmpString = (*m_Entries)[i]->m_Entry->GetValue();
// Remove trailing spaces, convert path to unix slashes // Remove trailing spaces, convert path to unix slashes
std::string tmpSubString = std::string tmpSubString =
tmpString.substr(0,tmpString.find_last_not_of(" ")+1); tmpString.substr(0,tmpString.find_last_not_of(" ")+1);
if ( entry->m_Type == cmCacheManager::PATH || if ( it.GetType() == cmCacheManager::PATH ||
entry->m_Type == cmCacheManager::FILEPATH ) it.GetType() == cmCacheManager::FILEPATH )
{ {
cmSystemTools::ConvertToUnixSlashes(tmpSubString); cmSystemTools::ConvertToUnixSlashes(tmpSubString);
} }
entry->m_Value = tmpSubString; it.SetValue(tmpSubString.c_str());
} }
} }
} }
@ -842,11 +850,11 @@ void cmCursesMainForm::HandleInput()
m_Fields[index-2])); m_Fields[index-2]));
const char* curField = lbl->GetValue(); const char* curField = lbl->GetValue();
const char* helpString=0; const char* helpString=0;
cmCacheManager::CacheEntry *entry = cmCacheManager::CacheIterator it =
this->m_CMakeInstance->GetCacheManager()->GetCacheEntry(curField); this->m_CMakeInstance->GetCacheManager()->GetCacheIterator(curField);
if (entry) if (!it.IsAtEnd())
{ {
helpString = entry->m_HelpString.c_str(); helpString = it.GetProperty("HELPSTRING");
} }
if (helpString) if (helpString)
{ {

View File

@ -33,6 +33,7 @@ const char* cmCacheManagerTypes[] =
"STRING", "STRING",
"INTERNAL", "INTERNAL",
"STATIC", "STATIC",
"UNINITIALIZED",
0 0
}; };
@ -153,7 +154,7 @@ bool cmCacheManager::LoadCache(const char* path,
} }
while(realbuffer[0] == '/' && realbuffer[1] == '/') while(realbuffer[0] == '/' && realbuffer[1] == '/')
{ {
e.m_HelpString += &realbuffer[2]; e.m_Properties["HELPSTRING"] += &realbuffer[2];
fin.getline(realbuffer, bsize); fin.getline(realbuffer, bsize);
if(!fin) if(!fin)
{ {
@ -177,14 +178,34 @@ bool cmCacheManager::LoadCache(const char* path,
if (!internal) if (!internal)
{ {
e.m_Type = INTERNAL; e.m_Type = INTERNAL;
e.m_HelpString = "DO NOT EDIT, "; e.m_Properties["HELPSTRING"] = "DO NOT EDIT, ";
e.m_HelpString += entryKey; e.m_Properties["HELPSTRING"] += entryKey;
e.m_HelpString += " loaded from external file. " e.m_Properties["HELPSTRING"] += " loaded from external file. "
"To change this value edit this file: "; "To change this value edit this file: ";
e.m_HelpString += path; e.m_Properties["HELPSTRING"] += path;
e.m_HelpString += "/CMakeCache.txt" ; e.m_Properties["HELPSTRING"] += "/CMakeCache.txt" ;
} }
m_Cache[entryKey] = e; if ( e.m_Type == cmCacheManager::INTERNAL &&
(entryKey.size() > strlen("-ADVANCED")) &&
strcmp(entryKey.c_str() + (entryKey.size() - strlen("-ADVANCED")),
"-ADVANCED") == 0 )
{
std::string akey = entryKey.substr(0, (entryKey.size() - strlen("-ADVANCED")));
cmCacheManager::CacheIterator it = this->GetCacheIterator(akey.c_str());
if ( it.IsAtEnd() )
{
e.m_Type = cmCacheManager::UNINITIALIZED;
m_Cache[akey] = e;
}
else
{
it.SetProperty("ADVANCED", true);
}
}
else
{
m_Cache[entryKey] = e;
}
} }
} }
} }
@ -295,10 +316,24 @@ bool cmCacheManager::SaveCache(const char* path)
{ {
const CacheEntry& ce = (*i).second; const CacheEntry& ce = (*i).second;
CacheEntryType t = ce.m_Type; CacheEntryType t = ce.m_Type;
if(t != INTERNAL) if(t == cmCacheManager::UNINITIALIZED)
{
cmSystemTools::Error("Cache entry \"", (*i).first.c_str(),
"\" is uninitialized");
}
else if(t != INTERNAL)
{ {
// Format is key:type=value // Format is key:type=value
cmCacheManager::OutputHelpString(fout, ce.m_HelpString); std::map<cmStdString,cmStdString>::const_iterator it =
ce.m_Properties.find("HELPSTRING");
if ( it == ce.m_Properties.end() )
{
cmCacheManager::OutputHelpString(fout, "Missing description");
}
else
{
cmCacheManager::OutputHelpString(fout, it->second);
}
std::string key; std::string key;
// support : in key name by double quoting // support : in key name by double quoting
if((*i).first.find(':') != std::string::npos || if((*i).first.find(':') != std::string::npos ||
@ -335,40 +370,70 @@ bool cmCacheManager::SaveCache(const char* path)
fout << "########################\n"; fout << "########################\n";
fout << "\n"; fout << "\n";
for( std::map<cmStdString, CacheEntry>::const_iterator i = m_Cache.begin(); for( cmCacheManager::CacheIterator i = this->NewIterator();
i != m_Cache.end(); ++i) !i.IsAtEnd(); i.Next())
{ {
const CacheEntry& ce = (*i).second; CacheEntryType t = i.GetType();
CacheEntryType t = ce.m_Type; bool advanced = i.GetPropertyAsBool("ADVANCED");
if(t == INTERNAL) if ( advanced )
{ {
// Format is key:type=value // Format is key:type=value
cmCacheManager::OutputHelpString(fout, ce.m_HelpString);
std::string key; std::string key;
std::string rkey = i.GetName();
std::string helpstring;
// If this is advanced variable, we have to do some magic for
// backward compatibility
helpstring = "Advanced flag for variable: ";
helpstring += i.GetName();
rkey += "-ADVANCED";
cmCacheManager::OutputHelpString(fout, helpstring.c_str());
// support : in key name by double quoting // support : in key name by double quoting
if((*i).first.find(':') != std::string::npos || if(rkey.find(':') != std::string::npos ||
(*i).first.find("//") == 0) rkey.find("//") == 0)
{ {
key = "\""; key = "\"";
key += i->first; key += rkey;
key += "\""; key += "\"";
} }
else else
{ {
key = i->first; key = rkey;
}
fout << key.c_str() << ":INTERNAL=1\n";
}
if(t == cmCacheManager::INTERNAL)
{
// Format is key:type=value
std::string key;
std::string rkey = i.GetName();
std::string helpstring;
helpstring = i.GetProperty("HELPSTRING");
cmCacheManager::OutputHelpString(fout, helpstring.c_str());
// support : in key name by double quoting
if(rkey.find(':') != std::string::npos ||
rkey.find("//") == 0)
{
key = "\"";
key += rkey;
key += "\"";
}
else
{
key = rkey;
} }
fout << key.c_str() << ":" fout << key.c_str() << ":"
<< cmCacheManagerTypes[t] << "="; << cmCacheManagerTypes[t] << "=";
// if value has trailing space or tab, enclose it in single quotes // if value has trailing space or tab, enclose it in single quotes
if (ce.m_Value.size() && std::string value = i.GetValue();
(ce.m_Value[ce.m_Value.size() - 1] == ' ' || if (value.size() &&
ce.m_Value[ce.m_Value.size() - 1] == '\t')) (value[value.size() - 1] == ' ' ||
value[value.size() - 1] == '\t'))
{ {
fout << '\'' << ce.m_Value << '\''; fout << '\'' << value << '\'';
} }
else else
{ {
fout << ce.m_Value; fout << value;
} }
fout << "\n"; fout << "\n";
} }
@ -439,6 +504,11 @@ cmCacheManager::CacheEntry *cmCacheManager::GetCacheEntry(const char* key)
return 0; return 0;
} }
cmCacheManager::CacheIterator cmCacheManager::GetCacheIterator(const char *key)
{
return CacheIterator(*this, key);
}
const char* cmCacheManager::GetCacheValue(const char* key) const const char* cmCacheManager::GetCacheValue(const char* key) const
{ {
CacheEntryMap::const_iterator i = m_Cache.find(key); CacheEntryMap::const_iterator i = m_Cache.find(key);
@ -473,15 +543,29 @@ void cmCacheManager::AddCacheEntry(const char* key,
const char* helpString, const char* helpString,
CacheEntryType type) CacheEntryType type)
{ {
CacheEntry e; CacheEntry& e = m_Cache[key];
e.m_Value = value; if ( value )
{
e.m_Value = value;
}
else
{
e.m_Value = "(none)";
}
e.m_Type = type; e.m_Type = type;
// make sure we only use unix style paths // make sure we only use unix style paths
if(type == FILEPATH || type == PATH) if(type == FILEPATH || type == PATH)
{ {
cmSystemTools::ConvertToUnixSlashes(e.m_Value); cmSystemTools::ConvertToUnixSlashes(e.m_Value);
} }
e.m_HelpString = helpString; if ( helpString )
{
e.m_Properties["HELPSTRING"] = helpString;
}
else
{
e.m_Properties["HELPSTRING"] = "(This variable does not exists and should not be used)";
}
m_Cache[key] = e; m_Cache[key] = e;
} }
@ -498,29 +582,91 @@ void cmCacheManager::AddCacheEntry(const char* key, bool v,
} }
} }
bool cmCacheManager::IsAdvanced(const char* key)
{
std::string advancedVar = key;
advancedVar += "-ADVANCED";
const char* value = this->GetCacheValue(advancedVar.c_str());
if(value)
{
return cmSystemTools::IsOn(value);
}
return false;
}
bool cmCacheManager::CacheIterator::IsAtEnd() bool cmCacheManager::CacheIterator::IsAtEnd()
{ {
return position == m_Container.m_Cache.end(); return m_Position == m_Container.m_Cache.end();
} }
void cmCacheManager::CacheIterator::Begin() void cmCacheManager::CacheIterator::Begin()
{ {
position = m_Container.m_Cache.begin(); m_Position = m_Container.m_Cache.begin();
}
bool cmCacheManager::CacheIterator::Find(const char* key)
{
m_Position = m_Container.m_Cache.find(key);
return this->IsAtEnd();
} }
void cmCacheManager::CacheIterator::Next() void cmCacheManager::CacheIterator::Next()
{ {
++position; ++m_Position;
} }
void cmCacheManager::CacheIterator::SetValue(const char* value)
{
CacheEntry* entry = &this->GetEntry();
entry->m_Value = value;
}
const char* cmCacheManager::CacheIterator::GetProperty(const char* property) const
{
if ( !strcasecmp(property, "TYPE") || !strcasecmp(property, "VALUE") )
{
cmSystemTools::Error("Property \"", property,
"\" cannot be accessed through the GetProperty()");
return 0;
}
const CacheEntry* ent = &this->GetEntry();
std::map<cmStdString,cmStdString>::const_iterator it =
ent->m_Properties.find(property);
if ( it == ent->m_Properties.end() )
{
return 0;
}
return it->second.c_str();
}
void cmCacheManager::CacheIterator::SetProperty(const char* p, const char* v)
{
if ( !strcasecmp(p, "TYPE") || !strcasecmp(p, "VALUE") )
{
cmSystemTools::Error("Property \"", p,
"\" cannot be accessed through the SetProperty()");
return;
}
CacheEntry* ent = &this->GetEntry();
ent->m_Properties[p] = v;
}
bool cmCacheManager::CacheIterator::GetPropertyAsBool(const char* property) const
{
if ( !strcasecmp(property, "TYPE") || !strcasecmp(property, "VALUE") )
{
cmSystemTools::Error("Property \"", property,
"\" cannot be accessed through the GetPropertyAsBool()");
return false;
}
const CacheEntry* ent = &this->GetEntry();
std::map<cmStdString,cmStdString>::const_iterator it =
ent->m_Properties.find(property);
if ( it == ent->m_Properties.end() )
{
return false;
}
return cmSystemTools::IsOn(it->second.c_str());
}
void cmCacheManager::CacheIterator::SetProperty(const char* p, bool v)
{
if ( !strcasecmp(p, "TYPE") || !strcasecmp(p, "VALUE") )
{
cmSystemTools::Error("Property \"", p,
"\" cannot be accessed through the SetProperty()");
return;
}
CacheEntry* ent = &this->GetEntry();
ent->m_Properties[p] = v ? "ON" : "OFF";
}

View File

@ -29,28 +29,44 @@ class cmMakefile;
class cmCacheManager class cmCacheManager
{ {
public: public:
enum CacheEntryType{ BOOL=0, PATH, FILEPATH, STRING, INTERNAL,STATIC }; enum CacheEntryType{ BOOL=0, PATH, FILEPATH, STRING, INTERNAL,STATIC,UNINITIALIZED };
private:
struct CacheEntry struct CacheEntry
{ {
std::string m_Value; std::string m_Value;
std::string m_HelpString;
CacheEntryType m_Type; CacheEntryType m_Type;
std::map<cmStdString,cmStdString> m_Properties;
}; };
public:
class CacheIterator class CacheIterator
{ {
public: public:
void Begin(); void Begin();
bool Find(const char*);
bool IsAtEnd(); bool IsAtEnd();
void Next(); void Next();
const char *GetName() { const char *GetName() const {
return position->first.c_str(); } return m_Position->first.c_str(); }
CacheEntry const &GetEntry() { const char* GetProperty(const char*) const ;
return position->second; } bool GetPropertyAsBool(const char*) const ;
cmCacheManager const &m_Container; void SetProperty(const char* property, const char* value);
std::map<cmStdString, CacheEntry>::const_iterator position; void SetProperty(const char* property, bool value);
CacheIterator(cmCacheManager const &foo) : m_Container(foo) { const char* GetValue() const { return this->GetEntry().m_Value.c_str(); }
void SetValue(const char*);
CacheEntryType GetType() const { return this->GetEntry().m_Type; }
cmCacheManager &m_Container;
std::map<cmStdString, CacheEntry>::iterator m_Position;
CacheIterator(cmCacheManager &foo) : m_Container(foo) {
this->Begin(); this->Begin();
} }
CacheIterator(cmCacheManager &foo, const char* key) : m_Container(foo) {
this->Find(key);
}
private:
CacheEntry const& GetEntry() const { return m_Position->second; }
CacheEntry& GetEntry() { return m_Position->second; }
}; };
friend class cmCacheManager::CacheIterator; friend class cmCacheManager::CacheIterator;
@ -60,7 +76,6 @@ public:
return CacheIterator(*this); return CacheIterator(*this);
} }
typedef std::map<cmStdString, CacheEntry> CacheEntryMap;
/** /**
* Types for the cache entries. These are useful as * Types for the cache entries. These are useful as
* hints for a cache editor program. Path should bring * hints for a cache editor program. Path should bring
@ -87,10 +102,8 @@ public:
///! Print the cache to a stream ///! Print the cache to a stream
void PrintCache(std::ostream&) const; void PrintCache(std::ostream&) const;
///! Get a cache entry object for a key ///! Get the iterator for an entry with a given key.
CacheEntry *GetCacheEntry(const char *key); cmCacheManager::CacheIterator GetCacheIterator(const char *key);
bool IsAdvanced(const char* key);
///! Remove an entry from the cache ///! Remove an entry from the cache
void RemoveCacheEntry(const char* key); void RemoveCacheEntry(const char* key);
@ -116,7 +129,11 @@ protected:
///! Add a BOOL entry into the cache ///! Add a BOOL entry into the cache
void AddCacheEntry(const char* key, bool, const char* helpString); void AddCacheEntry(const char* key, bool, const char* helpString);
///! Get a cache entry object for a key
CacheEntry *GetCacheEntry(const char *key);
private: private:
typedef std::map<cmStdString, CacheEntry> CacheEntryMap;
static void OutputHelpString(std::ofstream& fout, static void OutputHelpString(std::ofstream& fout,
const std::string& helpString); const std::string& helpString);
CacheEntryMap m_Cache; CacheEntryMap m_Cache;

View File

@ -58,11 +58,12 @@ bool cmFindPathCommand::InitialPass(std::vector<std::string> const& argsIn)
} }
if(cacheValue) if(cacheValue)
{ {
cmCacheManager::CacheEntry* e = cmCacheManager::CacheIterator it =
m_Makefile->GetCacheManager()->GetCacheEntry(args[0].c_str()); m_Makefile->GetCacheManager()->GetCacheIterator(args[0].c_str());
if(e) if(!it.IsAtEnd())
{ {
helpString = e->m_HelpString; const char* hs = it.GetProperty("HELPSTRING");
helpString = hs?hs:"(none)";
} }
} }
std::vector<std::string> path; std::vector<std::string> path;

View File

@ -64,11 +64,12 @@ bool cmFindProgramCommand::InitialPass(std::vector<std::string> const& argsIn)
} }
if(cacheValue) if(cacheValue)
{ {
cmCacheManager::CacheEntry* e = cmCacheManager::CacheIterator it =
m_Makefile->GetCacheManager()->GetCacheEntry(args[0].c_str()); m_Makefile->GetCacheManager()->GetCacheIterator(args[0].c_str());
if(e) if(!it.IsAtEnd())
{ {
doc = e->m_HelpString; const char* hs = it.GetProperty("HELPSTRING");
doc = hs?hs:"(none)";
} }
} }
std::vector<std::string> path; std::vector<std::string> path;

View File

@ -547,6 +547,10 @@ void cmMakefile::AddIncludeDirectory(const char* inc, bool before)
void cmMakefile::AddDefinition(const char* name, const char* value) void cmMakefile::AddDefinition(const char* name, const char* value)
{ {
if (!value )
{
return;
}
m_Definitions.erase( DefinitionMap::key_type(name)); m_Definitions.erase( DefinitionMap::key_type(name));
m_Definitions.insert(DefinitionMap::value_type(name, value)); m_Definitions.insert(DefinitionMap::value_type(name, value));
} }

View File

@ -42,17 +42,20 @@ bool cmMarkAsAdvancedCommand::InitialPass(std::vector<std::string> const& argsIn
for(; i < args.size(); ++i) for(; i < args.size(); ++i)
{ {
std::string variable = args[i]; std::string variable = args[i];
variable += "-ADVANCED"; cmCacheManager* manager = m_Makefile->GetCacheManager();
std::string doc = "Advanced flag for variable: "; cmCacheManager::CacheIterator it = manager->GetCacheIterator(variable.c_str());
doc += args[i]; if ( it.IsAtEnd() )
// if not CLEAR or FORCE or it is not yet defined,
// then define variable-ADVANCED
if(overwrite || !m_Makefile->GetDefinition(variable.c_str()))
{ {
m_Makefile->AddCacheDefinition(variable.c_str(), value, m_Makefile->AddCacheDefinition(variable.c_str(), 0, 0,
doc.c_str(), cmCacheManager::UNINITIALIZED);
cmCacheManager::INTERNAL);
} }
it.Find(variable.c_str());
if ( it.IsAtEnd() )
{
cmSystemTools::Error("This should never happen...");
return false;
}
it.SetProperty("ADVANCED", value);
} }
return true; return true;
} }

View File

@ -47,7 +47,9 @@ void cmVariableRequiresCommand::FinalPass()
requirementsMet = false; requirementsMet = false;
notSet += m_Arguments[i]; notSet += m_Arguments[i];
notSet += "\n"; notSet += "\n";
if(m_Makefile->GetCacheManager()->IsAdvanced(m_Arguments[i].c_str())) cmCacheManager::CacheIterator it =
m_Makefile->GetCacheManager()->GetCacheIterator(m_Arguments[i].c_str());
if(!it.IsAtEnd() && it.GetPropertyAsBool("ADVANCED"))
{ {
hasAdvanced = true; hasAdvanced = true;
} }

View File

@ -24,39 +24,33 @@ cmakewizard::cmakewizard()
} }
void cmakewizard::AskUser(const char* key, cmCacheManager::CacheEntry & entry, void cmakewizard::AskUser(const char* key, cmCacheManager::CacheIterator& iter,
cmCacheManager *cacheManager) cmCacheManager *cacheManager)
{ {
std::cout << "Variable Name: " << key << "\n"; std::cout << "Variable Name: " << key << "\n";
std::cout << "Description: " << entry.m_HelpString << "\n"; const char* helpstring = iter.GetProperty("HELPSTRING");
std::cout << "Current Value: " << entry.m_Value.c_str() << "\n"; std::cout << "Description: " << (helpstring?helpstring:"(none)") << "\n";
std::cout << "Current Value: " << iter.GetValue() << "\n";
std::cout << "New Value (Enter to keep current value): "; std::cout << "New Value (Enter to keep current value): ";
char buffer[4096]; char buffer[4096];
buffer[0] = 0; buffer[0] = 0;
std::cin.getline(buffer, sizeof(buffer)); std::cin.getline(buffer, sizeof(buffer));
if(buffer[0]) if(buffer[0])
{ {
cmCacheManager::CacheEntry *entry = cacheManager->GetCacheEntry(key); std::string value = buffer;
if(entry) if(iter.GetType() == cmCacheManager::PATH ||
iter.GetType() == cmCacheManager::FILEPATH)
{ {
entry->m_Value = buffer; cmSystemTools::ConvertToUnixSlashes(value);
if(entry->m_Type == cmCacheManager::PATH || }
entry->m_Type == cmCacheManager::FILEPATH) if(iter.GetType() == cmCacheManager::BOOL)
{
if(!cmSystemTools::IsOn(value.c_str()))
{ {
cmSystemTools::ConvertToUnixSlashes(entry->m_Value); value = "OFF";
}
if(entry->m_Type == cmCacheManager::BOOL)
{
if(!cmSystemTools::IsOn(buffer))
{
entry->m_Value = "OFF";
}
} }
} }
else iter.SetValue(value.c_str());
{
std::cerr << "strange error, should be in cache but is not... " << key << "\n";
}
} }
std::cout << "\n"; std::cout << "\n";
} }
@ -90,7 +84,8 @@ void cmakewizard::RunWizard(std::vector<std::string> const& args)
m_ShowAdvanced = this->AskAdvanced(); m_ShowAdvanced = this->AskAdvanced();
cmSystemTools::DisableRunCommandOutput(); cmSystemTools::DisableRunCommandOutput();
cmake make; cmake make;
cmCacheManager::CacheEntryMap askedCache; make.SetArgs(args);
std::map<std::string,std::string> askedCache;
bool asked = false; bool asked = false;
// continue asking questions until no new questions are asked // continue asking questions until no new questions are asked
do do
@ -98,6 +93,7 @@ void cmakewizard::RunWizard(std::vector<std::string> const& args)
asked = false; asked = false;
// run cmake // run cmake
this->ShowMessage("Please wait while cmake processes CMakeLists.txt files....\n"); this->ShowMessage("Please wait while cmake processes CMakeLists.txt files....\n");
make.Configure(args[0].c_str(),&args); make.Configure(args[0].c_str(),&args);
this->ShowMessage("\n"); this->ShowMessage("\n");
// load the cache from disk // load the cache from disk
@ -109,33 +105,33 @@ void cmakewizard::RunWizard(std::vector<std::string> const& args)
for(;!i.IsAtEnd(); i.Next()) for(;!i.IsAtEnd(); i.Next())
{ {
std::string key = i.GetName(); std::string key = i.GetName();
cmCacheManager::CacheEntry ce = i.GetEntry(); if( i.GetType() == cmCacheManager::INTERNAL ||
if(ce.m_Type == cmCacheManager::INTERNAL i.GetType() == cmCacheManager::STATIC ||
|| ce.m_Type == cmCacheManager::STATIC) i.GetType() == cmCacheManager::UNINITIALIZED )
{ {
continue; continue;
} }
if(askedCache.count(key)) if(askedCache.count(key))
{ {
cmCacheManager::CacheEntry& e = askedCache.find(key)->second; std::string& e = askedCache.find(key)->second;
if(e.m_Value != ce.m_Value) if(e != i.GetValue())
{ {
if(m_ShowAdvanced || !cachem->IsAdvanced(key.c_str())) if(m_ShowAdvanced || !i.GetPropertyAsBool("ADVANCED"))
{ {
this->AskUser(key.c_str(), ce, cachem); this->AskUser(key.c_str(), i, cachem);
asked = true; asked = true;
} }
} }
} }
else else
{ {
if(m_ShowAdvanced || !cachem->IsAdvanced(key.c_str())) if(m_ShowAdvanced || !i.GetPropertyAsBool("ADVANCED"))
{ {
this->AskUser(key.c_str(), ce, cachem); this->AskUser(key.c_str(), i, cachem);
asked = true; asked = true;
} }
} }
askedCache[key] = i.GetEntry(); askedCache[key] = i.GetValue();
} }
cachem->SaveCache(cmSystemTools::GetCurrentWorkingDirectory().c_str()); cachem->SaveCache(cmSystemTools::GetCurrentWorkingDirectory().c_str());
} }

View File

@ -31,7 +31,7 @@ public:
/** /**
* Prompt the User for a new value for key, the answer is put in entry. * Prompt the User for a new value for key, the answer is put in entry.
*/ */
virtual void AskUser(const char* key, cmCacheManager::CacheEntry & entry, virtual void AskUser(const char* key, cmCacheManager::CacheIterator& iter,
cmCacheManager *cm); cmCacheManager *cm);
///! Show a message to wait for cmake to run. ///! Show a message to wait for cmake to run.
virtual void ShowMessage(const char*); virtual void ShowMessage(const char*);