cmPropertyMap.cxx 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. /*============================================================================
  2. CMake - Cross Platform Makefile Generator
  3. Copyright 2000-2009 Kitware, Inc., Insight Software Consortium
  4. Distributed under the OSI-approved BSD License (the "License");
  5. see accompanying file Copyright.txt for details.
  6. This software is distributed WITHOUT ANY WARRANTY; without even the
  7. implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  8. See the License for more information.
  9. ============================================================================*/
  10. #include "cmPropertyMap.h"
  11. #include "cmState.h"
  12. #include "cmSystemTools.h"
  13. #include "cmake.h"
  14. #include <algorithm>
  15. #include <assert.h>
  16. cmProperty* cmPropertyMap::GetOrCreateProperty(const std::string& name)
  17. {
  18. cmPropertyMap::iterator it = this->find(name);
  19. cmProperty* prop;
  20. if (it == this->end()) {
  21. prop = &(*this)[name];
  22. } else {
  23. prop = &(it->second);
  24. }
  25. return prop;
  26. }
  27. std::vector<std::string> cmPropertyMap::GetPropertyList() const
  28. {
  29. std::vector<std::string> keyList;
  30. for (cmPropertyMap::const_iterator i = this->begin(), e = this->end();
  31. i != e; ++i) {
  32. keyList.push_back(i->first);
  33. }
  34. std::sort(keyList.begin(), keyList.end());
  35. return keyList;
  36. }
  37. void cmPropertyMap::SetProperty(const std::string& name, const char* value)
  38. {
  39. if (!value) {
  40. this->erase(name);
  41. return;
  42. }
  43. cmProperty* prop = this->GetOrCreateProperty(name);
  44. prop->Set(value);
  45. }
  46. void cmPropertyMap::AppendProperty(const std::string& name, const char* value,
  47. bool asString)
  48. {
  49. // Skip if nothing to append.
  50. if (!value || !*value) {
  51. return;
  52. }
  53. cmProperty* prop = this->GetOrCreateProperty(name);
  54. prop->Append(value, asString);
  55. }
  56. const char* cmPropertyMap::GetPropertyValue(const std::string& name) const
  57. {
  58. assert(!name.empty());
  59. cmPropertyMap::const_iterator it = this->find(name);
  60. if (it == this->end()) {
  61. return 0;
  62. }
  63. return it->second.GetValue();
  64. }