You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

160 lines
4.2 KiB

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