summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBrad King <brad.king@kitware.com>2009-03-10 15:10:42 (GMT)
committerBrad King <brad.king@kitware.com>2009-03-10 15:10:42 (GMT)
commitca9fb4826f89722a5a190e0c69e6bf5c26889a55 (patch)
treefc2f3474f2417783a7019db34fcdb4d4b98a702d
parenteffd6d6e0b4445811b27af9cbc9db6923f6aacdf (diff)
downloadCMake-ca9fb4826f89722a5a190e0c69e6bf5c26889a55.zip
CMake-ca9fb4826f89722a5a190e0c69e6bf5c26889a55.tar.gz
CMake-ca9fb4826f89722a5a190e0c69e6bf5c26889a55.tar.bz2
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.
-rw-r--r--Source/cmCacheManager.cxx192
-rw-r--r--Source/cmCacheManager.h7
-rw-r--r--Source/cmProperty.h2
-rw-r--r--Source/cmPropertyDefinitionMap.cxx3
4 files changed, 103 insertions, 101 deletions
diff --git a/Source/cmCacheManager.cxx b/Source/cmCacheManager.cxx
index 74e1d4d..f53ed49 100644
--- a/Source/cmCacheManager.cxx
+++ b/Source/cmCacheManager.cxx
@@ -212,6 +212,7 @@ bool cmCacheManager::LoadCache(const char* path,
while(fin)
{
// Format is key:type=value
+ std::string helpString;
CacheEntry e;
cmSystemTools::GetLineFromStream(fin, buffer);
realbuffer = buffer.c_str();
@@ -232,12 +233,12 @@ bool cmCacheManager::LoadCache(const char* path,
{
if ((realbuffer[2] == '\\') && (realbuffer[3]=='n'))
{
- e.Properties["HELPSTRING"] += "\n";
- e.Properties["HELPSTRING"] += &realbuffer[4];
+ helpString += "\n";
+ helpString += &realbuffer[4];
}
else
{
- e.Properties["HELPSTRING"] += &realbuffer[2];
+ helpString += &realbuffer[2];
}
cmSystemTools::GetLineFromStream(fin, buffer);
realbuffer = buffer.c_str();
@@ -246,6 +247,7 @@ bool cmCacheManager::LoadCache(const char* path,
continue;
}
}
+ e.SetProperty("HELPSTRING", helpString.c_str());
if(cmCacheManager::ParseEntry(realbuffer, entryKey, e.Value, e.Type))
{
if ( excludes.find(entryKey) == excludes.end() )
@@ -263,12 +265,13 @@ bool cmCacheManager::LoadCache(const char* path,
if (!internal)
{
e.Type = INTERNAL;
- e.Properties["HELPSTRING"] = "DO NOT EDIT, ";
- e.Properties["HELPSTRING"] += entryKey;
- e.Properties["HELPSTRING"] += " loaded from external file. "
+ helpString = "DO NOT EDIT, ";
+ helpString += entryKey;
+ helpString += " loaded from external file. "
"To change this value edit this file: ";
- e.Properties["HELPSTRING"] += path;
- e.Properties["HELPSTRING"] += "/CMakeCache.txt" ;
+ helpString += path;
+ helpString += "/CMakeCache.txt" ;
+ e.SetProperty("HELPSTRING", helpString.c_str());
}
if ( e.Type == cmCacheManager::INTERNAL &&
(entryKey.size() > strlen("-ADVANCED")) &&
@@ -472,15 +475,13 @@ bool cmCacheManager::SaveCache(const char* path)
else if(t != INTERNAL)
{
// Format is key:type=value
- std::map<cmStdString,cmStdString>::const_iterator it =
- ce.Properties.find("HELPSTRING");
- if ( it == ce.Properties.end() )
+ if(const char* help = ce.GetProperty("HELPSTRING"))
{
- cmCacheManager::OutputHelpString(fout, "Missing description");
+ cmCacheManager::OutputHelpString(fout, help);
}
else
{
- cmCacheManager::OutputHelpString(fout, it->second);
+ cmCacheManager::OutputHelpString(fout, "Missing description");
}
std::string key;
// support : in key name by double quoting
@@ -803,15 +804,8 @@ void cmCacheManager::AddCacheEntry(const char* key,
cmSystemTools::ConvertToUnixSlashes(e.Value);
}
}
- if ( helpString )
- {
- e.Properties["HELPSTRING"] = helpString;
- }
- else
- {
- e.Properties["HELPSTRING"] =
- "(This variable does not exist and should not be used)";
- }
+ e.SetProperty("HELPSTRING", helpString? helpString :
+ "(This variable does not exist and should not be used)");
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
- if (this->IsAtEnd())
- {
- return 0;
- }
+ return cmSystemTools::IsOn(this->GetEntry().Value.c_str());
+}
- if ( !strcmp(property, "TYPE") || !strcmp(property, "VALUE") )
+//----------------------------------------------------------------------------
+const char*
+cmCacheManager::CacheEntry::GetProperty(const char* prop) const
+{
+ if(strcmp(prop, "TYPE") == 0)
{
- cmSystemTools::Error("Property \"", property,
- "\" cannot be accessed through the GetProperty()");
- return 0;
+ return cmCacheManagerTypes[this->Type];
}
- const CacheEntry* ent = &this->GetEntry();
- std::map<cmStdString,cmStdString>::const_iterator it =
- ent->Properties.find(property);
- if ( it == ent->Properties.end() )
+ else if(strcmp(prop, "VALUE") == 0)
{
- return 0;
+ return this->Value.c_str();
}
- return it->second.c_str();
+ bool c = false;
+ return
+ this->Properties.GetPropertyValue(prop, cmProperty::CACHE, c);
}
-void cmCacheManager::CacheIterator::SetProperty(const char* p, const char* v)
+//----------------------------------------------------------------------------
+void cmCacheManager::CacheEntry::SetProperty(const char* prop,
+ const char* value)
{
- // make sure it is not at the end
- if (this->IsAtEnd())
+ if(strcmp(prop, "TYPE") == 0)
{
- return;
+ this->Type = cmCacheManager::StringToType(value? value : "STRING");
}
-
- if ( !strcmp(p, "TYPE") || !strcmp(p, "VALUE") )
+ else if(strcmp(prop, "VALUE") == 0)
{
- cmSystemTools::Error("Property \"", p,
- "\" cannot be accessed through the SetProperty()");
- return;
+ this->Value = value? value : "";
+ }
+ else
+ {
+ this->Properties.SetProperty(prop, value, cmProperty::CACHE);
}
- CacheEntry* ent = &this->GetEntry();
- ent->Properties[p] = v;
-}
-
-
-bool cmCacheManager::CacheIterator::GetValueAsBool() const
-{
- return cmSystemTools::IsOn(this->GetEntry().Value.c_str());
}
-bool cmCacheManager::CacheIterator::GetPropertyAsBool(
- const char* property) const
+//----------------------------------------------------------------------------
+void cmCacheManager::CacheEntry::AppendProperty(const char* prop,
+ const char* value)
{
- // make sure it is not at the end
- if (this->IsAtEnd())
+ if(strcmp(prop, "TYPE") == 0)
{
- return false;
+ this->Type = cmCacheManager::StringToType(value? value : "STRING");
}
-
- if ( !strcmp(property, "TYPE") || !strcmp(property, "VALUE") )
+ else if(strcmp(prop, "VALUE") == 0)
{
- cmSystemTools::Error("Property \"", property,
- "\" cannot be accessed through the GetPropertyAsBool()");
- return false;
+ if(value)
+ {
+ if(!this->Value.empty() && *value)
+ {
+ this->Value += ";";
+ }
+ this->Value += value;
+ }
}
- const CacheEntry* ent = &this->GetEntry();
- std::map<cmStdString,cmStdString>::const_iterator it =
- ent->Properties.find(property);
- if ( it == ent->Properties.end() )
+ else
{
- return false;
+ this->Properties.AppendProperty(prop, value, cmProperty::CACHE);
}
- return cmSystemTools::IsOn(it->second.c_str());
}
-
-void cmCacheManager::CacheIterator::SetProperty(const char* p, bool v)
+//----------------------------------------------------------------------------
+const char* cmCacheManager::CacheIterator::GetProperty(const char* prop) const
{
- // make sure it is not at the end
- if (this->IsAtEnd())
+ if(!this->IsAtEnd())
{
- return;
+ return this->GetEntry().GetProperty(prop);
}
+ return 0;
+}
- if ( !strcmp(p, "TYPE") || !strcmp(p, "VALUE") )
+//----------------------------------------------------------------------------
+void cmCacheManager::CacheIterator::SetProperty(const char* p, const char* v)
+{
+ if(!this->IsAtEnd())
{
- cmSystemTools::Error("Property \"", p,
- "\" cannot be accessed through the SetProperty()");
- return;
+ return this->GetEntry().SetProperty(p, v);
}
- CacheEntry* ent = &this->GetEntry();
- ent->Properties[p] = v ? "ON" : "OFF";
}
-bool cmCacheManager::CacheIterator::PropertyExists(const char* property) const
+//----------------------------------------------------------------------------
+void cmCacheManager::CacheIterator::AppendProperty(const char* p,
+ const char* v)
{
- // 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 PropertyExists()");
- return false;
- }
- const CacheEntry* ent = &this->GetEntry();
- std::map<cmStdString,cmStdString>::const_iterator it =
- ent->Properties.find(property);
- if ( it == ent->Properties.end() )
+//----------------------------------------------------------------------------
+bool cmCacheManager::CacheIterator::GetPropertyAsBool(const char* prop) const
+{
+ if(const char* value = this->GetProperty(prop))
{
- return false;
+ return cmSystemTools::IsOn(value);
}
- return true;
+ return false;
+}
+
+//----------------------------------------------------------------------------
+void cmCacheManager::CacheIterator::SetProperty(const char* p, bool v)
+{
+ this->SetProperty(p, v ? "ON" : "OFF");
+}
+
+//----------------------------------------------------------------------------
+bool cmCacheManager::CacheIterator::PropertyExists(const char* prop) const
+{
+ return this->GetProperty(prop)? true:false;
}
//----------------------------------------------------------------------------
diff --git a/Source/cmCacheManager.h b/Source/cmCacheManager.h
index f1e2298..e57042b 100644
--- a/Source/cmCacheManager.h
+++ b/Source/cmCacheManager.h
@@ -18,6 +18,7 @@
#define cmCacheManager_h
#include "cmStandardIncludes.h"
+#include "cmPropertyMap.h"
class cmMakefile;
class cmMarkAsAdvancedCommand;
@@ -41,7 +42,10 @@ private:
{
std::string Value;
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;
CacheEntry() : Value(""), Type(UNINITIALIZED), Initialized(false)
{}
@@ -61,6 +65,7 @@ public:
bool GetPropertyAsBool(const char*) const ;
bool PropertyExists(const char*) const;
void SetProperty(const char* property, const char* value);
+ void AppendProperty(const char* property, const char* value);
void SetProperty(const char* property, bool value);
const char* GetValue() const { return this->GetEntry().Value.c_str(); }
bool GetValueAsBool() const;
diff --git a/Source/cmProperty.h b/Source/cmProperty.h
index 7d238b6..39f8920 100644
--- a/Source/cmProperty.h
+++ b/Source/cmProperty.h
@@ -22,7 +22,7 @@
class cmProperty
{
public:
- enum ScopeType { TARGET, SOURCE_FILE, DIRECTORY, GLOBAL,
+ enum ScopeType { TARGET, SOURCE_FILE, DIRECTORY, GLOBAL, CACHE,
TEST, VARIABLE, CACHED_VARIABLE };
// set this property
diff --git a/Source/cmPropertyDefinitionMap.cxx b/Source/cmPropertyDefinitionMap.cxx
index b9d0cde..90351bd 100644
--- a/Source/cmPropertyDefinitionMap.cxx
+++ b/Source/cmPropertyDefinitionMap.cxx
@@ -69,6 +69,9 @@ void cmPropertyDefinitionMap
case cmProperty::TEST:
secName = "Properties on Tests";
break;
+ case cmProperty::CACHE:
+ secName = "Properties on Cache Entries";
+ break;
case cmProperty::VARIABLE:
secName = "Variables";
break;