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