ENH: Use cmPropertyMap for cache properties
This re-implements cache entry property storage in cmCacheManager to use cmPropertyMap so it can share the standard property implementation.
This commit is contained in:
parent
effd6d6e0b
commit
ca9fb4826f
@ -212,6 +212,7 @@ bool cmCacheManager::LoadCache(const char* path,
|
|||||||
while(fin)
|
while(fin)
|
||||||
{
|
{
|
||||||
// Format is key:type=value
|
// Format is key:type=value
|
||||||
|
std::string helpString;
|
||||||
CacheEntry e;
|
CacheEntry e;
|
||||||
cmSystemTools::GetLineFromStream(fin, buffer);
|
cmSystemTools::GetLineFromStream(fin, buffer);
|
||||||
realbuffer = buffer.c_str();
|
realbuffer = buffer.c_str();
|
||||||
@ -232,12 +233,12 @@ bool cmCacheManager::LoadCache(const char* path,
|
|||||||
{
|
{
|
||||||
if ((realbuffer[2] == '\\') && (realbuffer[3]=='n'))
|
if ((realbuffer[2] == '\\') && (realbuffer[3]=='n'))
|
||||||
{
|
{
|
||||||
e.Properties["HELPSTRING"] += "\n";
|
helpString += "\n";
|
||||||
e.Properties["HELPSTRING"] += &realbuffer[4];
|
helpString += &realbuffer[4];
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
e.Properties["HELPSTRING"] += &realbuffer[2];
|
helpString += &realbuffer[2];
|
||||||
}
|
}
|
||||||
cmSystemTools::GetLineFromStream(fin, buffer);
|
cmSystemTools::GetLineFromStream(fin, buffer);
|
||||||
realbuffer = buffer.c_str();
|
realbuffer = buffer.c_str();
|
||||||
@ -246,6 +247,7 @@ bool cmCacheManager::LoadCache(const char* path,
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
e.SetProperty("HELPSTRING", helpString.c_str());
|
||||||
if(cmCacheManager::ParseEntry(realbuffer, entryKey, e.Value, e.Type))
|
if(cmCacheManager::ParseEntry(realbuffer, entryKey, e.Value, e.Type))
|
||||||
{
|
{
|
||||||
if ( excludes.find(entryKey) == excludes.end() )
|
if ( excludes.find(entryKey) == excludes.end() )
|
||||||
@ -263,12 +265,13 @@ bool cmCacheManager::LoadCache(const char* path,
|
|||||||
if (!internal)
|
if (!internal)
|
||||||
{
|
{
|
||||||
e.Type = INTERNAL;
|
e.Type = INTERNAL;
|
||||||
e.Properties["HELPSTRING"] = "DO NOT EDIT, ";
|
helpString = "DO NOT EDIT, ";
|
||||||
e.Properties["HELPSTRING"] += entryKey;
|
helpString += entryKey;
|
||||||
e.Properties["HELPSTRING"] += " loaded from external file. "
|
helpString += " loaded from external file. "
|
||||||
"To change this value edit this file: ";
|
"To change this value edit this file: ";
|
||||||
e.Properties["HELPSTRING"] += path;
|
helpString += path;
|
||||||
e.Properties["HELPSTRING"] += "/CMakeCache.txt" ;
|
helpString += "/CMakeCache.txt" ;
|
||||||
|
e.SetProperty("HELPSTRING", helpString.c_str());
|
||||||
}
|
}
|
||||||
if ( e.Type == cmCacheManager::INTERNAL &&
|
if ( e.Type == cmCacheManager::INTERNAL &&
|
||||||
(entryKey.size() > strlen("-ADVANCED")) &&
|
(entryKey.size() > strlen("-ADVANCED")) &&
|
||||||
@ -472,15 +475,13 @@ bool cmCacheManager::SaveCache(const char* path)
|
|||||||
else if(t != INTERNAL)
|
else if(t != INTERNAL)
|
||||||
{
|
{
|
||||||
// Format is key:type=value
|
// Format is key:type=value
|
||||||
std::map<cmStdString,cmStdString>::const_iterator it =
|
if(const char* help = ce.GetProperty("HELPSTRING"))
|
||||||
ce.Properties.find("HELPSTRING");
|
|
||||||
if ( it == ce.Properties.end() )
|
|
||||||
{
|
{
|
||||||
cmCacheManager::OutputHelpString(fout, "Missing description");
|
cmCacheManager::OutputHelpString(fout, help);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
cmCacheManager::OutputHelpString(fout, it->second);
|
cmCacheManager::OutputHelpString(fout, "Missing description");
|
||||||
}
|
}
|
||||||
std::string key;
|
std::string key;
|
||||||
// support : in key name by double quoting
|
// support : in key name by double quoting
|
||||||
@ -803,15 +804,8 @@ void cmCacheManager::AddCacheEntry(const char* key,
|
|||||||
cmSystemTools::ConvertToUnixSlashes(e.Value);
|
cmSystemTools::ConvertToUnixSlashes(e.Value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if ( helpString )
|
e.SetProperty("HELPSTRING", helpString? helpString :
|
||||||
{
|
"(This variable does not exist and should not be used)");
|
||||||
e.Properties["HELPSTRING"] = helpString;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
e.Properties["HELPSTRING"] =
|
|
||||||
"(This variable does not exist and should not be used)";
|
|
||||||
}
|
|
||||||
this->Cache[key] = e;
|
this->Cache[key] = e;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -870,121 +864,121 @@ void cmCacheManager::CacheIterator::SetValue(const char* value)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const char* cmCacheManager::CacheIterator::GetProperty(
|
//----------------------------------------------------------------------------
|
||||||
const char* property) const
|
bool cmCacheManager::CacheIterator::GetValueAsBool() const
|
||||||
{
|
{
|
||||||
// make sure it is not at the end
|
return cmSystemTools::IsOn(this->GetEntry().Value.c_str());
|
||||||
if (this->IsAtEnd())
|
|
||||||
{
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ( !strcmp(property, "TYPE") || !strcmp(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->Properties.find(property);
|
|
||||||
if ( it == ent->Properties.end() )
|
|
||||||
{
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
return it->second.c_str();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//----------------------------------------------------------------------------
|
||||||
|
const char*
|
||||||
|
cmCacheManager::CacheEntry::GetProperty(const char* prop) const
|
||||||
|
{
|
||||||
|
if(strcmp(prop, "TYPE") == 0)
|
||||||
|
{
|
||||||
|
return cmCacheManagerTypes[this->Type];
|
||||||
|
}
|
||||||
|
else if(strcmp(prop, "VALUE") == 0)
|
||||||
|
{
|
||||||
|
return this->Value.c_str();
|
||||||
|
}
|
||||||
|
bool c = false;
|
||||||
|
return
|
||||||
|
this->Properties.GetPropertyValue(prop, cmProperty::CACHE, c);
|
||||||
|
}
|
||||||
|
|
||||||
|
//----------------------------------------------------------------------------
|
||||||
|
void cmCacheManager::CacheEntry::SetProperty(const char* prop,
|
||||||
|
const char* value)
|
||||||
|
{
|
||||||
|
if(strcmp(prop, "TYPE") == 0)
|
||||||
|
{
|
||||||
|
this->Type = cmCacheManager::StringToType(value? value : "STRING");
|
||||||
|
}
|
||||||
|
else if(strcmp(prop, "VALUE") == 0)
|
||||||
|
{
|
||||||
|
this->Value = value? value : "";
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
this->Properties.SetProperty(prop, value, cmProperty::CACHE);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//----------------------------------------------------------------------------
|
||||||
|
void cmCacheManager::CacheEntry::AppendProperty(const char* prop,
|
||||||
|
const char* value)
|
||||||
|
{
|
||||||
|
if(strcmp(prop, "TYPE") == 0)
|
||||||
|
{
|
||||||
|
this->Type = cmCacheManager::StringToType(value? value : "STRING");
|
||||||
|
}
|
||||||
|
else if(strcmp(prop, "VALUE") == 0)
|
||||||
|
{
|
||||||
|
if(value)
|
||||||
|
{
|
||||||
|
if(!this->Value.empty() && *value)
|
||||||
|
{
|
||||||
|
this->Value += ";";
|
||||||
|
}
|
||||||
|
this->Value += value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
this->Properties.AppendProperty(prop, value, cmProperty::CACHE);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//----------------------------------------------------------------------------
|
||||||
|
const char* cmCacheManager::CacheIterator::GetProperty(const char* prop) const
|
||||||
|
{
|
||||||
|
if(!this->IsAtEnd())
|
||||||
|
{
|
||||||
|
return this->GetEntry().GetProperty(prop);
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
//----------------------------------------------------------------------------
|
||||||
void cmCacheManager::CacheIterator::SetProperty(const char* p, const char* v)
|
void cmCacheManager::CacheIterator::SetProperty(const char* p, const char* v)
|
||||||
{
|
{
|
||||||
// make sure it is not at the end
|
if(!this->IsAtEnd())
|
||||||
if (this->IsAtEnd())
|
|
||||||
{
|
{
|
||||||
return;
|
return this->GetEntry().SetProperty(p, v);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( !strcmp(p, "TYPE") || !strcmp(p, "VALUE") )
|
|
||||||
{
|
|
||||||
cmSystemTools::Error("Property \"", p,
|
|
||||||
"\" cannot be accessed through the SetProperty()");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
CacheEntry* ent = &this->GetEntry();
|
|
||||||
ent->Properties[p] = v;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//----------------------------------------------------------------------------
|
||||||
bool cmCacheManager::CacheIterator::GetValueAsBool() const
|
void cmCacheManager::CacheIterator::AppendProperty(const char* p,
|
||||||
{
|
const char* v)
|
||||||
return cmSystemTools::IsOn(this->GetEntry().Value.c_str());
|
|
||||||
}
|
|
||||||
|
|
||||||
bool cmCacheManager::CacheIterator::GetPropertyAsBool(
|
|
||||||
const char* property) const
|
|
||||||
{
|
{
|
||||||
// make sure it is not at the end
|
if(!this->IsAtEnd())
|
||||||
if (this->IsAtEnd())
|
|
||||||
{
|
{
|
||||||
return false;
|
this->GetEntry().AppendProperty(p, v);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( !strcmp(property, "TYPE") || !strcmp(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->Properties.find(property);
|
|
||||||
if ( it == ent->Properties.end() )
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return cmSystemTools::IsOn(it->second.c_str());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//----------------------------------------------------------------------------
|
||||||
|
bool cmCacheManager::CacheIterator::GetPropertyAsBool(const char* prop) const
|
||||||
|
{
|
||||||
|
if(const char* value = this->GetProperty(prop))
|
||||||
|
{
|
||||||
|
return cmSystemTools::IsOn(value);
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
//----------------------------------------------------------------------------
|
||||||
void cmCacheManager::CacheIterator::SetProperty(const char* p, bool v)
|
void cmCacheManager::CacheIterator::SetProperty(const char* p, bool v)
|
||||||
{
|
{
|
||||||
// make sure it is not at the end
|
this->SetProperty(p, v ? "ON" : "OFF");
|
||||||
if (this->IsAtEnd())
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ( !strcmp(p, "TYPE") || !strcmp(p, "VALUE") )
|
|
||||||
{
|
|
||||||
cmSystemTools::Error("Property \"", p,
|
|
||||||
"\" cannot be accessed through the SetProperty()");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
CacheEntry* ent = &this->GetEntry();
|
|
||||||
ent->Properties[p] = v ? "ON" : "OFF";
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool cmCacheManager::CacheIterator::PropertyExists(const char* property) const
|
//----------------------------------------------------------------------------
|
||||||
|
bool cmCacheManager::CacheIterator::PropertyExists(const char* prop) const
|
||||||
{
|
{
|
||||||
// make sure it is not at the end
|
return this->GetProperty(prop)? true:false;
|
||||||
if (this->IsAtEnd())
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ( !strcmp(property, "TYPE") || !strcmp(property, "VALUE") )
|
|
||||||
{
|
|
||||||
cmSystemTools::Error("Property \"", property,
|
|
||||||
"\" cannot be accessed through the PropertyExists()");
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
const CacheEntry* ent = &this->GetEntry();
|
|
||||||
std::map<cmStdString,cmStdString>::const_iterator it =
|
|
||||||
ent->Properties.find(property);
|
|
||||||
if ( it == ent->Properties.end() )
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//----------------------------------------------------------------------------
|
//----------------------------------------------------------------------------
|
||||||
|
@ -18,6 +18,7 @@
|
|||||||
#define cmCacheManager_h
|
#define cmCacheManager_h
|
||||||
|
|
||||||
#include "cmStandardIncludes.h"
|
#include "cmStandardIncludes.h"
|
||||||
|
#include "cmPropertyMap.h"
|
||||||
class cmMakefile;
|
class cmMakefile;
|
||||||
class cmMarkAsAdvancedCommand;
|
class cmMarkAsAdvancedCommand;
|
||||||
|
|
||||||
@ -41,7 +42,10 @@ private:
|
|||||||
{
|
{
|
||||||
std::string Value;
|
std::string Value;
|
||||||
CacheEntryType Type;
|
CacheEntryType Type;
|
||||||
std::map<cmStdString,cmStdString> Properties;
|
cmPropertyMap Properties;
|
||||||
|
const char* GetProperty(const char*) const;
|
||||||
|
void SetProperty(const char* property, const char* value);
|
||||||
|
void AppendProperty(const char* property, const char* value);
|
||||||
bool Initialized;
|
bool Initialized;
|
||||||
CacheEntry() : Value(""), Type(UNINITIALIZED), Initialized(false)
|
CacheEntry() : Value(""), Type(UNINITIALIZED), Initialized(false)
|
||||||
{}
|
{}
|
||||||
@ -61,6 +65,7 @@ public:
|
|||||||
bool GetPropertyAsBool(const char*) const ;
|
bool GetPropertyAsBool(const char*) const ;
|
||||||
bool PropertyExists(const char*) const;
|
bool PropertyExists(const char*) const;
|
||||||
void SetProperty(const char* property, const char* value);
|
void SetProperty(const char* property, const char* value);
|
||||||
|
void AppendProperty(const char* property, const char* value);
|
||||||
void SetProperty(const char* property, bool value);
|
void SetProperty(const char* property, bool value);
|
||||||
const char* GetValue() const { return this->GetEntry().Value.c_str(); }
|
const char* GetValue() const { return this->GetEntry().Value.c_str(); }
|
||||||
bool GetValueAsBool() const;
|
bool GetValueAsBool() const;
|
||||||
|
@ -22,7 +22,7 @@
|
|||||||
class cmProperty
|
class cmProperty
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
enum ScopeType { TARGET, SOURCE_FILE, DIRECTORY, GLOBAL,
|
enum ScopeType { TARGET, SOURCE_FILE, DIRECTORY, GLOBAL, CACHE,
|
||||||
TEST, VARIABLE, CACHED_VARIABLE };
|
TEST, VARIABLE, CACHED_VARIABLE };
|
||||||
|
|
||||||
// set this property
|
// set this property
|
||||||
|
@ -69,6 +69,9 @@ void cmPropertyDefinitionMap
|
|||||||
case cmProperty::TEST:
|
case cmProperty::TEST:
|
||||||
secName = "Properties on Tests";
|
secName = "Properties on Tests";
|
||||||
break;
|
break;
|
||||||
|
case cmProperty::CACHE:
|
||||||
|
secName = "Properties on Cache Entries";
|
||||||
|
break;
|
||||||
case cmProperty::VARIABLE:
|
case cmProperty::VARIABLE:
|
||||||
secName = "Variables";
|
secName = "Variables";
|
||||||
break;
|
break;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user