From 8d934d861be8c2a8b43d4c421715fb1e8c0c54fd Mon Sep 17 00:00:00 2001 From: Sebastian Holtermann Date: Sun, 2 Jun 2019 13:34:31 +0200 Subject: cmPropertyMap: Make std::map container private --- Source/cmExportFileGenerator.cxx | 9 +++---- Source/cmPropertyMap.cxx | 40 +++++++++++------------------- Source/cmPropertyMap.h | 11 +++++--- Source/cmState.cxx | 4 +-- Source/cmVisualStudio10TargetGenerator.cxx | 24 +++++++++--------- 5 files changed, 40 insertions(+), 48 deletions(-) diff --git a/Source/cmExportFileGenerator.cxx b/Source/cmExportFileGenerator.cxx index a12e0c4..6621797 100644 --- a/Source/cmExportFileGenerator.cxx +++ b/Source/cmExportFileGenerator.cxx @@ -1205,12 +1205,9 @@ bool cmExportFileGenerator::PopulateExportProperties( std::string& errorMessage) { auto& targetProperties = gte->Target->GetProperties(); - const auto& exportProperties = targetProperties.find("EXPORT_PROPERTIES"); - if (exportProperties != targetProperties.end()) { - std::vector propsToExport; - cmSystemTools::ExpandListArgument(exportProperties->second.GetValue(), - propsToExport); - for (auto& prop : propsToExport) { + if (const char* exportProperties = + targetProperties.GetPropertyValue("EXPORT_PROPERTIES")) { + for (auto& prop : cmSystemTools::ExpandedListArgument(exportProperties)) { /* Black list reserved properties */ if (cmSystemTools::StringStartsWith(prop, "IMPORTED_") || cmSystemTools::StringStartsWith(prop, "INTERFACE_")) { diff --git a/Source/cmPropertyMap.cxx b/Source/cmPropertyMap.cxx index 09b30ba..7177a63 100644 --- a/Source/cmPropertyMap.cxx +++ b/Source/cmPropertyMap.cxx @@ -2,30 +2,21 @@ file Copyright.txt or https://cmake.org/licensing for details. */ #include "cmPropertyMap.h" -#include #include -cmProperty* cmPropertyMap::GetOrCreateProperty(const std::string& name) +void cmPropertyMap::Clear() { - cmPropertyMap::iterator it = this->find(name); - cmProperty* prop; - if (it == this->end()) { - prop = &(*this)[name]; - } else { - prop = &(it->second); - } - return prop; + Map_.clear(); } void cmPropertyMap::SetProperty(const std::string& name, const char* value) { if (!value) { - this->erase(name); + Map_.erase(name); return; } - cmProperty* prop = this->GetOrCreateProperty(name); - prop->Set(value); + Map_[name].Set(value); } void cmPropertyMap::AppendProperty(const std::string& name, const char* value, @@ -36,26 +27,25 @@ void cmPropertyMap::AppendProperty(const std::string& name, const char* value, return; } - cmProperty* prop = this->GetOrCreateProperty(name); - prop->Append(value, asString); + Map_[name].Append(value, asString); } const char* cmPropertyMap::GetPropertyValue(const std::string& name) const { - assert(!name.empty()); - - cmPropertyMap::const_iterator it = this->find(name); - if (it == this->end()) { - return nullptr; + { + auto it = Map_.find(name); + if (it != Map_.end()) { + return it->second.GetValue(); + } } - return it->second.GetValue(); + return nullptr; } std::vector cmPropertyMap::GetKeys() const { std::vector keyList; - keyList.reserve(this->size()); - for (auto const& item : *this) { + keyList.reserve(Map_.size()); + for (auto const& item : Map_) { keyList.push_back(item.first); } return keyList; @@ -64,8 +54,8 @@ std::vector cmPropertyMap::GetKeys() const std::vector> cmPropertyMap::GetList() const { std::vector> kvList; - kvList.reserve(this->size()); - for (auto const& item : *this) { + kvList.reserve(Map_.size()); + for (auto const& item : Map_) { kvList.emplace_back(item.first, item.second.GetValue()); } return kvList; diff --git a/Source/cmPropertyMap.h b/Source/cmPropertyMap.h index e2348a3..4fcbf58 100644 --- a/Source/cmPropertyMap.h +++ b/Source/cmPropertyMap.h @@ -12,12 +12,14 @@ #include #include -class cmPropertyMap : public std::map +class cmPropertyMap { public: - // -- Properties - cmProperty* GetOrCreateProperty(const std::string& name); + // -- General + //! Clear property list + void Clear(); + // -- Properties void SetProperty(const std::string& name, const char* value); void AppendProperty(const std::string& name, const char* value, @@ -31,6 +33,9 @@ public: //! Get a sorted by key list of property key,value pairs std::vector> GetList() const; + +private: + std::map Map_; }; #endif diff --git a/Source/cmState.cxx b/Source/cmState.cxx index fa7df0b..091c2e0 100644 --- a/Source/cmState.cxx +++ b/Source/cmState.cxx @@ -267,7 +267,7 @@ void cmState::RemoveCacheEntryProperty(std::string const& key, cmStateSnapshot cmState::Reset() { - this->GlobalProperties.clear(); + this->GlobalProperties.Clear(); this->PropertyDefinitions.clear(); this->GlobVerificationManager->Reset(); @@ -289,7 +289,7 @@ cmStateSnapshot cmState::Reset() it->LinkDirectoriesBacktraces.clear(); it->DirectoryEnd = pos; it->NormalTargetNames.clear(); - it->Properties.clear(); + it->Properties.Clear(); it->Children.clear(); } diff --git a/Source/cmVisualStudio10TargetGenerator.cxx b/Source/cmVisualStudio10TargetGenerator.cxx index 9368414..634c990 100644 --- a/Source/cmVisualStudio10TargetGenerator.cxx +++ b/Source/cmVisualStudio10TargetGenerator.cxx @@ -774,11 +774,11 @@ void cmVisualStudio10TargetGenerator::WriteDotNetReferences(Elem& e0) cmSystemTools::ExpandListArgument(vsDotNetReferences, references); } cmPropertyMap const& props = this->GeneratorTarget->Target->GetProperties(); - for (auto const& i : props) { + for (auto const& i : props.GetList()) { if (i.first.find("VS_DOTNET_REFERENCE_") == 0) { std::string name = i.first.substr(20); if (!name.empty()) { - std::string path = i.second.GetValue(); + std::string path = i.second; if (!cmsys::SystemTools::FileIsFullPath(path)) { path = this->Makefile->GetCurrentSourceDirectory() + "/" + path; } @@ -870,10 +870,10 @@ void cmVisualStudio10TargetGenerator::WriteDotNetReferenceCustomTags( typedef std::map CustomTags; CustomTags tags; cmPropertyMap const& props = this->GeneratorTarget->Target->GetProperties(); - for (const auto& i : props) { + for (const auto& i : props.GetList()) { if (i.first.find(refPropFullPrefix) == 0) { std::string refTag = i.first.substr(refPropFullPrefix.length()); - std::string refVal = i.second.GetValue(); + std::string refVal = i.second; if (!refTag.empty() && !refVal.empty()) { tags[refTag] = refVal; } @@ -967,12 +967,12 @@ void cmVisualStudio10TargetGenerator::WriteEmbeddedResourceGroup(Elem& e0) } } const cmPropertyMap& props = oi->GetProperties(); - for (const auto& p : props) { + for (const std::string& p : props.GetKeys()) { static const std::string propNamePrefix = "VS_CSHARP_"; - if (p.first.find(propNamePrefix) == 0) { - std::string tagName = p.first.substr(propNamePrefix.length()); + if (p.find(propNamePrefix) == 0) { + std::string tagName = p.substr(propNamePrefix.length()); if (!tagName.empty()) { - std::string value = props.GetPropertyValue(p.first); + std::string value = props.GetPropertyValue(p); if (!value.empty()) { e2.Element(tagName.c_str(), value); } @@ -4681,12 +4681,12 @@ void cmVisualStudio10TargetGenerator::GetCSharpSourceProperties( { if (this->ProjectType == csproj) { const cmPropertyMap& props = sf->GetProperties(); - for (auto const& p : props) { + for (const std::string& p : props.GetKeys()) { static const std::string propNamePrefix = "VS_CSHARP_"; - if (p.first.find(propNamePrefix) == 0) { - std::string tagName = p.first.substr(propNamePrefix.length()); + if (p.find(propNamePrefix) == 0) { + std::string tagName = p.substr(propNamePrefix.length()); if (!tagName.empty()) { - const std::string val = props.GetPropertyValue(p.first); + const std::string val = props.GetPropertyValue(p); if (!val.empty()) { tags[tagName] = val; } else { -- cgit v0.12