cmPropertyMap.cxx 1.7 KB

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