cmPropertyMap.cxx 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  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, const char* value)
  11. {
  12. if (!value) {
  13. this->Map_.erase(name);
  14. return;
  15. }
  16. this->Map_[name] = value;
  17. }
  18. void cmPropertyMap::SetProperty(const std::string& name, cmProp value)
  19. {
  20. if (!value) {
  21. this->Map_.erase(name);
  22. return;
  23. }
  24. this->Map_[name] = *value;
  25. }
  26. void cmPropertyMap::AppendProperty(const std::string& name,
  27. const std::string& value, bool asString)
  28. {
  29. // Skip if nothing to append.
  30. if (value.empty()) {
  31. return;
  32. }
  33. {
  34. std::string& pVal = this->Map_[name];
  35. if (!pVal.empty() && !asString) {
  36. pVal += ';';
  37. }
  38. pVal += value;
  39. }
  40. }
  41. void cmPropertyMap::RemoveProperty(const std::string& name)
  42. {
  43. this->Map_.erase(name);
  44. }
  45. cmProp cmPropertyMap::GetPropertyValue(const std::string& name) const
  46. {
  47. auto it = this->Map_.find(name);
  48. if (it != this->Map_.end()) {
  49. return cmProp(it->second);
  50. }
  51. return nullptr;
  52. }
  53. std::vector<std::string> cmPropertyMap::GetKeys() const
  54. {
  55. std::vector<std::string> keyList;
  56. keyList.reserve(this->Map_.size());
  57. for (auto const& item : this->Map_) {
  58. keyList.push_back(item.first);
  59. }
  60. std::sort(keyList.begin(), keyList.end());
  61. return keyList;
  62. }
  63. std::vector<std::pair<std::string, std::string>> cmPropertyMap::GetList() const
  64. {
  65. using StringPair = std::pair<std::string, std::string>;
  66. std::vector<StringPair> kvList;
  67. kvList.reserve(this->Map_.size());
  68. for (auto const& item : this->Map_) {
  69. kvList.emplace_back(item.first, item.second);
  70. }
  71. std::sort(kvList.begin(), kvList.end(),
  72. [](StringPair const& a, StringPair const& b) {
  73. return a.first < b.first;
  74. });
  75. return kvList;
  76. }