cmSourceGroup.cxx 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  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 std::string& 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 std::string& name)
  64. {
  65. return this->GroupRegex.find(name);
  66. }
  67. bool cmSourceGroup::MatchesFiles(const std::string& name) const
  68. {
  69. return this->GroupFiles.find(name) != this->GroupFiles.cend();
  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 std::string& name)
  84. {
  85. for (cmSourceGroup& group : this->Internal->GroupChildren) {
  86. // look if descenened is the one were looking for
  87. if (group.GetName() == name) {
  88. return (&group); // if it so return it
  89. }
  90. }
  91. // if no child with this name was found return NULL
  92. return nullptr;
  93. }
  94. cmSourceGroup* cmSourceGroup::MatchChildrenFiles(const std::string& name)
  95. {
  96. if (this->MatchesFiles(name)) {
  97. return this;
  98. }
  99. for (cmSourceGroup& group : this->Internal->GroupChildren) {
  100. cmSourceGroup* result = group.MatchChildrenFiles(name);
  101. if (result) {
  102. return result;
  103. }
  104. }
  105. return nullptr;
  106. }
  107. cmSourceGroup* cmSourceGroup::MatchChildrenRegex(const std::string& name)
  108. {
  109. for (cmSourceGroup& group : this->Internal->GroupChildren) {
  110. cmSourceGroup* result = group.MatchChildrenRegex(name);
  111. if (result) {
  112. return result;
  113. }
  114. }
  115. if (this->MatchesRegex(name)) {
  116. return this;
  117. }
  118. return nullptr;
  119. }
  120. std::vector<cmSourceGroup> const& cmSourceGroup::GetGroupChildren() const
  121. {
  122. return this->Internal->GroupChildren;
  123. }