cmSourceGroup.cxx 3.23 KB
Newer Older
1 2
/* Distributed under the OSI-approved BSD 3-Clause License.  See accompanying
   file Copyright.txt or https://cmake.org/licensing for details.  */
3 4
#include "cmSourceGroup.h"

wahikihiki's avatar
wahikihiki committed
5 6
#include <utility>

7 8 9 10 11 12
class cmSourceGroupInternals
{
public:
  std::vector<cmSourceGroup> GroupChildren;
};

wahikihiki's avatar
wahikihiki committed
13
cmSourceGroup::cmSourceGroup(std::string name, const char* regex,
14
                             const char* parentName)
wahikihiki's avatar
wahikihiki committed
15
  : Name(std::move(name))
16
{
17
  this->Internal = new cmSourceGroupInternals;
18
  this->SetGroupRegex(regex);
19
  if (parentName) {
20 21
    this->FullName = parentName;
    this->FullName += "\\";
22
  }
23
  this->FullName += this->Name;
24 25
}

26 27 28 29 30 31 32 33
cmSourceGroup::~cmSourceGroup()
{
  delete this->Internal;
}

cmSourceGroup::cmSourceGroup(cmSourceGroup const& r)
{
  this->Name = r.Name;
34
  this->FullName = r.FullName;
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50
  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;
}

51
void cmSourceGroup::SetGroupRegex(const char* regex)
52
{
53
  if (regex) {
54
    this->GroupRegex.compile(regex);
55
  } else {
56
    this->GroupRegex.compile("^$");
57
  }
58
}
59

60
void cmSourceGroup::AddGroupFile(const std::string& name)
61
{
62
  this->GroupFiles.insert(name);
63
}
64

65
std::string const& cmSourceGroup::GetName() const
66
{
67
  return this->Name;
68
}
69

70
std::string const& cmSourceGroup::GetFullName() const
71
{
72
  return this->FullName;
73
}
74

75
bool cmSourceGroup::MatchesRegex(const std::string& name)
76
{
77
  return this->GroupRegex.find(name);
78 79
}

80
bool cmSourceGroup::MatchesFiles(const std::string& name) const
81
{
82
  return this->GroupFiles.find(name) != this->GroupFiles.cend();
83
}
84

85
void cmSourceGroup::AssignSource(const cmSourceFile* sf)
86
{
87
  this->SourceFiles.push_back(sf);
88 89
}

90 91
const std::vector<const cmSourceFile*>& cmSourceGroup::GetSourceFiles() const
{
92
  return this->SourceFiles;
93 94
}

95
void cmSourceGroup::AddChild(cmSourceGroup const& child)
96
{
97
  this->Internal->GroupChildren.push_back(child);
98 99
}

100
cmSourceGroup* 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 105
    if (group.GetName() == name) {
      return (&group); // if it so return it
106
    }
107
  }
108 109

  // if no child with this name was found return NULL
Daniel Pfeifer's avatar
Daniel Pfeifer committed
110
  return nullptr;
111 112
}

113
cmSourceGroup* cmSourceGroup::MatchChildrenFiles(const std::string& name)
114
{
115
  if (this->MatchesFiles(name)) {
116
    return this;
117
  }
118 119
  for (cmSourceGroup& group : this->Internal->GroupChildren) {
    cmSourceGroup* result = group.MatchChildrenFiles(name);
120
    if (result) {
121 122
      return result;
    }
123
  }
Daniel Pfeifer's avatar
Daniel Pfeifer committed
124
  return nullptr;
125 126
}

127
cmSourceGroup* cmSourceGroup::MatchChildrenRegex(const std::string& name)
128
{
129 130
  for (cmSourceGroup& group : this->Internal->GroupChildren) {
    cmSourceGroup* result = group.MatchChildrenRegex(name);
131
    if (result) {
132 133
      return result;
    }
134 135
  }
  if (this->MatchesRegex(name)) {
136
    return this;
137
  }
138

Daniel Pfeifer's avatar
Daniel Pfeifer committed
139
  return nullptr;
140 141
}

142
std::vector<cmSourceGroup> const& cmSourceGroup::GetGroupChildren() const
143
{
144
  return this->Internal->GroupChildren;
145
}