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"
9 #include "cmStringAlgorithms.h"
11 class cmSourceGroupInternals
14 std::vector<cmSourceGroup> GroupChildren;
17 cmSourceGroup::cmSourceGroup(std::string name, const char* regex,
18 const char* parentName)
19 : Name(std::move(name))
21 this->Internal = cm::make_unique<cmSourceGroupInternals>();
22 this->SetGroupRegex(regex);
24 this->FullName = cmStrCat(parentName, '\\');
26 this->FullName += this->Name;
29 cmSourceGroup::~cmSourceGroup() = default;
31 cmSourceGroup::cmSourceGroup(cmSourceGroup const& r)
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);
41 cmSourceGroup& cmSourceGroup::operator=(cmSourceGroup const& r)
44 this->GroupRegex = r.GroupRegex;
45 this->GroupFiles = r.GroupFiles;
46 this->SourceFiles = r.SourceFiles;
47 *(this->Internal) = *(r.Internal);
51 void cmSourceGroup::SetGroupRegex(const char* regex)
54 this->GroupRegex.compile(regex);
56 this->GroupRegex.compile("^$");
60 void cmSourceGroup::AddGroupFile(const std::string& name)
62 this->GroupFiles.insert(name);
65 std::string const& cmSourceGroup::GetName() const
70 std::string const& cmSourceGroup::GetFullName() const
72 return this->FullName;
75 bool cmSourceGroup::MatchesRegex(const std::string& name)
77 return this->GroupRegex.find(name);
80 bool cmSourceGroup::MatchesFiles(const std::string& name) const
82 return this->GroupFiles.find(name) != this->GroupFiles.cend();
85 void cmSourceGroup::AssignSource(const cmSourceFile* sf)
87 this->SourceFiles.push_back(sf);
90 const std::vector<const cmSourceFile*>& cmSourceGroup::GetSourceFiles() const
92 return this->SourceFiles;
95 void cmSourceGroup::AddChild(cmSourceGroup const& child)
97 this->Internal->GroupChildren.push_back(child);
100 cmSourceGroup* cmSourceGroup::LookupChild(const std::string& name)
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
109 // if no child with this name was found return NULL
113 cmSourceGroup* cmSourceGroup::MatchChildrenFiles(const std::string& name)
115 if (this->MatchesFiles(name)) {
118 for (cmSourceGroup& group : this->Internal->GroupChildren) {
119 cmSourceGroup* result = group.MatchChildrenFiles(name);
127 const cmSourceGroup* cmSourceGroup::MatchChildrenFiles(
128 const std::string& name) const
130 if (this->MatchesFiles(name)) {
133 for (const cmSourceGroup& group : this->Internal->GroupChildren) {
134 const cmSourceGroup* result = group.MatchChildrenFiles(name);
142 cmSourceGroup* cmSourceGroup::MatchChildrenRegex(const std::string& name)
144 for (cmSourceGroup& group : this->Internal->GroupChildren) {
145 cmSourceGroup* result = group.MatchChildrenRegex(name);
150 if (this->MatchesRegex(name)) {
157 std::vector<cmSourceGroup> const& cmSourceGroup::GetGroupChildren() const
159 return this->Internal->GroupChildren;