cmPropertyMap.cxx 1.8 KB

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