cmPropertyMap.cxx 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. /*=========================================================================
  2. Program: CMake - Cross-Platform Makefile Generator
  3. Module: $RCSfile$
  4. Language: C++
  5. Date: $Date$
  6. Version: $Revision$
  7. Copyright (c) 2002 Kitware, Inc., Insight Consortium. All rights reserved.
  8. See Copyright.txt or http://www.cmake.org/HTML/Copyright.html for details.
  9. This software is distributed WITHOUT ANY WARRANTY; without even
  10. the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
  11. PURPOSE. See the above copyright notices for more information.
  12. =========================================================================*/
  13. #include "cmPropertyMap.h"
  14. #include "cmSystemTools.h"
  15. #include "cmake.h"
  16. cmProperty *cmPropertyMap::GetOrCreateProperty(const char *name)
  17. {
  18. cmPropertyMap::iterator it = this->find(name);
  19. cmProperty *prop;
  20. if (it == this->end())
  21. {
  22. prop = &(*this)[name];
  23. }
  24. else
  25. {
  26. prop = &(it->second);
  27. }
  28. return prop;
  29. }
  30. void cmPropertyMap::SetProperty(const char *name, const char *value,
  31. cmProperty::ScopeType scope)
  32. {
  33. if (!name)
  34. {
  35. return;
  36. }
  37. if(!value)
  38. {
  39. this->erase(name);
  40. return;
  41. }
  42. #ifdef CMAKE_STRICT
  43. if (!this->CMakeInstance)
  44. {
  45. cmSystemTools::Error("CMakeInstance not set on a property map!");
  46. abort();
  47. }
  48. else
  49. {
  50. this->CMakeInstance->RecordPropertyAccess(name,scope);
  51. }
  52. #else
  53. (void)scope;
  54. #endif
  55. cmProperty *prop = this->GetOrCreateProperty(name);
  56. prop->Set(name,value);
  57. }
  58. void cmPropertyMap::AppendProperty(const char* name, const char* value,
  59. cmProperty::ScopeType scope)
  60. {
  61. // Skip if nothing to append.
  62. if(!name || !value || !*value)
  63. {
  64. return;
  65. }
  66. #ifdef CMAKE_STRICT
  67. if (!this->CMakeInstance)
  68. {
  69. cmSystemTools::Error("CMakeInstance not set on a property map!");
  70. abort();
  71. }
  72. else
  73. {
  74. this->CMakeInstance->RecordPropertyAccess(name,scope);
  75. }
  76. #else
  77. (void)scope;
  78. #endif
  79. cmProperty *prop = this->GetOrCreateProperty(name);
  80. prop->Append(name,value);
  81. }
  82. const char *cmPropertyMap
  83. ::GetPropertyValue(const char *name,
  84. cmProperty::ScopeType scope,
  85. bool &chain) const
  86. {
  87. chain = false;
  88. if (!name)
  89. {
  90. return 0;
  91. }
  92. // has the property been defined?
  93. #ifdef CMAKE_STRICT
  94. if (!this->CMakeInstance)
  95. {
  96. cmSystemTools::Error("CMakeInstance not set on a property map!");
  97. abort();
  98. }
  99. else
  100. {
  101. this->CMakeInstance->RecordPropertyAccess(name,scope);
  102. }
  103. #endif
  104. cmPropertyMap::const_iterator it = this->find(name);
  105. if (it == this->end())
  106. {
  107. // should we chain up?
  108. if (this->CMakeInstance)
  109. {
  110. chain = this->CMakeInstance->IsPropertyChained(name,scope);
  111. }
  112. return 0;
  113. }
  114. return it->second.GetValue();
  115. }