cmPropertyMap.cxx 1.4 KB

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