cmake/Source/cmSourceGroup.cxx

144 lines
3.2 KiB
C++
Raw Normal View History

2016-10-30 18:24:19 +01:00
/* Distributed under the OSI-approved BSD 3-Clause License. See accompanying
file Copyright.txt or https://cmake.org/licensing for details. */
#include "cmSourceGroup.h"
class cmSourceGroupInternals
{
public:
std::vector<cmSourceGroup> GroupChildren;
};
2018-04-23 21:13:27 +02:00
cmSourceGroup::cmSourceGroup(const std::string& name, const char* regex,
2016-07-09 11:21:54 +02:00
const char* parentName)
: Name(name)
{
this->Internal = new cmSourceGroupInternals;
this->SetGroupRegex(regex);
2016-07-09 11:21:54 +02:00
if (parentName) {
2009-10-04 10:30:41 +03:00
this->FullName = parentName;
this->FullName += "\\";
2016-07-09 11:21:54 +02:00
}
2009-10-04 10:30:41 +03:00
this->FullName += this->Name;
}
cmSourceGroup::~cmSourceGroup()
{
delete this->Internal;
}
cmSourceGroup::cmSourceGroup(cmSourceGroup const& r)
{
this->Name = r.Name;
2009-10-04 10:30:41 +03:00
this->FullName = r.FullName;
this->GroupRegex = r.GroupRegex;
this->GroupFiles = r.GroupFiles;
this->SourceFiles = r.SourceFiles;
this->Internal = new cmSourceGroupInternals(*r.Internal);
}
cmSourceGroup& cmSourceGroup::operator=(cmSourceGroup const& r)
{
this->Name = r.Name;
this->GroupRegex = r.GroupRegex;
this->GroupFiles = r.GroupFiles;
this->SourceFiles = r.SourceFiles;
*(this->Internal) = *(r.Internal);
return *this;
}
void cmSourceGroup::SetGroupRegex(const char* regex)
{
2016-07-09 11:21:54 +02:00
if (regex) {
this->GroupRegex.compile(regex);
2016-07-09 11:21:54 +02:00
} else {
this->GroupRegex.compile("^$");
2016-07-09 11:21:54 +02:00
}
}
2013-03-16 19:13:01 +02:00
2015-04-27 22:25:09 +02:00
void cmSourceGroup::AddGroupFile(const std::string& name)
{
this->GroupFiles.insert(name);
}
2013-03-16 19:13:01 +02:00
2018-04-23 21:13:27 +02:00
std::string const& cmSourceGroup::GetName() const
{
2018-04-23 21:13:27 +02:00
return this->Name;
}
2009-10-04 10:30:41 +03:00
2018-04-23 21:13:27 +02:00
std::string const& cmSourceGroup::GetFullName() const
2009-10-04 10:30:41 +03:00
{
2018-04-23 21:13:27 +02:00
return this->FullName;
2009-10-04 10:30:41 +03:00
}
2013-03-16 19:13:01 +02:00
2018-04-23 21:13:27 +02:00
bool cmSourceGroup::MatchesRegex(const std::string& name)
{
return this->GroupRegex.find(name);
}
2018-04-23 21:13:27 +02:00
bool cmSourceGroup::MatchesFiles(const std::string& name) const
{
2018-04-23 21:13:27 +02:00
return this->GroupFiles.find(name) != this->GroupFiles.cend();
}
void cmSourceGroup::AssignSource(const cmSourceFile* sf)
{
this->SourceFiles.push_back(sf);
}
const std::vector<const cmSourceFile*>& cmSourceGroup::GetSourceFiles() const
{
return this->SourceFiles;
}
2016-07-09 11:21:54 +02:00
void cmSourceGroup::AddChild(cmSourceGroup const& child)
{
this->Internal->GroupChildren.push_back(child);
}
2018-04-23 21:13:27 +02:00
cmSourceGroup* cmSourceGroup::LookupChild(const std::string& name)
{
2018-04-23 21:13:27 +02:00
for (cmSourceGroup& group : this->Internal->GroupChildren) {
// look if descenened is the one were looking for
2018-04-23 21:13:27 +02:00
if (group.GetName() == name) {
return (&group); // if it so return it
}
2016-07-09 11:21:54 +02:00
}
// if no child with this name was found return NULL
2018-01-26 17:06:56 +01:00
return nullptr;
}
2018-04-23 21:13:27 +02:00
cmSourceGroup* cmSourceGroup::MatchChildrenFiles(const std::string& name)
{
2016-07-09 11:21:54 +02:00
if (this->MatchesFiles(name)) {
return this;
2016-07-09 11:21:54 +02:00
}
2018-04-23 21:13:27 +02:00
for (cmSourceGroup& group : this->Internal->GroupChildren) {
cmSourceGroup* result = group.MatchChildrenFiles(name);
2016-07-09 11:21:54 +02:00
if (result) {
return result;
}
2016-07-09 11:21:54 +02:00
}
2018-01-26 17:06:56 +01:00
return nullptr;
}
2018-04-23 21:13:27 +02:00
cmSourceGroup* cmSourceGroup::MatchChildrenRegex(const std::string& name)
{
2018-04-23 21:13:27 +02:00
for (cmSourceGroup& group : this->Internal->GroupChildren) {
cmSourceGroup* result = group.MatchChildrenRegex(name);
2016-07-09 11:21:54 +02:00
if (result) {
return result;
}
2016-07-09 11:21:54 +02:00
}
if (this->MatchesRegex(name)) {
2013-03-16 19:13:01 +02:00
return this;
2016-07-09 11:21:54 +02:00
}
2013-03-16 19:13:01 +02:00
2018-01-26 17:06:56 +01:00
return nullptr;
}
2016-07-09 11:21:54 +02:00
std::vector<cmSourceGroup> const& cmSourceGroup::GetGroupChildren() const
{
return this->Internal->GroupChildren;
}