cmSourceGroup.cxx 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  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. #include <utility>
  5. #include <cm/memory>
  6. #include "cmStringAlgorithms.h"
  7. class cmSourceGroupInternals
  8. {
  9. public:
  10. std::vector<cmSourceGroup> GroupChildren;
  11. };
  12. cmSourceGroup::cmSourceGroup(std::string name, const char* regex,
  13. const char* parentName)
  14. : Name(std::move(name))
  15. {
  16. this->Internal = cm::make_unique<cmSourceGroupInternals>();
  17. this->SetGroupRegex(regex);
  18. if (parentName) {
  19. this->FullName = cmStrCat(parentName, '\\');
  20. }
  21. this->FullName += this->Name;
  22. }
  23. cmSourceGroup::~cmSourceGroup() = default;
  24. cmSourceGroup::cmSourceGroup(cmSourceGroup const& r)
  25. {
  26. this->Name = r.Name;
  27. this->FullName = r.FullName;
  28. this->GroupRegex = r.GroupRegex;
  29. this->GroupFiles = r.GroupFiles;
  30. this->SourceFiles = r.SourceFiles;
  31. this->Internal = cm::make_unique<cmSourceGroupInternals>(*r.Internal);
  32. }
  33. cmSourceGroup& cmSourceGroup::operator=(cmSourceGroup const& r)
  34. {
  35. this->Name = r.Name;
  36. this->GroupRegex = r.GroupRegex;
  37. this->GroupFiles = r.GroupFiles;
  38. this->SourceFiles = r.SourceFiles;
  39. *(this->Internal) = *(r.Internal);
  40. return *this;
  41. }
  42. void cmSourceGroup::SetGroupRegex(const char* regex)
  43. {
  44. if (regex) {
  45. this->GroupRegex.compile(regex);
  46. } else {
  47. this->GroupRegex.compile("^$");
  48. }
  49. }
  50. void cmSourceGroup::AddGroupFile(const std::string& name)
  51. {
  52. this->GroupFiles.insert(name);
  53. }
  54. std::string const& cmSourceGroup::GetName() const
  55. {
  56. return this->Name;
  57. }
  58. std::string const& cmSourceGroup::GetFullName() const
  59. {
  60. return this->FullName;
  61. }
  62. bool cmSourceGroup::MatchesRegex(const std::string& name)
  63. {
  64. return this->GroupRegex.find(name);
  65. }
  66. bool cmSourceGroup::MatchesFiles(const std::string& name) const
  67. {
  68. return this->GroupFiles.find(name) != this->GroupFiles.cend();
  69. }
  70. void cmSourceGroup::AssignSource(const cmSourceFile* sf)
  71. {
  72. this->SourceFiles.push_back(sf);
  73. }
  74. const std::vector<const cmSourceFile*>& cmSourceGroup::GetSourceFiles() const
  75. {
  76. return this->SourceFiles;
  77. }
  78. void cmSourceGroup::AddChild(cmSourceGroup const& child)
  79. {
  80. this->Internal->GroupChildren.push_back(child);
  81. }
  82. cmSourceGroup* cmSourceGroup::LookupChild(const std::string& name)
  83. {
  84. for (cmSourceGroup& group : this->Internal->GroupChildren) {
  85. // look if descenened is the one were looking for
  86. if (group.GetName() == name) {
  87. return (&group); // if it so return it
  88. }
  89. }
  90. // if no child with this name was found return NULL
  91. return nullptr;
  92. }
  93. cmSourceGroup* cmSourceGroup::MatchChildrenFiles(const std::string& name)
  94. {
  95. if (this->MatchesFiles(name)) {
  96. return this;
  97. }
  98. for (cmSourceGroup& group : this->Internal->GroupChildren) {
  99. cmSourceGroup* result = group.MatchChildrenFiles(name);
  100. if (result) {
  101. return result;
  102. }
  103. }
  104. return nullptr;
  105. }
  106. cmSourceGroup* cmSourceGroup::MatchChildrenRegex(const std::string& name)
  107. {
  108. for (cmSourceGroup& group : this->Internal->GroupChildren) {
  109. cmSourceGroup* result = group.MatchChildrenRegex(name);
  110. if (result) {
  111. return result;
  112. }
  113. }
  114. if (this->MatchesRegex(name)) {
  115. return this;
  116. }
  117. return nullptr;
  118. }
  119. std::vector<cmSourceGroup> const& cmSourceGroup::GetGroupChildren() const
  120. {
  121. return this->Internal->GroupChildren;
  122. }