cmSourceGroup.cxx 5.5 KB

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