cmPropertyMap.cxx 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  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 "cmSystemTools.h"
  12. #include "cmake.h"
  13. cmProperty *cmPropertyMap::GetOrCreateProperty(const char *name)
  14. {
  15. cmPropertyMap::iterator it = this->find(name);
  16. cmProperty *prop;
  17. if (it == this->end())
  18. {
  19. prop = &(*this)[name];
  20. }
  21. else
  22. {
  23. prop = &(it->second);
  24. }
  25. return prop;
  26. }
  27. void cmPropertyMap::SetProperty(const char *name, const char *value,
  28. cmProperty::ScopeType scope)
  29. {
  30. if (!name)
  31. {
  32. return;
  33. }
  34. if(!value)
  35. {
  36. this->erase(name);
  37. return;
  38. }
  39. #ifdef CMAKE_STRICT
  40. if (!this->CMakeInstance)
  41. {
  42. cmSystemTools::Error("CMakeInstance not set on a property map!");
  43. abort();
  44. }
  45. else
  46. {
  47. this->CMakeInstance->RecordPropertyAccess(name,scope);
  48. }
  49. #else
  50. (void)scope;
  51. #endif
  52. cmProperty *prop = this->GetOrCreateProperty(name);
  53. prop->Set(name,value);
  54. }
  55. void cmPropertyMap::AppendProperty(const char* name, const char* value,
  56. cmProperty::ScopeType scope)
  57. {
  58. // Skip if nothing to append.
  59. if(!name || !value || !*value)
  60. {
  61. return;
  62. }
  63. #ifdef CMAKE_STRICT
  64. if (!this->CMakeInstance)
  65. {
  66. cmSystemTools::Error("CMakeInstance not set on a property map!");
  67. abort();
  68. }
  69. else
  70. {
  71. this->CMakeInstance->RecordPropertyAccess(name,scope);
  72. }
  73. #else
  74. (void)scope;
  75. #endif
  76. cmProperty *prop = this->GetOrCreateProperty(name);
  77. prop->Append(name,value);
  78. }
  79. const char *cmPropertyMap
  80. ::GetPropertyValue(const char *name,
  81. cmProperty::ScopeType scope,
  82. bool &chain) const
  83. {
  84. chain = false;
  85. if (!name)
  86. {
  87. return 0;
  88. }
  89. // has the property been defined?
  90. #ifdef CMAKE_STRICT
  91. if (!this->CMakeInstance)
  92. {
  93. cmSystemTools::Error("CMakeInstance not set on a property map!");
  94. abort();
  95. }
  96. else
  97. {
  98. this->CMakeInstance->RecordPropertyAccess(name,scope);
  99. }
  100. #endif
  101. cmPropertyMap::const_iterator it = this->find(name);
  102. if (it == this->end())
  103. {
  104. // should we chain up?
  105. if (this->CMakeInstance)
  106. {
  107. chain = this->CMakeInstance->IsPropertyChained(name,scope);
  108. }
  109. return 0;
  110. }
  111. return it->second.GetValue();
  112. }