cmCacheManager: more members use std::string

This commit is contained in:
Vitaly Stakhovsky 2020-01-06 00:00:00 -05:00
parent 3f8be0ad66
commit 93e9d10c7f
3 changed files with 41 additions and 40 deletions

View File

@ -190,7 +190,7 @@ bool cmCacheManager::ReadPropertyEntry(std::string const& entryKey,
if (entryKey.size() > plen && *(end - plen) == '-' &&
strcmp(end - plen + 1, *p) == 0) {
std::string key = entryKey.substr(0, entryKey.size() - plen);
cmCacheManager::CacheIterator it = this->GetCacheIterator(key.c_str());
cmCacheManager::CacheIterator it = this->GetCacheIterator(key);
if (it.IsAtEnd()) {
// Create an entry and store the property.
CacheEntry& ne = this->Cache[key];
@ -497,9 +497,15 @@ cmCacheManager::CacheEntry* cmCacheManager::GetCacheEntry(
return nullptr;
}
cmCacheManager::CacheIterator cmCacheManager::GetCacheIterator(const char* key)
cmCacheManager::CacheIterator cmCacheManager::GetCacheIterator(
const std::string& key)
{
return { *this, key };
return { *this, key.c_str() };
}
cmCacheManager::CacheIterator cmCacheManager::GetCacheIterator()
{
return { *this, nullptr };
}
const std::string* cmCacheManager::GetInitializedCacheValue(
@ -638,20 +644,21 @@ void cmCacheManager::CacheEntry::SetProperty(const std::string& prop,
}
void cmCacheManager::CacheEntry::AppendProperty(const std::string& prop,
const char* value,
const std::string& value,
bool asString)
{
if (prop == "TYPE") {
this->Type = cmState::StringToCacheEntryType(value ? value : "STRING");
this->Type = cmState::StringToCacheEntryType(!value.empty() ? value.c_str()
: "STRING");
} else if (prop == "VALUE") {
if (value) {
if (!this->Value.empty() && *value && !asString) {
if (!value.empty()) {
if (!this->Value.empty() && !asString) {
this->Value += ";";
}
this->Value += value;
}
} else {
this->Properties.AppendProperty(prop, value, asString);
this->Properties.AppendProperty(prop, value.c_str(), asString);
}
}
@ -673,7 +680,7 @@ void cmCacheManager::CacheIterator::SetProperty(const std::string& p,
}
void cmCacheManager::CacheIterator::AppendProperty(const std::string& p,
const char* v,
const std::string& v,
bool asString)
{
if (!this->IsAtEnd()) {

View File

@ -39,7 +39,7 @@ private:
std::vector<std::string> GetPropertyList() const;
const char* GetProperty(const std::string&) const;
void SetProperty(const std::string& property, const char* value);
void AppendProperty(const std::string& property, const char* value,
void AppendProperty(const std::string& property, const std::string& value,
bool asString = false);
bool Initialized = false;
};
@ -58,10 +58,10 @@ public:
bool GetPropertyAsBool(const std::string&) const;
bool PropertyExists(const std::string&) const;
void SetProperty(const std::string& property, const char* value);
void AppendProperty(const std::string& property, const char* value,
void AppendProperty(const std::string& property, const std::string& value,
bool asString = false);
void SetProperty(const std::string& property, bool value);
const char* GetValue() const { return this->GetEntry().Value.c_str(); }
const std::string& GetValue() const { return this->GetEntry().Value; }
bool GetValueAsBool() const;
void SetValue(const char*);
cmStateEnums::CacheEntryType GetType() const
@ -111,7 +111,8 @@ public:
void PrintCache(std::ostream&) const;
//! Get the iterator for an entry with a given key.
cmCacheManager::CacheIterator GetCacheIterator(const char* key = nullptr);
cmCacheManager::CacheIterator GetCacheIterator(const std::string& key);
cmCacheManager::CacheIterator GetCacheIterator();
//! Remove an entry from the cache
void RemoveCacheEntry(const std::string& key);
@ -124,52 +125,52 @@ public:
const char* GetCacheEntryValue(const std::string& key)
{
cmCacheManager::CacheIterator it = this->GetCacheIterator(key.c_str());
cmCacheManager::CacheIterator it = this->GetCacheIterator(key);
if (it.IsAtEnd()) {
return nullptr;
}
return it.GetValue();
return it.GetValue().c_str();
}
const char* GetCacheEntryProperty(std::string const& key,
std::string const& propName)
{
return this->GetCacheIterator(key.c_str()).GetProperty(propName);
return this->GetCacheIterator(key).GetProperty(propName);
}
cmStateEnums::CacheEntryType GetCacheEntryType(std::string const& key)
{
return this->GetCacheIterator(key.c_str()).GetType();
return this->GetCacheIterator(key).GetType();
}
bool GetCacheEntryPropertyAsBool(std::string const& key,
std::string const& propName)
{
return this->GetCacheIterator(key.c_str()).GetPropertyAsBool(propName);
return this->GetCacheIterator(key).GetPropertyAsBool(propName);
}
void SetCacheEntryProperty(std::string const& key,
std::string const& propName,
std::string const& value)
{
this->GetCacheIterator(key.c_str()).SetProperty(propName, value.c_str());
this->GetCacheIterator(key).SetProperty(propName, value.c_str());
}
void SetCacheEntryBoolProperty(std::string const& key,
std::string const& propName, bool value)
{
this->GetCacheIterator(key.c_str()).SetProperty(propName, value);
this->GetCacheIterator(key).SetProperty(propName, value);
}
void SetCacheEntryValue(std::string const& key, std::string const& value)
{
this->GetCacheIterator(key.c_str()).SetValue(value.c_str());
this->GetCacheIterator(key).SetValue(value.c_str());
}
void RemoveCacheEntryProperty(std::string const& key,
std::string const& propName)
{
this->GetCacheIterator(key.c_str()).SetProperty(propName, nullptr);
this->GetCacheIterator(key).SetProperty(propName, nullptr);
}
void AppendCacheEntryProperty(std::string const& key,
@ -177,8 +178,7 @@ public:
std::string const& value,
bool asString = false)
{
this->GetCacheIterator(key.c_str())
.AppendProperty(propName, value.c_str(), asString);
this->GetCacheIterator(key).AppendProperty(propName, value, asString);
}
std::vector<std::string> GetCacheEntryKeys()

View File

@ -150,8 +150,7 @@ const std::string* cmState::GetInitializedCacheValue(
cmStateEnums::CacheEntryType cmState::GetCacheEntryType(
std::string const& key) const
{
cmCacheManager::CacheIterator it =
this->CacheManager->GetCacheIterator(key.c_str());
cmCacheManager::CacheIterator it = this->CacheManager->GetCacheIterator(key);
return it.GetType();
}
@ -165,8 +164,7 @@ void cmState::SetCacheEntryProperty(std::string const& key,
std::string const& propertyName,
std::string const& value)
{
cmCacheManager::CacheIterator it =
this->CacheManager->GetCacheIterator(key.c_str());
cmCacheManager::CacheIterator it = this->CacheManager->GetCacheIterator(key);
it.SetProperty(propertyName, value.c_str());
}
@ -174,24 +172,21 @@ void cmState::SetCacheEntryBoolProperty(std::string const& key,
std::string const& propertyName,
bool value)
{
cmCacheManager::CacheIterator it =
this->CacheManager->GetCacheIterator(key.c_str());
cmCacheManager::CacheIterator it = this->CacheManager->GetCacheIterator(key);
it.SetProperty(propertyName, value);
}
std::vector<std::string> cmState::GetCacheEntryPropertyList(
const std::string& key)
{
cmCacheManager::CacheIterator it =
this->CacheManager->GetCacheIterator(key.c_str());
cmCacheManager::CacheIterator it = this->CacheManager->GetCacheIterator(key);
return it.GetPropertyList();
}
const char* cmState::GetCacheEntryProperty(std::string const& key,
std::string const& propertyName)
{
cmCacheManager::CacheIterator it =
this->CacheManager->GetCacheIterator(key.c_str());
cmCacheManager::CacheIterator it = this->CacheManager->GetCacheIterator(key);
if (!it.PropertyExists(propertyName)) {
return nullptr;
}
@ -201,8 +196,8 @@ const char* cmState::GetCacheEntryProperty(std::string const& key,
bool cmState::GetCacheEntryPropertyAsBool(std::string const& key,
std::string const& propertyName)
{
return this->CacheManager->GetCacheIterator(key.c_str())
.GetPropertyAsBool(propertyName);
return this->CacheManager->GetCacheIterator(key).GetPropertyAsBool(
propertyName);
}
void cmState::AddCacheEntry(const std::string& key, const char* value,
@ -254,15 +249,14 @@ void cmState::AppendCacheEntryProperty(const std::string& key,
const std::string& property,
const std::string& value, bool asString)
{
this->CacheManager->GetCacheIterator(key.c_str())
.AppendProperty(property, value.c_str(), asString);
this->CacheManager->GetCacheIterator(key).AppendProperty(property, value,
asString);
}
void cmState::RemoveCacheEntryProperty(std::string const& key,
std::string const& propertyName)
{
this->CacheManager->GetCacheIterator(key.c_str())
.SetProperty(propertyName, nullptr);
this->CacheManager->GetCacheIterator(key).SetProperty(propertyName, nullptr);
}
cmStateSnapshot cmState::Reset()