diff options
author | Brad King <brad.king@kitware.com> | 2019-06-12 16:45:55 (GMT) |
---|---|---|
committer | Kitware Robot <kwrobot@kitware.com> | 2019-06-12 16:46:18 (GMT) |
commit | c1580ecc13cf2dea3f047d1018e705bd34cecc53 (patch) | |
tree | b157b069e557867bcc344bb4520d2e5ab2670279 /Source/cmPropertyMap.cxx | |
parent | 1af08229a7b871ea592cdf6d2aa41e47787eb713 (diff) | |
parent | 00d265e3c812516e2a71faed4f352b36f51112e2 (diff) | |
download | CMake-c1580ecc13cf2dea3f047d1018e705bd34cecc53.zip CMake-c1580ecc13cf2dea3f047d1018e705bd34cecc53.tar.gz CMake-c1580ecc13cf2dea3f047d1018e705bd34cecc53.tar.bz2 |
Merge topic 'cmPropertyMap_unordered_map'
00d265e3c8 cmPropertyMap: Use std::unordered_map as container instead of std::map
1b945f95ba cmPropertyMap: Add RemoveProperty method
e0a8ff3148 cmPropertyMap: Use std::string as value container class
8d934d861b cmPropertyMap: Make std::map container private
026f65d284 cmPropertyMap: Add GetList method
9e64e617eb cmPropertyMap: Rename GetPropertyList method to GetKeys
Acked-by: Kitware Robot <kwrobot@kitware.com>
Merge-request: !3435
Diffstat (limited to 'Source/cmPropertyMap.cxx')
-rw-r--r-- | Source/cmPropertyMap.cxx | 77 |
1 files changed, 47 insertions, 30 deletions
diff --git a/Source/cmPropertyMap.cxx b/Source/cmPropertyMap.cxx index 3f6d7c8..3ed4c05 100644 --- a/Source/cmPropertyMap.cxx +++ b/Source/cmPropertyMap.cxx @@ -3,40 +3,21 @@ #include "cmPropertyMap.h" #include <algorithm> -#include <assert.h> #include <utility> -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; -} - -std::vector<std::string> cmPropertyMap::GetPropertyList() const -{ - std::vector<std::string> keyList; - for (auto const& i : *this) { - keyList.push_back(i.first); - } - std::sort(keyList.begin(), keyList.end()); - return keyList; + 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] = value; } void cmPropertyMap::AppendProperty(const std::string& name, const char* value, @@ -47,17 +28,53 @@ void cmPropertyMap::AppendProperty(const std::string& name, const char* value, return; } - cmProperty* prop = this->GetOrCreateProperty(name); - prop->Append(value, asString); + { + std::string& pVal = Map_[name]; + if (!pVal.empty() && !asString) { + pVal += ';'; + } + pVal += value; + } +} + +void cmPropertyMap::RemoveProperty(const std::string& name) +{ + Map_.erase(name); } const char* cmPropertyMap::GetPropertyValue(const std::string& name) const { - assert(!name.empty()); + { + auto it = Map_.find(name); + if (it != Map_.end()) { + return it->second.c_str(); + } + } + return nullptr; +} - cmPropertyMap::const_iterator it = this->find(name); - if (it == this->end()) { - return nullptr; +std::vector<std::string> cmPropertyMap::GetKeys() const +{ + std::vector<std::string> keyList; + keyList.reserve(Map_.size()); + for (auto const& item : Map_) { + keyList.push_back(item.first); + } + std::sort(keyList.begin(), keyList.end()); + return keyList; +} + +std::vector<std::pair<std::string, std::string>> cmPropertyMap::GetList() const +{ + typedef std::pair<std::string, std::string> StringPair; + std::vector<StringPair> kvList; + kvList.reserve(Map_.size()); + for (auto const& item : Map_) { + kvList.emplace_back(item.first, item.second); } - return it->second.GetValue(); + std::sort(kvList.begin(), kvList.end(), + [](StringPair const& a, StringPair const& b) { + return a.first < b.first; + }); + return kvList; } |