cmSourceGroup.cxx 4.2 KB

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