cmSourceGroup.cxx 5.2 KB

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