cmake/Source/cmSourceGroup.cxx

178 lines
4.2 KiB
C++
Raw Normal View History

2009-10-04 10:30:41 +03:00
/*============================================================================
CMake - Cross Platform Makefile Generator
Copyright 2000-2009 Kitware, Inc., Insight Software Consortium
2009-10-04 10:30:41 +03:00
Distributed under the OSI-approved BSD License (the "License");
see accompanying file Copyright.txt for details.
2009-10-04 10:30:41 +03:00
This software is distributed WITHOUT ANY WARRANTY; without even the
implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the License for more information.
============================================================================*/
#include "cmSourceGroup.h"
class cmSourceGroupInternals
{
public:
std::vector<cmSourceGroup> GroupChildren;
};
2009-10-04 10:30:41 +03:00
cmSourceGroup::cmSourceGroup(const char* 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
const char* cmSourceGroup::GetName() const
{
return this->Name.c_str();
}
2009-10-04 10:30:41 +03:00
const char* cmSourceGroup::GetFullName() const
{
return this->FullName.c_str();
}
2013-03-16 19:13:01 +02:00
bool cmSourceGroup::MatchesRegex(const char* name)
{
return this->GroupRegex.find(name);
}
bool cmSourceGroup::MatchesFiles(const char* name)
{
2015-04-27 22:25:09 +02:00
std::set<std::string>::const_iterator i = this->GroupFiles.find(name);
2016-07-09 11:21:54 +02:00
if (i != this->GroupFiles.end()) {
return true;
2016-07-09 11:21:54 +02:00
}
return false;
}
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);
}
2016-07-09 11:21:54 +02:00
cmSourceGroup* cmSourceGroup::LookupChild(const char* name) const
{
// initializing iterators
2014-08-03 19:52:23 +02:00
std::vector<cmSourceGroup>::const_iterator iter =
this->Internal->GroupChildren.begin();
2014-08-03 19:52:23 +02:00
const std::vector<cmSourceGroup>::const_iterator end =
this->Internal->GroupChildren.end();
// st
2016-07-09 11:21:54 +02:00
for (; iter != end; ++iter) {
2013-03-16 19:13:01 +02:00
std::string sgName = iter->GetName();
// look if descenened is the one were looking for
2016-07-09 11:21:54 +02:00
if (sgName == name) {
2014-08-03 19:52:23 +02:00
return const_cast<cmSourceGroup*>(&(*iter)); // if it so return it
}
2016-07-09 11:21:54 +02:00
}
// if no child with this name was found return NULL
return NULL;
}
2016-07-09 11:21:54 +02:00
cmSourceGroup* cmSourceGroup::MatchChildrenFiles(const char* name)
{
// initializing iterators
std::vector<cmSourceGroup>::iterator iter =
this->Internal->GroupChildren.begin();
std::vector<cmSourceGroup>::iterator end =
this->Internal->GroupChildren.end();
2016-07-09 11:21:54 +02:00
if (this->MatchesFiles(name)) {
return this;
2016-07-09 11:21:54 +02:00
}
for (; iter != end; ++iter) {
cmSourceGroup* result = iter->MatchChildrenFiles(name);
if (result) {
return result;
}
2016-07-09 11:21:54 +02:00
}
return 0;
}
2016-07-09 11:21:54 +02:00
cmSourceGroup* cmSourceGroup::MatchChildrenRegex(const char* name)
{
// initializing iterators
std::vector<cmSourceGroup>::iterator iter =
this->Internal->GroupChildren.begin();
std::vector<cmSourceGroup>::iterator end =
this->Internal->GroupChildren.end();
2016-07-09 11:21:54 +02:00
for (; iter != end; ++iter) {
cmSourceGroup* result = iter->MatchChildrenRegex(name);
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
return 0;
}
2016-07-09 11:21:54 +02:00
std::vector<cmSourceGroup> const& cmSourceGroup::GetGroupChildren() const
{
return this->Internal->GroupChildren;
}