From 9e64e617eb295c7e2725d871225659ae7bcf7c48 Mon Sep 17 00:00:00 2001 From: Sebastian Holtermann Date: Sun, 2 Jun 2019 12:35:33 +0200 Subject: cmPropertyMap: Rename GetPropertyList method to GetKeys --- Source/cmCacheManager.cxx | 2 +- Source/cmGeneratorTarget.cxx | 8 +------- Source/cmPropertyMap.cxx | 21 ++++++++++----------- Source/cmPropertyMap.h | 7 +++++-- Source/cmStateDirectory.cxx | 8 +------- 5 files changed, 18 insertions(+), 28 deletions(-) diff --git a/Source/cmCacheManager.cxx b/Source/cmCacheManager.cxx index 358f095..e8fc350 100644 --- a/Source/cmCacheManager.cxx +++ b/Source/cmCacheManager.cxx @@ -620,7 +620,7 @@ bool cmCacheManager::CacheIterator::GetValueAsBool() const std::vector cmCacheManager::CacheEntry::GetPropertyList() const { - return this->Properties.GetPropertyList(); + return this->Properties.GetKeys(); } const char* cmCacheManager::CacheEntry::GetProperty( diff --git a/Source/cmGeneratorTarget.cxx b/Source/cmGeneratorTarget.cxx index 036a07d..de0f371 100644 --- a/Source/cmGeneratorTarget.cxx +++ b/Source/cmGeneratorTarget.cxx @@ -5032,13 +5032,7 @@ void cmGeneratorTarget::ComputeVersionedName(std::string& vName, std::vector cmGeneratorTarget::GetPropertyKeys() const { - cmPropertyMap const& propsObject = this->Target->GetProperties(); - std::vector props; - props.reserve(propsObject.size()); - for (auto const& it : propsObject) { - props.push_back(it.first); - } - return props; + return this->Target->GetProperties().GetKeys(); } void cmGeneratorTarget::ReportPropertyOrigin( diff --git a/Source/cmPropertyMap.cxx b/Source/cmPropertyMap.cxx index 3f6d7c8..a97e1f0 100644 --- a/Source/cmPropertyMap.cxx +++ b/Source/cmPropertyMap.cxx @@ -2,7 +2,6 @@ file Copyright.txt or https://cmake.org/licensing for details. */ #include "cmPropertyMap.h" -#include #include #include @@ -18,16 +17,6 @@ cmProperty* cmPropertyMap::GetOrCreateProperty(const std::string& name) return prop; } -std::vector cmPropertyMap::GetPropertyList() const -{ - std::vector keyList; - for (auto const& i : *this) { - keyList.push_back(i.first); - } - std::sort(keyList.begin(), keyList.end()); - return keyList; -} - void cmPropertyMap::SetProperty(const std::string& name, const char* value) { if (!value) { @@ -61,3 +50,13 @@ const char* cmPropertyMap::GetPropertyValue(const std::string& name) const } return it->second.GetValue(); } + +std::vector cmPropertyMap::GetKeys() const +{ + std::vector keyList; + keyList.reserve(this->size()); + for (auto const& item : *this) { + keyList.push_back(item.first); + } + return keyList; +} diff --git a/Source/cmPropertyMap.h b/Source/cmPropertyMap.h index 5a05150..5c93627 100644 --- a/Source/cmPropertyMap.h +++ b/Source/cmPropertyMap.h @@ -14,16 +14,19 @@ class cmPropertyMap : public std::map { public: + // -- Properties cmProperty* GetOrCreateProperty(const std::string& name); - std::vector GetPropertyList() const; - void SetProperty(const std::string& name, const char* value); void AppendProperty(const std::string& name, const char* value, bool asString = false); const char* GetPropertyValue(const std::string& name) const; + + // -- Lists + //! Get a sorted list of property keys + std::vector GetKeys() const; }; #endif diff --git a/Source/cmStateDirectory.cxx b/Source/cmStateDirectory.cxx index 182d3fe..6ca1c9f 100644 --- a/Source/cmStateDirectory.cxx +++ b/Source/cmStateDirectory.cxx @@ -6,7 +6,6 @@ #include #include #include -#include #include "cmAlgorithms.h" #include "cmProperty.h" @@ -667,12 +666,7 @@ bool cmStateDirectory::GetPropertyAsBool(const std::string& prop) const std::vector cmStateDirectory::GetPropertyKeys() const { - std::vector keys; - keys.reserve(this->DirectoryState->Properties.size()); - for (auto const& it : this->DirectoryState->Properties) { - keys.push_back(it.first); - } - return keys; + return this->DirectoryState->Properties.GetKeys(); } void cmStateDirectory::AddNormalTargetName(std::string const& name) -- cgit v0.12 From 026f65d284deaea9f2dba41ed956fabf84e17b6d Mon Sep 17 00:00:00 2001 From: Sebastian Holtermann Date: Sun, 2 Jun 2019 12:43:16 +0200 Subject: cmPropertyMap: Add GetList method --- Source/cmJsonObjects.cxx | 4 ++-- Source/cmPropertyMap.cxx | 10 ++++++++++ Source/cmPropertyMap.h | 4 ++++ Source/cmTestGenerator.cxx | 10 ++++------ 4 files changed, 20 insertions(+), 8 deletions(-) diff --git a/Source/cmJsonObjects.cxx b/Source/cmJsonObjects.cxx index 636a8e1..657d681 100644 --- a/Source/cmJsonObjects.cxx +++ b/Source/cmJsonObjects.cxx @@ -363,12 +363,12 @@ static Json::Value DumpCTestInfo(cmLocalGenerator* lg, cmTest* testInfo, // Build up the list of properties that may have been specified Json::Value properties = Json::arrayValue; - for (auto& prop : testInfo->GetProperties()) { + for (auto& prop : testInfo->GetProperties().GetList()) { Json::Value entry = Json::objectValue; entry[kKEY_KEY] = prop.first; // Remove config variables from the value too. - auto cge_value = ge.Parse(prop.second.GetValue()); + auto cge_value = ge.Parse(prop.second); const std::string& processed_value = cge_value->Evaluate(lg, config); entry[kVALUE_KEY] = processed_value; properties.append(entry); diff --git a/Source/cmPropertyMap.cxx b/Source/cmPropertyMap.cxx index a97e1f0..09b30ba 100644 --- a/Source/cmPropertyMap.cxx +++ b/Source/cmPropertyMap.cxx @@ -60,3 +60,13 @@ std::vector cmPropertyMap::GetKeys() const } return keyList; } + +std::vector> cmPropertyMap::GetList() const +{ + std::vector> kvList; + kvList.reserve(this->size()); + for (auto const& item : *this) { + kvList.emplace_back(item.first, item.second.GetValue()); + } + return kvList; +} diff --git a/Source/cmPropertyMap.h b/Source/cmPropertyMap.h index 5c93627..e2348a3 100644 --- a/Source/cmPropertyMap.h +++ b/Source/cmPropertyMap.h @@ -9,6 +9,7 @@ #include #include +#include #include class cmPropertyMap : public std::map @@ -27,6 +28,9 @@ public: // -- Lists //! Get a sorted list of property keys std::vector GetKeys() const; + + //! Get a sorted by key list of property key,value pairs + std::vector> GetList() const; }; #endif diff --git a/Source/cmTestGenerator.cxx b/Source/cmTestGenerator.cxx index 571cd09..3840e50 100644 --- a/Source/cmTestGenerator.cxx +++ b/Source/cmTestGenerator.cxx @@ -117,13 +117,12 @@ void cmTestGenerator::GenerateScriptForConfig(std::ostream& os, os << ")\n"; // Output properties for the test. - cmPropertyMap& pm = this->Test->GetProperties(); os << indent << "set_tests_properties(" << this->Test->GetName() << " PROPERTIES "; - for (auto const& i : pm) { + for (auto const& i : this->Test->GetProperties().GetList()) { os << " " << i.first << " " << cmOutputConverter::EscapeForCMake( - ge.Parse(i.second.GetValue())->Evaluate(this->LG, config)); + ge.Parse(i.second)->Evaluate(this->LG, config)); } this->GenerateInternalProperties(os); os << ")" << std::endl; @@ -173,12 +172,11 @@ void cmTestGenerator::GenerateOldStyle(std::ostream& fout, Indent indent) fout << ")" << std::endl; // Output properties for the test. - cmPropertyMap& pm = this->Test->GetProperties(); fout << indent << "set_tests_properties(" << this->Test->GetName() << " PROPERTIES "; - for (auto const& i : pm) { + for (auto const& i : this->Test->GetProperties().GetList()) { fout << " " << i.first << " " - << cmOutputConverter::EscapeForCMake(i.second.GetValue()); + << cmOutputConverter::EscapeForCMake(i.second); } this->GenerateInternalProperties(fout); fout << ")" << std::endl; -- cgit v0.12 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 From e0a8ff31480df672e42e2382e8ed7f33ea65afb4 Mon Sep 17 00:00:00 2001 From: Sebastian Holtermann Date: Mon, 3 Jun 2019 09:26:59 +0200 Subject: cmPropertyMap: Use std::string as value container class --- Source/CMakeLists.txt | 1 - Source/cmExportFileGenerator.cxx | 1 - Source/cmJsonObjects.cxx | 1 - Source/cmProperty.cxx | 26 -------------------------- Source/cmProperty.h | 18 ------------------ Source/cmPropertyMap.cxx | 14 ++++++++++---- Source/cmPropertyMap.h | 4 +--- Source/cmTestGenerator.cxx | 1 - bootstrap | 1 - 9 files changed, 11 insertions(+), 56 deletions(-) delete mode 100644 Source/cmProperty.cxx diff --git a/Source/CMakeLists.txt b/Source/CMakeLists.txt index 695e075..67bc598 100644 --- a/Source/CMakeLists.txt +++ b/Source/CMakeLists.txt @@ -338,7 +338,6 @@ set(SRCS cmProcessOutput.h cmProcessTools.cxx cmProcessTools.h - cmProperty.cxx cmProperty.h cmPropertyDefinition.cxx cmPropertyDefinition.h diff --git a/Source/cmExportFileGenerator.cxx b/Source/cmExportFileGenerator.cxx index 6621797..c366183 100644 --- a/Source/cmExportFileGenerator.cxx +++ b/Source/cmExportFileGenerator.cxx @@ -12,7 +12,6 @@ #include "cmMessageType.h" #include "cmOutputConverter.h" #include "cmPolicies.h" -#include "cmProperty.h" #include "cmPropertyMap.h" #include "cmStateTypes.h" #include "cmSystemTools.h" diff --git a/Source/cmJsonObjects.cxx b/Source/cmJsonObjects.cxx index 657d681..8d065e1 100644 --- a/Source/cmJsonObjects.cxx +++ b/Source/cmJsonObjects.cxx @@ -14,7 +14,6 @@ #include "cmLinkLineComputer.h" #include "cmLocalGenerator.h" #include "cmMakefile.h" -#include "cmProperty.h" #include "cmPropertyMap.h" #include "cmSourceFile.h" #include "cmState.h" diff --git a/Source/cmProperty.cxx b/Source/cmProperty.cxx deleted file mode 100644 index 27f0ecd..0000000 --- a/Source/cmProperty.cxx +++ /dev/null @@ -1,26 +0,0 @@ -/* Distributed under the OSI-approved BSD 3-Clause License. See accompanying - file Copyright.txt or https://cmake.org/licensing for details. */ -#include "cmProperty.h" - -void cmProperty::Set(const char* value) -{ - this->Value = value; - this->ValueHasBeenSet = true; -} - -void cmProperty::Append(const char* value, bool asString) -{ - if (!this->Value.empty() && *value && !asString) { - this->Value += ";"; - } - this->Value += value; - this->ValueHasBeenSet = true; -} - -const char* cmProperty::GetValue() const -{ - if (this->ValueHasBeenSet) { - return this->Value.c_str(); - } - return nullptr; -} diff --git a/Source/cmProperty.h b/Source/cmProperty.h index d11c5ef..80f131a 100644 --- a/Source/cmProperty.h +++ b/Source/cmProperty.h @@ -5,8 +5,6 @@ #include "cmConfigure.h" // IWYU pragma: keep -#include - class cmProperty { public: @@ -22,22 +20,6 @@ public: CACHED_VARIABLE, INSTALL }; - - // set this property - void Set(const char* value); - - // append to this property - void Append(const char* value, bool asString = false); - - // get the value - const char* GetValue() const; - - // construct with the value not set - cmProperty() { this->ValueHasBeenSet = false; } - -protected: - std::string Value; - bool ValueHasBeenSet; }; #endif diff --git a/Source/cmPropertyMap.cxx b/Source/cmPropertyMap.cxx index 7177a63..0874977 100644 --- a/Source/cmPropertyMap.cxx +++ b/Source/cmPropertyMap.cxx @@ -16,7 +16,7 @@ void cmPropertyMap::SetProperty(const std::string& name, const char* value) return; } - Map_[name].Set(value); + Map_[name] = value; } void cmPropertyMap::AppendProperty(const std::string& name, const char* value, @@ -27,7 +27,13 @@ void cmPropertyMap::AppendProperty(const std::string& name, const char* value, return; } - Map_[name].Append(value, asString); + { + std::string& pVal = Map_[name]; + if (!pVal.empty() && !asString) { + pVal += ';'; + } + pVal += value; + } } const char* cmPropertyMap::GetPropertyValue(const std::string& name) const @@ -35,7 +41,7 @@ const char* cmPropertyMap::GetPropertyValue(const std::string& name) const { auto it = Map_.find(name); if (it != Map_.end()) { - return it->second.GetValue(); + return it->second.c_str(); } } return nullptr; @@ -56,7 +62,7 @@ std::vector> cmPropertyMap::GetList() const std::vector> kvList; kvList.reserve(Map_.size()); for (auto const& item : Map_) { - kvList.emplace_back(item.first, item.second.GetValue()); + kvList.emplace_back(item.first, item.second); } return kvList; } diff --git a/Source/cmPropertyMap.h b/Source/cmPropertyMap.h index 4fcbf58..165eb92 100644 --- a/Source/cmPropertyMap.h +++ b/Source/cmPropertyMap.h @@ -5,8 +5,6 @@ #include "cmConfigure.h" // IWYU pragma: keep -#include "cmProperty.h" - #include #include #include @@ -35,7 +33,7 @@ public: std::vector> GetList() const; private: - std::map Map_; + std::map Map_; }; #endif diff --git a/Source/cmTestGenerator.cxx b/Source/cmTestGenerator.cxx index 3840e50..174fb8a 100644 --- a/Source/cmTestGenerator.cxx +++ b/Source/cmTestGenerator.cxx @@ -10,7 +10,6 @@ #include "cmListFileCache.h" #include "cmLocalGenerator.h" #include "cmOutputConverter.h" -#include "cmProperty.h" #include "cmPropertyMap.h" #include "cmRange.h" #include "cmStateTypes.h" diff --git a/bootstrap b/bootstrap index 38fa32b..569a6a4 100755 --- a/bootstrap +++ b/bootstrap @@ -388,7 +388,6 @@ CMAKE_CXX_SOURCES="\ cmPolicies \ cmProcessOutput \ cmProjectCommand \ - cmProperty \ cmPropertyDefinition \ cmPropertyDefinitionMap \ cmPropertyMap \ -- cgit v0.12 From 1b945f95bafc9a795b092904f7c6bd84dad940e8 Mon Sep 17 00:00:00 2001 From: Sebastian Holtermann Date: Mon, 3 Jun 2019 09:19:58 +0200 Subject: cmPropertyMap: Add RemoveProperty method The new `cmPropertyMap::RemoveProperty` allows to remove a property from the map. --- Source/cmPropertyMap.cxx | 5 +++++ Source/cmPropertyMap.h | 8 ++++++++ 2 files changed, 13 insertions(+) diff --git a/Source/cmPropertyMap.cxx b/Source/cmPropertyMap.cxx index 0874977..64bceb5 100644 --- a/Source/cmPropertyMap.cxx +++ b/Source/cmPropertyMap.cxx @@ -36,6 +36,11 @@ void cmPropertyMap::AppendProperty(const std::string& name, const char* value, } } +void cmPropertyMap::RemoveProperty(const std::string& name) +{ + Map_.erase(name); +} + const char* cmPropertyMap::GetPropertyValue(const std::string& name) const { { diff --git a/Source/cmPropertyMap.h b/Source/cmPropertyMap.h index 165eb92..6284e8c 100644 --- a/Source/cmPropertyMap.h +++ b/Source/cmPropertyMap.h @@ -14,17 +14,25 @@ class cmPropertyMap { public: // -- General + //! Clear property list void Clear(); // -- Properties + + //! Set the property value void SetProperty(const std::string& name, const char* value); + //! Append to the property value void AppendProperty(const std::string& name, const char* value, bool asString = false); + //! Get the property value const char* GetPropertyValue(const std::string& name) const; + //! Remove the property @a name from the map + void RemoveProperty(const std::string& name); + // -- Lists //! Get a sorted list of property keys std::vector GetKeys() const; -- cgit v0.12 From 00d265e3c812516e2a71faed4f352b36f51112e2 Mon Sep 17 00:00:00 2001 From: Sebastian Holtermann Date: Mon, 3 Jun 2019 10:29:12 +0200 Subject: cmPropertyMap: Use std::unordered_map as container instead of std::map --- Source/cmPropertyMap.cxx | 9 ++++++++- Source/cmPropertyMap.h | 8 ++++++-- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/Source/cmPropertyMap.cxx b/Source/cmPropertyMap.cxx index 64bceb5..3ed4c05 100644 --- a/Source/cmPropertyMap.cxx +++ b/Source/cmPropertyMap.cxx @@ -2,6 +2,7 @@ file Copyright.txt or https://cmake.org/licensing for details. */ #include "cmPropertyMap.h" +#include #include void cmPropertyMap::Clear() @@ -59,15 +60,21 @@ std::vector cmPropertyMap::GetKeys() const for (auto const& item : Map_) { keyList.push_back(item.first); } + std::sort(keyList.begin(), keyList.end()); return keyList; } std::vector> cmPropertyMap::GetList() const { - std::vector> kvList; + typedef std::pair StringPair; + std::vector kvList; kvList.reserve(Map_.size()); for (auto const& item : Map_) { kvList.emplace_back(item.first, item.second); } + std::sort(kvList.begin(), kvList.end(), + [](StringPair const& a, StringPair const& b) { + return a.first < b.first; + }); return kvList; } diff --git a/Source/cmPropertyMap.h b/Source/cmPropertyMap.h index 6284e8c..9aed349 100644 --- a/Source/cmPropertyMap.h +++ b/Source/cmPropertyMap.h @@ -5,11 +5,14 @@ #include "cmConfigure.h" // IWYU pragma: keep -#include #include +#include #include #include +/** \class cmPropertyMap + * \brief String property map. + */ class cmPropertyMap { public: @@ -34,6 +37,7 @@ public: void RemoveProperty(const std::string& name); // -- Lists + //! Get a sorted list of property keys std::vector GetKeys() const; @@ -41,7 +45,7 @@ public: std::vector> GetList() const; private: - std::map Map_; + std::unordered_map Map_; }; #endif -- cgit v0.12