cmPropertyMap.cxx 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. /* Distributed under the OSI-approved BSD 3-Clause License. See accompanying
  2. file Copyright.txt or https://cmake.org/licensing for details. */
  3. #include "cmPropertyMap.h"
  4. #include <algorithm>
  5. #include <utility>
  6. void cmPropertyMap::Clear()
  7. {
  8. this->Map_.clear();
  9. }
  10. void cmPropertyMap::SetProperty(const std::string& name, std::nullptr_t)
  11. {
  12. this->Map_.erase(name);
  13. }
  14. void cmPropertyMap::SetProperty(const std::string& name, cmValue value)
  15. {
  16. if (!value) {
  17. this->Map_.erase(name);
  18. return;
  19. }
  20. this->Map_[name] = *value;
  21. }
  22. void cmPropertyMap::AppendProperty(const std::string& name,
  23. const std::string& value, bool asString)
  24. {
  25. // Skip if nothing to append.
  26. if (value.empty()) {
  27. return;
  28. }
  29. {
  30. std::string& pVal = this->Map_[name];
  31. if (!pVal.empty() && !asString) {
  32. pVal += ';';
  33. }
  34. pVal += value;
  35. }
  36. }
  37. void cmPropertyMap::RemoveProperty(const std::string& name)
  38. {
  39. this->Map_.erase(name);
  40. }
  41. cmValue cmPropertyMap::GetPropertyValue(const std::string& name) const
  42. {
  43. auto it = this->Map_.find(name);
  44. if (it != this->Map_.end()) {
  45. return cmValue(it->second);
  46. }
  47. return nullptr;
  48. }
  49. std::vector<std::string> cmPropertyMap::GetKeys() const
  50. {
  51. std::vector<std::string> keyList;
  52. keyList.reserve(this->Map_.size());
  53. for (auto const& item : this->Map_) {
  54. keyList.push_back(item.first);
  55. }
  56. std::sort(keyList.begin(), keyList.end());
  57. return keyList;
  58. }
  59. std::vector<std::pair<std::string, std::string>> cmPropertyMap::GetList() const
  60. {
  61. using StringPair = std::pair<std::string, std::string>;
  62. std::vector<StringPair> kvList;
  63. kvList.reserve(this->Map_.size());
  64. for (auto const& item : this->Map_) {
  65. kvList.emplace_back(item.first, item.second);
  66. }
  67. std::sort(kvList.begin(), kvList.end(),
  68. [](StringPair const& a, StringPair const& b) {
  69. return a.first < b.first;
  70. });
  71. return kvList;
  72. }