Commit f081c5bd authored by Stephen Kelly's avatar Stephen Kelly Committed by Brad King
Browse files

cmState: Move CacheEntryType enum from cmCacheManager.

parent f71fdf0e
......@@ -16,7 +16,7 @@ cmCursesBoolWidget::cmCursesBoolWidget(int width, int height,
int left, int top) :
cmCursesWidget(width, height, left, top)
{
this->Type = cmCacheManager::BOOL;
this->Type = cmState::BOOL;
set_field_fore(this->Field, A_NORMAL);
set_field_back(this->Field, A_STANDOUT);
field_opts_off(this->Field, O_STATIC);
......
......@@ -55,7 +55,7 @@ cmCursesCacheEntryComposite::cmCursesCacheEntryComposite(
assert(value);
switch (cm->GetState()->GetCacheEntryType(key))
{
case cmCacheManager::BOOL:
case cmState::BOOL:
this->Entry = new cmCursesBoolWidget(this->EntryWidth, 1, 1, 1);
if (cmSystemTools::IsOn(value))
{
......@@ -66,15 +66,15 @@ cmCursesCacheEntryComposite::cmCursesCacheEntryComposite(
static_cast<cmCursesBoolWidget*>(this->Entry)->SetValueAsBool(false);
}
break;
case cmCacheManager::PATH:
case cmState::PATH:
this->Entry = new cmCursesPathWidget(this->EntryWidth, 1, 1, 1);
static_cast<cmCursesPathWidget*>(this->Entry)->SetString(value);
break;
case cmCacheManager::FILEPATH:
case cmState::FILEPATH:
this->Entry = new cmCursesFilePathWidget(this->EntryWidth, 1, 1, 1);
static_cast<cmCursesFilePathWidget*>(this->Entry)->SetString(value);
break;
case cmCacheManager::STRING:
case cmState::STRING:
{
const char* stringsProp = cm->GetState()
->GetCacheEntryProperty(key, "STRINGS");
......@@ -99,7 +99,7 @@ cmCursesCacheEntryComposite::cmCursesCacheEntryComposite(
}
break;
}
case cmCacheManager::UNINITIALIZED:
case cmState::UNINITIALIZED:
cmSystemTools::Error("Found an undefined variable: ",
key.c_str());
break;
......
......@@ -12,7 +12,6 @@
#ifndef cmCursesCacheEntryComposite_h
#define cmCursesCacheEntryComposite_h
#include "../cmCacheManager.h"
#include "cmCursesLabelWidget.h"
class cmCursesCacheEntryComposite
......
......@@ -15,7 +15,7 @@ cmCursesDummyWidget::cmCursesDummyWidget(int width, int height,
int left, int top) :
cmCursesWidget(width, height, left, top)
{
this->Type = cmCacheManager::INTERNAL;
this->Type = cmState::INTERNAL;
}
......
......@@ -15,6 +15,6 @@ cmCursesFilePathWidget::cmCursesFilePathWidget(int width, int height,
int left, int top) :
cmCursesPathWidget(width, height, left, top)
{
this->Type = cmCacheManager::FILEPATH;
this->Type = cmState::FILEPATH;
}
......@@ -9,7 +9,6 @@
implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the License for more information.
============================================================================*/
#include "../cmCacheManager.h"
#include "../cmSystemTools.h"
#include "../cmVersion.h"
#include "../cmake.h"
......@@ -118,11 +117,11 @@ void cmCursesMainForm::InitializeUI()
for(std::vector<std::string>::const_iterator it = cacheKeys.begin();
it != cacheKeys.end(); ++it)
{
cmCacheManager::CacheEntryType t = this->CMakeInstance->GetState()
cmState::CacheEntryType t = this->CMakeInstance->GetState()
->GetCacheEntryType(*it);
if (t != cmCacheManager::INTERNAL &&
t != cmCacheManager::STATIC &&
t != cmCacheManager::UNINITIALIZED)
if (t != cmState::INTERNAL &&
t != cmState::STATIC &&
t != cmState::UNINITIALIZED)
{
++count;
}
......@@ -148,11 +147,11 @@ void cmCursesMainForm::InitializeUI()
it != cacheKeys.end(); ++it)
{
std::string key = *it;
cmCacheManager::CacheEntryType t = this->CMakeInstance->GetState()
cmState::CacheEntryType t = this->CMakeInstance->GetState()
->GetCacheEntryType(*it);
if (t == cmCacheManager::INTERNAL ||
t == cmCacheManager::STATIC ||
t == cmCacheManager::UNINITIALIZED )
if (t == cmState::INTERNAL ||
t == cmState::STATIC ||
t == cmState::UNINITIALIZED )
{
continue;
}
......@@ -172,11 +171,11 @@ void cmCursesMainForm::InitializeUI()
it != cacheKeys.end(); ++it)
{
std::string key = *it;
cmCacheManager::CacheEntryType t = this->CMakeInstance->GetState()
cmState::CacheEntryType t = this->CMakeInstance->GetState()
->GetCacheEntryType(*it);
if (t == cmCacheManager::INTERNAL ||
t == cmCacheManager::STATIC ||
t == cmCacheManager::UNINITIALIZED )
if (t == cmState::INTERNAL ||
t == cmState::STATIC ||
t == cmState::UNINITIALIZED )
{
continue;
}
......@@ -294,9 +293,9 @@ void cmCursesMainForm::Render(int left, int top, int width, int height)
cmCursesWidget* cw = reinterpret_cast<cmCursesWidget*>
(field_userptr(currentField));
// If in edit mode, get out of it
if ( cw->GetType() == cmCacheManager::STRING ||
cw->GetType() == cmCacheManager::PATH ||
cw->GetType() == cmCacheManager::FILEPATH )
if ( cw->GetType() == cmState::STRING ||
cw->GetType() == cmState::PATH ||
cw->GetType() == cmState::FILEPATH )
{
cmCursesStringWidget* sw = static_cast<cmCursesStringWidget*>(cw);
sw->SetInEdit(false);
......@@ -823,7 +822,7 @@ void cmCursesMainForm::FillCacheManagerFromUI()
std::string newValue = (*this->Entries)[i]->Entry->GetValue();
std::string fixedOldValue;
std::string fixedNewValue;
cmCacheManager::CacheEntryType t =
cmState::CacheEntryType t =
this->CMakeInstance->GetState()
->GetCacheEntryType(cacheKey);
this->FixValue(t, oldValue, fixedOldValue);
......@@ -841,15 +840,15 @@ void cmCursesMainForm::FillCacheManagerFromUI()
}
}
void cmCursesMainForm::FixValue(cmCacheManager::CacheEntryType type,
void cmCursesMainForm::FixValue(cmState::CacheEntryType type,
const std::string& in, std::string& out) const
{
out = in.substr(0,in.find_last_not_of(" ")+1);
if(type == cmCacheManager::PATH || type == cmCacheManager::FILEPATH)
if(type == cmState::PATH || type == cmState::FILEPATH)
{
cmSystemTools::ConvertToUnixSlashes(out);
}
if(type == cmCacheManager::BOOL)
if(type == cmState::BOOL)
{
if(cmSystemTools::IsOff(out.c_str()))
{
......
......@@ -113,7 +113,7 @@ protected:
// cache.
void FillCacheManagerFromUI();
// Fix formatting of values to a consistent form.
void FixValue(cmCacheManager::CacheEntryType type,
void FixValue(cmState::CacheEntryType type,
const std::string& in, std::string& out) const;
// Re-post the existing fields. Used to toggle between
// normal and advanced modes. Render() should be called
......
......@@ -21,7 +21,7 @@ cmCursesOptionsWidget::cmCursesOptionsWidget(int width, int height,
int left, int top) :
cmCursesWidget(width, height, left, top)
{
this->Type = cmCacheManager::BOOL; // this is a bit of a hack
this->Type = cmState::BOOL; // this is a bit of a hack
// there is no option type, and string type causes ccmake to cast
// the widget into a string widget at some point. BOOL is safe for
// now.
......
......@@ -18,7 +18,7 @@ cmCursesPathWidget::cmCursesPathWidget(int width, int height,
int left, int top) :
cmCursesStringWidget(width, height, left, top)
{
this->Type = cmCacheManager::PATH;
this->Type = cmState::PATH;
this->Cycle = false;
this->CurrentIndex = 0;
}
......@@ -59,7 +59,7 @@ void cmCursesPathWidget::OnTab(cmCursesMainForm* fm, WINDOW* w)
}
std::vector<std::string> dirs;
cmSystemTools::SimpleGlob(glob, dirs, (this->Type == cmCacheManager::PATH?-1:0));
cmSystemTools::SimpleGlob(glob, dirs, (this->Type == cmState::PATH?-1:0));
if ( this->CurrentIndex < dirs.size() )
{
cstr = dirs[this->CurrentIndex];
......
......@@ -22,7 +22,7 @@ cmCursesStringWidget::cmCursesStringWidget(int width, int height,
cmCursesWidget(width, height, left, top)
{
this->InEdit = false;
this->Type = cmCacheManager::STRING;
this->Type = cmState::STRING;
set_field_fore(this->Field, A_NORMAL);
set_field_back(this->Field, A_STANDOUT);
field_opts_off(this->Field, O_STATIC);
......
......@@ -12,7 +12,7 @@
#ifndef cmCursesWidget_h
#define cmCursesWidget_h
#include "../cmCacheManager.h"
#include "../cmState.h"
#include "cmCursesStandardIncludes.h"
class cmCursesMainForm;
......@@ -46,7 +46,7 @@ public:
/**
* Get the type of the widget (STRING, PATH etc...)
*/
cmCacheManager::CacheEntryType GetType()
cmState::CacheEntryType GetType()
{ return this->Type; }
/**
......@@ -77,7 +77,7 @@ protected:
cmCursesWidget(const cmCursesWidget& from);
void operator=(const cmCursesWidget&);
cmCacheManager::CacheEntryType Type;
cmState::CacheEntryType Type;
std::string Value;
FIELD* Field;
// The page in the main form this widget is in
......
......@@ -200,9 +200,9 @@ void QCMake::setProperties(const QCMakePropertyList& newProps)
for(std::vector<std::string>::const_iterator it = cacheKeys.begin();
it != cacheKeys.end(); ++it)
{
cmCacheManager::CacheEntryType t = state->GetCacheEntryType(*it);
if(t == cmCacheManager::INTERNAL ||
t == cmCacheManager::STATIC)
cmState::CacheEntryType t = state->GetCacheEntryType(*it);
if(t == cmState::INTERNAL ||
t == cmState::STATIC)
{
continue;
}
......@@ -249,28 +249,28 @@ void QCMake::setProperties(const QCMakePropertyList& newProps)
this->CMakeInstance->AddCacheEntry(s.Key.toLocal8Bit().data(),
s.Value.toBool() ? "ON" : "OFF",
s.Help.toLocal8Bit().data(),
cmCacheManager::BOOL);
cmState::BOOL);
}
else if(s.Type == QCMakeProperty::STRING)
{
this->CMakeInstance->AddCacheEntry(s.Key.toLocal8Bit().data(),
s.Value.toString().toLocal8Bit().data(),
s.Help.toLocal8Bit().data(),
cmCacheManager::STRING);
cmState::STRING);
}
else if(s.Type == QCMakeProperty::PATH)
{
this->CMakeInstance->AddCacheEntry(s.Key.toLocal8Bit().data(),
s.Value.toString().toLocal8Bit().data(),
s.Help.toLocal8Bit().data(),
cmCacheManager::PATH);
cmState::PATH);
}
else if(s.Type == QCMakeProperty::FILEPATH)
{
this->CMakeInstance->AddCacheEntry(s.Key.toLocal8Bit().data(),
s.Value.toString().toLocal8Bit().data(),
s.Help.toLocal8Bit().data(),
cmCacheManager::FILEPATH);
cmState::FILEPATH);
}
}
......@@ -286,10 +286,10 @@ QCMakePropertyList QCMake::properties() const
for (std::vector<std::string>::const_iterator i = cacheKeys.begin();
i != cacheKeys.end(); ++i)
{
cmCacheManager::CacheEntryType t = state->GetCacheEntryType(*i);
if(t == cmCacheManager::INTERNAL ||
t == cmCacheManager::STATIC ||
t == cmCacheManager::UNINITIALIZED)
cmState::CacheEntryType t = state->GetCacheEntryType(*i);
if(t == cmState::INTERNAL ||
t == cmState::STATIC ||
t == cmState::UNINITIALIZED)
{
continue;
}
......@@ -302,20 +302,20 @@ QCMakePropertyList QCMake::properties() const
state->GetCacheEntryProperty(*i, "HELPSTRING"));
prop.Value = QString::fromLocal8Bit(cachedValue);
prop.Advanced = state->GetCacheEntryPropertyAsBool(*i, "ADVANCED");
if(t == cmCacheManager::BOOL)
if(t == cmState::BOOL)
{
prop.Type = QCMakeProperty::BOOL;
prop.Value = cmSystemTools::IsOn(cachedValue);
}
else if(t == cmCacheManager::PATH)
else if(t == cmState::PATH)
{
prop.Type = QCMakeProperty::PATH;
}
else if(t == cmCacheManager::FILEPATH)
else if(t == cmState::FILEPATH)
{
prop.Type = QCMakeProperty::FILEPATH;
}
else if(t == cmCacheManager::STRING)
else if(t == cmState::STRING)
{
prop.Type = QCMakeProperty::STRING;
const char* stringsProperty =
......
......@@ -147,6 +147,6 @@ bool cmBuildCommand
makecommand.c_str(),
"Command used to build entire project "
"from the command line.",
cmCacheManager::STRING);
cmState::STRING);
return true;
}
......@@ -39,7 +39,7 @@ bool cmBuildNameCommand
this->Makefile->AddCacheDefinition(args[0],
cv.c_str(),
"Name of build.",
cmCacheManager::STRING);
cmState::STRING);
}
return true;
}
......@@ -74,7 +74,7 @@ bool cmBuildNameCommand
this->Makefile->AddCacheDefinition(args[0],
buildname.c_str(),
"Name of build.",
cmCacheManager::STRING);
cmState::STRING);
return true;
}
......@@ -87,27 +87,27 @@ void CCONV cmAddCacheDefinition(void *arg, const char* name,
{
case CM_CACHE_BOOL:
mf->AddCacheDefinition(name,value,doc,
cmCacheManager::BOOL);
cmState::BOOL);
break;
case CM_CACHE_PATH:
mf->AddCacheDefinition(name,value,doc,
cmCacheManager::PATH);
cmState::PATH);
break;
case CM_CACHE_FILEPATH:
mf->AddCacheDefinition(name,value,doc,
cmCacheManager::FILEPATH);
cmState::FILEPATH);
break;
case CM_CACHE_STRING:
mf->AddCacheDefinition(name,value,doc,
cmCacheManager::STRING);
cmState::STRING);
break;
case CM_CACHE_INTERNAL:
mf->AddCacheDefinition(name,value,doc,
cmCacheManager::INTERNAL);
cmState::INTERNAL);
break;
case CM_CACHE_STATIC:
mf->AddCacheDefinition(name,value,doc,
cmCacheManager::STATIC);
cmState::STATIC);
break;
}
}
......
......@@ -2279,7 +2279,7 @@ bool cmCTest::AddVariableDefinition(const std::string &arg)
{
std::string name;
std::string value;
cmCacheManager::CacheEntryType type = cmCacheManager::UNINITIALIZED;
cmState::CacheEntryType type = cmState::UNINITIALIZED;
if (cmake::ParseCacheEntry(arg, name, value, type))
{
......
......@@ -22,17 +22,6 @@
#include <cmsys/FStream.hxx>
#include <cmsys/RegularExpression.hxx>
const char* cmCacheManagerTypes[] =
{ "BOOL",
"PATH",
"FILEPATH",
"STRING",
"INTERNAL",
"STATIC",
"UNINITIALIZED",
0
};
cmCacheManager::cmCacheManager(cmake* cm)
{
this->CacheMajorVersion = 0;
......@@ -40,41 +29,6 @@ cmCacheManager::cmCacheManager(cmake* cm)
this->CMakeInstance = cm;
}
const char* cmCacheManager::TypeToString(cmCacheManager::CacheEntryType type)
{
if ( type > 6 )
{
return cmCacheManagerTypes[6];
}
return cmCacheManagerTypes[type];
}
cmCacheManager::CacheEntryType cmCacheManager::StringToType(const char* s)
{
int i = 0;
while(cmCacheManagerTypes[i])
{
if(strcmp(s, cmCacheManagerTypes[i]) == 0)
{
return static_cast<CacheEntryType>(i);
}
++i;
}
return STRING;
}
bool cmCacheManager::IsType(const char* s)
{
for(int i=0; cmCacheManagerTypes[i]; ++i)
{
if(strcmp(s, cmCacheManagerTypes[i]) == 0)
{
return true;
}
}
return false;
}
bool cmCacheManager::LoadCache(const std::string& path)
{
std::set<std::string> emptySet;
......@@ -122,7 +76,7 @@ static bool ParseEntryWithoutType(const std::string& entry,
bool cmCacheManager::ParseEntry(const std::string& entry,
std::string& var,
std::string& value,
CacheEntryType& type)
cmState::CacheEntryType& type)
{
// input line is: key:type=value
static cmsys::RegularExpression reg(
......@@ -134,14 +88,14 @@ bool cmCacheManager::ParseEntry(const std::string& entry,
if(regQuoted.find(entry))
{
var = regQuoted.match(1);
type = cmCacheManager::StringToType(regQuoted.match(2).c_str());
type = cmState::StringToCacheEntryType(regQuoted.match(2).c_str());
value = regQuoted.match(3);
flag = true;
}
else if (reg.find(entry))
{
var = reg.match(1);
type = cmCacheManager::StringToType(reg.match(2).c_str());
type = cmState::StringToCacheEntryType(reg.match(2).c_str());
value = reg.match(3);
flag = true;
}
......@@ -250,7 +204,7 @@ bool cmCacheManager::LoadCache(const std::string& path,
// If the entry is not internal to the cache being loaded
// or if it is in the list of internal entries to be
// imported, load it.
if ( internal || (e.Type != INTERNAL) ||
if ( internal || (e.Type != cmState::INTERNAL) ||
(includes.find(entryKey) != includes.end()) )
{
// If we are loading the cache from another project,
......@@ -258,7 +212,7 @@ bool cmCacheManager::LoadCache(const std::string& path,
// not visible in the gui
if (!internal)
{
e.Type = INTERNAL;
e.Type = cmState::INTERNAL;
helpString = "DO NOT EDIT, ";
helpString += entryKey;
helpString += " loaded from external file. "
......@@ -306,10 +260,10 @@ bool cmCacheManager::LoadCache(const std::string& path,
// Set as version 0.0
this->AddCacheEntry("CMAKE_CACHE_MINOR_VERSION", "0",
"Minor version of cmake used to create the "
"current loaded cache", cmCacheManager::INTERNAL);
"current loaded cache", cmState::INTERNAL);
this->AddCacheEntry("CMAKE_CACHE_MAJOR_VERSION", "0",
"Major version of cmake used to create the "
"current loaded cache", cmCacheManager::INTERNAL);
"current loaded cache", cmState::INTERNAL);
}
// check to make sure the cache directory has not
......@@ -351,7 +305,7 @@ bool cmCacheManager::ReadPropertyEntry(std::string const& entryKey,
CacheEntry& e)
{
// All property entries are internal.
if(e.Type != cmCacheManager::INTERNAL)
if(e.Type != cmState::INTERNAL)
{
return false;
}
......@@ -370,7 +324,7 @@ bool cmCacheManager::ReadPropertyEntry(std::string const& entryKey,
// Create an entry and store the property.
CacheEntry& ne = this->Cache[key];
ne.Properties.SetCMakeInstance(this->CMakeInstance);
ne.Type = cmCacheManager::UNINITIALIZED;
ne.Type = cmState::UNINITIALIZED;
ne.SetProperty(*p, e.Value.c_str());
}
else
......@@ -427,15 +381,15 @@ bool cmCacheManager::SaveCache(const std::string& path)
sprintf(temp, "%d", cmVersion::GetMinorVersion());
this->AddCacheEntry("CMAKE_CACHE_MINOR_VERSION", temp,
"Minor version of cmake used to create the "
"current loaded cache", cmCacheManager::INTERNAL);
"current loaded cache", cmState::INTERNAL);
sprintf(temp, "%d", cmVersion::GetMajorVersion());
this->AddCacheEntry("CMAKE_CACHE_MAJOR_VERSION", temp,
"Major version of cmake used to create the "
"current loaded cache", cmCacheManager::INTERNAL);
"current loaded cache", cmState::INTERNAL);
sprintf(temp, "%d", cmVersion::GetPatchVersion());
this->AddCacheEntry("CMAKE_CACHE_PATCH_VERSION", temp,
"Patch version of cmake used to create the "
"current loaded cache", cmCacheManager::INTERNAL);
"current loaded cache", cmState::INTERNAL);
// Let us store the current working directory so that if somebody
// Copies it, he will not be surprised
......@@ -450,7 +404,7 @@ bool cmCacheManager::SaveCache(const std::string& path)
cmSystemTools::ConvertToUnixSlashes(currentcwd);
this->AddCacheEntry("CMAKE_CACHEFILE_DIR", currentcwd.c_str(),
"This is the directory where this CMakeCache.txt"
" was created", cmCacheManager::INTERNAL);
" was created", cmState::INTERNAL);
fout << "# This is the CMakeCache file.\n"
<< "# For build in directory: " << currentcwd << "\n";
......@@ -484,7 +438,7 @@ bool cmCacheManager::SaveCache(const std::string& path)
this->Cache.begin(); i != this->Cache.end(); ++i)
{
const CacheEntry& ce = (*i).second;
CacheEntryType t = ce.Type;
cmState::CacheEntryType t = ce.Type;
if(!ce.Initialized)
{
/*
......@@ -493,7 +447,7 @@ bool cmCacheManager::SaveCache(const std::string& path)
"\" is uninitialized");
*/
}
else if(t != INTERNAL)
else if(t != cmState::INTERNAL)
{
// Format is key:type=value
if(const char* help = ce.GetProperty("HELPSTRING"))
......@@ -505,7 +459,7 @@ bool cmCacheManager::SaveCache(const std::string& path)
cmCacheManager::OutputHelpString(fout, "Missing description");
}
this->OutputKey(fout, i->first);
fout << ":" << cmCacheManagerTypes[t] << "=";
fout << ":" << cmState::CacheEntryTypeToString(t) << "=";
this->OutputValue(fout, ce.Value);
fout << "\n\n";
}
......@@ -525,9 +479,9 @@ bool cmCacheManager::SaveCache(const std::string& path)
continue;
}
CacheEntryType t = i.GetType();
cmState::CacheEntryType t = i.GetType();
this->WritePropertyEntries(fout, i);
if(t == cmCacheManager::INTERNAL)
if(t == cmState::INTERNAL)
{
// Format is key:type=value
if(const char* help = i.GetProperty("HELPSTRING"))
......@@ -535,7 +489,7 @@ bool cmCacheManager::SaveCache(const std::string& path)
this->OutputHelpString(fout, help);
}
this->OutputKey(fout, i.GetName());
fout << ":" << cmCacheManagerTypes[t] << "=";
fout << ":" << cmState::CacheEntryTypeToString(t) << "=";