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

View File

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

View File

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