cmake/Source/cmSourceGroup.cxx

161 lines
3.6 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"
2019-11-11 23:01:05 +01:00
#include <utility>
2020-08-30 11:54:41 +02:00
#include <cm/memory>
2020-02-01 23:06:01 +01:00
#include "cmStringAlgorithms.h"
class cmSourceGroupInternals
{
public:
std::vector<cmSourceGroup> GroupChildren;
};
2019-11-11 23:01:05 +01:00
cmSourceGroup::cmSourceGroup(std::string name, const char* regex,
2016-07-09 11:21:54 +02:00
const char* parentName)
2019-11-11 23:01:05 +01:00
: Name(std::move(name))
{
2020-08-30 11:54:41 +02:00
this->Internal = cm::make_unique<cmSourceGroupInternals>();
this->SetGroupRegex(regex);
2016-07-09 11:21:54 +02:00
if (parentName) {
2020-02-01 23:06:01 +01:00
this->FullName = cmStrCat(parentName, '\\');
2016-07-09 11:21:54 +02:00
}
2009-10-04 10:30:41 +03:00
this->FullName += this->Name;
}
2020-08-30 11:54:41 +02:00
cmSourceGroup::~cmSourceGroup() = default;
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;
2020-08-30 11:54:41 +02:00
this->Internal = cm::make_unique<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;
}
2022-09-13 21:35:23 +02:00
const cmSourceGroup* cmSourceGroup::MatchChildrenFiles(
const std::string& name) const
{
if (this->MatchesFiles(name)) {
return this;
}
for (const cmSourceGroup& group : this->Internal->GroupChildren) {
const cmSourceGroup* result = group.MatchChildrenFiles(name);
if (result) {
return result;
}
}
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;
}