cmSourceGroup.cxx 3.8 KB

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