cmPropertyMap.cxx 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  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 <assert.h>
  5. #include <utility>
  6. cmProperty* cmPropertyMap::GetOrCreateProperty(const std::string& name)
  7. {
  8. cmPropertyMap::iterator it = this->find(name);
  9. cmProperty* prop;
  10. if (it == this->end()) {
  11. prop = &(*this)[name];
  12. } else {
  13. prop = &(it->second);
  14. }
  15. return prop;
  16. }
  17. void cmPropertyMap::SetProperty(const std::string& name, const char* value)
  18. {
  19. if (!value) {
  20. this->erase(name);
  21. return;
  22. }
  23. cmProperty* prop = this->GetOrCreateProperty(name);
  24. prop->Set(value);
  25. }
  26. void cmPropertyMap::AppendProperty(const std::string& name, const char* value,
  27. bool asString)
  28. {
  29. // Skip if nothing to append.
  30. if (!value || !*value) {
  31. return;
  32. }
  33. cmProperty* prop = this->GetOrCreateProperty(name);
  34. prop->Append(value, asString);
  35. }
  36. const char* cmPropertyMap::GetPropertyValue(const std::string& name) const
  37. {
  38. assert(!name.empty());
  39. cmPropertyMap::const_iterator it = this->find(name);
  40. if (it == this->end()) {
  41. return nullptr;
  42. }
  43. return it->second.GetValue();
  44. }
  45. std::vector<std::string> cmPropertyMap::GetKeys() const
  46. {
  47. std::vector<std::string> keyList;
  48. keyList.reserve(this->size());
  49. for (auto const& item : *this) {
  50. keyList.push_back(item.first);
  51. }
  52. return keyList;
  53. }
  54. std::vector<std::pair<std::string, std::string>> cmPropertyMap::GetList() const
  55. {
  56. std::vector<std::pair<std::string, std::string>> kvList;
  57. kvList.reserve(this->size());
  58. for (auto const& item : *this) {
  59. kvList.emplace_back(item.first, item.second.GetValue());
  60. }
  61. return kvList;
  62. }