cmSourceGroup.cxx 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  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 "cmSourceGroup.h"
  11. class cmSourceGroupInternals
  12. {
  13. public:
  14. std::vector<cmSourceGroup> GroupChildren;
  15. };
  16. cmSourceGroup::cmSourceGroup(const char* name, const char* regex,
  17. const char* parentName)
  18. : Name(name)
  19. {
  20. this->Internal = new cmSourceGroupInternals;
  21. this->SetGroupRegex(regex);
  22. if (parentName) {
  23. this->FullName = parentName;
  24. this->FullName += "\\";
  25. }
  26. this->FullName += this->Name;
  27. }
  28. cmSourceGroup::~cmSourceGroup()
  29. {
  30. delete this->Internal;
  31. }
  32. cmSourceGroup::cmSourceGroup(cmSourceGroup const& r)
  33. {
  34. this->Name = r.Name;
  35. this->FullName = r.FullName;
  36. this->GroupRegex = r.GroupRegex;
  37. this->GroupFiles = r.GroupFiles;
  38. this->SourceFiles = r.SourceFiles;
  39. this->Internal = new cmSourceGroupInternals(*r.Internal);
  40. }
  41. cmSourceGroup& cmSourceGroup::operator=(cmSourceGroup const& r)
  42. {
  43. this->Name = r.Name;
  44. this->GroupRegex = r.GroupRegex;
  45. this->GroupFiles = r.GroupFiles;
  46. this->SourceFiles = r.SourceFiles;
  47. *(this->Internal) = *(r.Internal);
  48. return *this;
  49. }
  50. void cmSourceGroup::SetGroupRegex(const char* regex)
  51. {
  52. if (regex) {
  53. this->GroupRegex.compile(regex);
  54. } else {
  55. this->GroupRegex.compile("^$");
  56. }
  57. }
  58. void cmSourceGroup::AddGroupFile(const std::string& name)
  59. {
  60. this->GroupFiles.insert(name);
  61. }
  62. const char* cmSourceGroup::GetName() const
  63. {
  64. return this->Name.c_str();
  65. }
  66. const char* cmSourceGroup::GetFullName() const
  67. {
  68. return this->FullName.c_str();
  69. }
  70. bool cmSourceGroup::MatchesRegex(const char* name)
  71. {
  72. return this->GroupRegex.find(name);
  73. }
  74. bool cmSourceGroup::MatchesFiles(const char* name)
  75. {
  76. std::set<std::string>::const_iterator i = this->GroupFiles.find(name);
  77. if (i != this->GroupFiles.end()) {
  78. return true;
  79. }
  80. return false;
  81. }
  82. void cmSourceGroup::AssignSource(const cmSourceFile* sf)
  83. {
  84. this->SourceFiles.push_back(sf);
  85. }
  86. const std::vector<const cmSourceFile*>& cmSourceGroup::GetSourceFiles() const
  87. {
  88. return this->SourceFiles;
  89. }
  90. void cmSourceGroup::AddChild(cmSourceGroup const& child)
  91. {
  92. this->Internal->GroupChildren.push_back(child);
  93. }
  94. cmSourceGroup* cmSourceGroup::LookupChild(const char* name) const
  95. {
  96. // initializing iterators
  97. std::vector<cmSourceGroup>::const_iterator iter =
  98. this->Internal->GroupChildren.begin();
  99. const std::vector<cmSourceGroup>::const_iterator end =
  100. this->Internal->GroupChildren.end();
  101. // st
  102. for (; iter != end; ++iter) {
  103. std::string sgName = iter->GetName();
  104. // look if descenened is the one were looking for
  105. if (sgName == name) {
  106. return const_cast<cmSourceGroup*>(&(*iter)); // if it so return it
  107. }
  108. }
  109. // if no child with this name was found return NULL
  110. return NULL;
  111. }
  112. cmSourceGroup* cmSourceGroup::MatchChildrenFiles(const char* name)
  113. {
  114. // initializing iterators
  115. std::vector<cmSourceGroup>::iterator iter =
  116. this->Internal->GroupChildren.begin();
  117. std::vector<cmSourceGroup>::iterator end =
  118. this->Internal->GroupChildren.end();
  119. if (this->MatchesFiles(name)) {
  120. return this;
  121. }
  122. for (; iter != end; ++iter) {
  123. cmSourceGroup* result = iter->MatchChildrenFiles(name);
  124. if (result) {
  125. return result;
  126. }
  127. }
  128. return 0;
  129. }
  130. cmSourceGroup* cmSourceGroup::MatchChildrenRegex(const char* name)
  131. {
  132. // initializing iterators
  133. std::vector<cmSourceGroup>::iterator iter =
  134. this->Internal->GroupChildren.begin();
  135. std::vector<cmSourceGroup>::iterator end =
  136. this->Internal->GroupChildren.end();
  137. for (; iter != end; ++iter) {
  138. cmSourceGroup* result = iter->MatchChildrenRegex(name);
  139. if (result) {
  140. return result;
  141. }
  142. }
  143. if (this->MatchesRegex(name)) {
  144. return this;
  145. }
  146. return 0;
  147. }
  148. std::vector<cmSourceGroup> const& cmSourceGroup::GetGroupChildren() const
  149. {
  150. return this->Internal->GroupChildren;
  151. }