1
0
mirror of https://github.com/Kitware/CMake.git synced 2025-10-14 19:08:07 +08:00

cmPropertyMap: Make std::map container private

This commit is contained in:
Sebastian Holtermann
2019-06-02 13:34:31 +02:00
parent 026f65d284
commit 8d934d861b
5 changed files with 40 additions and 48 deletions

View File

@@ -1205,12 +1205,9 @@ bool cmExportFileGenerator::PopulateExportProperties(
std::string& errorMessage) std::string& errorMessage)
{ {
auto& targetProperties = gte->Target->GetProperties(); auto& targetProperties = gte->Target->GetProperties();
const auto& exportProperties = targetProperties.find("EXPORT_PROPERTIES"); if (const char* exportProperties =
if (exportProperties != targetProperties.end()) { targetProperties.GetPropertyValue("EXPORT_PROPERTIES")) {
std::vector<std::string> propsToExport; for (auto& prop : cmSystemTools::ExpandedListArgument(exportProperties)) {
cmSystemTools::ExpandListArgument(exportProperties->second.GetValue(),
propsToExport);
for (auto& prop : propsToExport) {
/* Black list reserved properties */ /* Black list reserved properties */
if (cmSystemTools::StringStartsWith(prop, "IMPORTED_") || if (cmSystemTools::StringStartsWith(prop, "IMPORTED_") ||
cmSystemTools::StringStartsWith(prop, "INTERFACE_")) { cmSystemTools::StringStartsWith(prop, "INTERFACE_")) {

View File

@@ -2,30 +2,21 @@
file Copyright.txt or https://cmake.org/licensing for details. */ file Copyright.txt or https://cmake.org/licensing for details. */
#include "cmPropertyMap.h" #include "cmPropertyMap.h"
#include <assert.h>
#include <utility> #include <utility>
cmProperty* cmPropertyMap::GetOrCreateProperty(const std::string& name) void cmPropertyMap::Clear()
{ {
cmPropertyMap::iterator it = this->find(name); Map_.clear();
cmProperty* prop;
if (it == this->end()) {
prop = &(*this)[name];
} else {
prop = &(it->second);
}
return prop;
} }
void cmPropertyMap::SetProperty(const std::string& name, const char* value) void cmPropertyMap::SetProperty(const std::string& name, const char* value)
{ {
if (!value) { if (!value) {
this->erase(name); Map_.erase(name);
return; return;
} }
cmProperty* prop = this->GetOrCreateProperty(name); Map_[name].Set(value);
prop->Set(value);
} }
void cmPropertyMap::AppendProperty(const std::string& name, const char* 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; return;
} }
cmProperty* prop = this->GetOrCreateProperty(name); Map_[name].Append(value, asString);
prop->Append(value, asString);
} }
const char* cmPropertyMap::GetPropertyValue(const std::string& name) const const char* cmPropertyMap::GetPropertyValue(const std::string& name) const
{ {
assert(!name.empty()); {
auto it = Map_.find(name);
cmPropertyMap::const_iterator it = this->find(name); if (it != Map_.end()) {
if (it == this->end()) { return it->second.GetValue();
return nullptr; }
} }
return it->second.GetValue(); return nullptr;
} }
std::vector<std::string> cmPropertyMap::GetKeys() const std::vector<std::string> cmPropertyMap::GetKeys() const
{ {
std::vector<std::string> keyList; std::vector<std::string> keyList;
keyList.reserve(this->size()); keyList.reserve(Map_.size());
for (auto const& item : *this) { for (auto const& item : Map_) {
keyList.push_back(item.first); keyList.push_back(item.first);
} }
return keyList; return keyList;
@@ -64,8 +54,8 @@ std::vector<std::string> cmPropertyMap::GetKeys() const
std::vector<std::pair<std::string, std::string>> cmPropertyMap::GetList() const std::vector<std::pair<std::string, std::string>> cmPropertyMap::GetList() const
{ {
std::vector<std::pair<std::string, std::string>> kvList; std::vector<std::pair<std::string, std::string>> kvList;
kvList.reserve(this->size()); kvList.reserve(Map_.size());
for (auto const& item : *this) { for (auto const& item : Map_) {
kvList.emplace_back(item.first, item.second.GetValue()); kvList.emplace_back(item.first, item.second.GetValue());
} }
return kvList; return kvList;

View File

@@ -12,12 +12,14 @@
#include <utility> #include <utility>
#include <vector> #include <vector>
class cmPropertyMap : public std::map<std::string, cmProperty> class cmPropertyMap
{ {
public: public:
// -- Properties // -- General
cmProperty* GetOrCreateProperty(const std::string& name); //! Clear property list
void Clear();
// -- Properties
void SetProperty(const std::string& name, const char* value); void SetProperty(const std::string& name, const char* value);
void AppendProperty(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 //! Get a sorted by key list of property key,value pairs
std::vector<std::pair<std::string, std::string>> GetList() const; std::vector<std::pair<std::string, std::string>> GetList() const;
private:
std::map<std::string, cmProperty> Map_;
}; };
#endif #endif

View File

@@ -267,7 +267,7 @@ void cmState::RemoveCacheEntryProperty(std::string const& key,
cmStateSnapshot cmState::Reset() cmStateSnapshot cmState::Reset()
{ {
this->GlobalProperties.clear(); this->GlobalProperties.Clear();
this->PropertyDefinitions.clear(); this->PropertyDefinitions.clear();
this->GlobVerificationManager->Reset(); this->GlobVerificationManager->Reset();
@@ -289,7 +289,7 @@ cmStateSnapshot cmState::Reset()
it->LinkDirectoriesBacktraces.clear(); it->LinkDirectoriesBacktraces.clear();
it->DirectoryEnd = pos; it->DirectoryEnd = pos;
it->NormalTargetNames.clear(); it->NormalTargetNames.clear();
it->Properties.clear(); it->Properties.Clear();
it->Children.clear(); it->Children.clear();
} }

View File

@@ -774,11 +774,11 @@ void cmVisualStudio10TargetGenerator::WriteDotNetReferences(Elem& e0)
cmSystemTools::ExpandListArgument(vsDotNetReferences, references); cmSystemTools::ExpandListArgument(vsDotNetReferences, references);
} }
cmPropertyMap const& props = this->GeneratorTarget->Target->GetProperties(); 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) { if (i.first.find("VS_DOTNET_REFERENCE_") == 0) {
std::string name = i.first.substr(20); std::string name = i.first.substr(20);
if (!name.empty()) { if (!name.empty()) {
std::string path = i.second.GetValue(); std::string path = i.second;
if (!cmsys::SystemTools::FileIsFullPath(path)) { if (!cmsys::SystemTools::FileIsFullPath(path)) {
path = this->Makefile->GetCurrentSourceDirectory() + "/" + path; path = this->Makefile->GetCurrentSourceDirectory() + "/" + path;
} }
@@ -870,10 +870,10 @@ void cmVisualStudio10TargetGenerator::WriteDotNetReferenceCustomTags(
typedef std::map<std::string, std::string> CustomTags; typedef std::map<std::string, std::string> CustomTags;
CustomTags tags; CustomTags tags;
cmPropertyMap const& props = this->GeneratorTarget->Target->GetProperties(); cmPropertyMap const& props = this->GeneratorTarget->Target->GetProperties();
for (const auto& i : props) { for (const auto& i : props.GetList()) {
if (i.first.find(refPropFullPrefix) == 0) { if (i.first.find(refPropFullPrefix) == 0) {
std::string refTag = i.first.substr(refPropFullPrefix.length()); std::string refTag = i.first.substr(refPropFullPrefix.length());
std::string refVal = i.second.GetValue(); std::string refVal = i.second;
if (!refTag.empty() && !refVal.empty()) { if (!refTag.empty() && !refVal.empty()) {
tags[refTag] = refVal; tags[refTag] = refVal;
} }
@@ -967,12 +967,12 @@ void cmVisualStudio10TargetGenerator::WriteEmbeddedResourceGroup(Elem& e0)
} }
} }
const cmPropertyMap& props = oi->GetProperties(); const cmPropertyMap& props = oi->GetProperties();
for (const auto& p : props) { for (const std::string& p : props.GetKeys()) {
static const std::string propNamePrefix = "VS_CSHARP_"; static const std::string propNamePrefix = "VS_CSHARP_";
if (p.first.find(propNamePrefix) == 0) { if (p.find(propNamePrefix) == 0) {
std::string tagName = p.first.substr(propNamePrefix.length()); std::string tagName = p.substr(propNamePrefix.length());
if (!tagName.empty()) { if (!tagName.empty()) {
std::string value = props.GetPropertyValue(p.first); std::string value = props.GetPropertyValue(p);
if (!value.empty()) { if (!value.empty()) {
e2.Element(tagName.c_str(), value); e2.Element(tagName.c_str(), value);
} }
@@ -4681,12 +4681,12 @@ void cmVisualStudio10TargetGenerator::GetCSharpSourceProperties(
{ {
if (this->ProjectType == csproj) { if (this->ProjectType == csproj) {
const cmPropertyMap& props = sf->GetProperties(); const cmPropertyMap& props = sf->GetProperties();
for (auto const& p : props) { for (const std::string& p : props.GetKeys()) {
static const std::string propNamePrefix = "VS_CSHARP_"; static const std::string propNamePrefix = "VS_CSHARP_";
if (p.first.find(propNamePrefix) == 0) { if (p.find(propNamePrefix) == 0) {
std::string tagName = p.first.substr(propNamePrefix.length()); std::string tagName = p.substr(propNamePrefix.length());
if (!tagName.empty()) { if (!tagName.empty()) {
const std::string val = props.GetPropertyValue(p.first); const std::string val = props.GetPropertyValue(p);
if (!val.empty()) { if (!val.empty()) {
tags[tagName] = val; tags[tagName] = val;
} else { } else {