cmSourceGroup.cxx 3.77 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"

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

11
cmSourceGroup::cmSourceGroup(const char* name, const char* regex,
12 13
                             const char* parentName)
  : Name(name)
14
{
15
  this->Internal = new cmSourceGroupInternals;
16
  this->SetGroupRegex(regex);
17
  if (parentName) {
18 19
    this->FullName = parentName;
    this->FullName += "\\";
20
  }
21
  this->FullName += this->Name;
22 23
}

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

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

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

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

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

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

73
bool cmSourceGroup::MatchesRegex(const char* name)
74
{
75
  return this->GroupRegex.find(name);
76 77
}

78 79
bool cmSourceGroup::MatchesFiles(const char* name)
{
80
  return this->GroupFiles.find(name) != this->GroupFiles.end();
81
}
82

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

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

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

98
cmSourceGroup* cmSourceGroup::LookupChild(const char* name) const
99 100
{
  // initializing iterators
101
  std::vector<cmSourceGroup>::const_iterator iter =
102
    this->Internal->GroupChildren.begin();
103
  const std::vector<cmSourceGroup>::const_iterator end =
104
    this->Internal->GroupChildren.end();
105 106

  // st
107
  for (; iter != end; ++iter) {
108
    std::string const& sgName = iter->GetName();
109 110

    // look if descenened is the one were looking for
111
    if (sgName == name) {
112
      return const_cast<cmSourceGroup*>(&(*iter)); // if it so return it
113
    }
114
  }
115 116

  // if no child with this name was found return NULL
Daniel Pfeifer's avatar
Daniel Pfeifer committed
117
  return nullptr;
118 119
}

120
cmSourceGroup* cmSourceGroup::MatchChildrenFiles(const char* name)
121 122
{
  // initializing iterators
123 124 125 126
  std::vector<cmSourceGroup>::iterator iter =
    this->Internal->GroupChildren.begin();
  std::vector<cmSourceGroup>::iterator end =
    this->Internal->GroupChildren.end();
127

128
  if (this->MatchesFiles(name)) {
129
    return this;
130 131 132 133
  }
  for (; iter != end; ++iter) {
    cmSourceGroup* result = iter->MatchChildrenFiles(name);
    if (result) {
134 135
      return result;
    }
136
  }
Daniel Pfeifer's avatar
Daniel Pfeifer committed
137
  return nullptr;
138 139
}

140
cmSourceGroup* cmSourceGroup::MatchChildrenRegex(const char* name)
141 142
{
  // initializing iterators
143 144 145 146
  std::vector<cmSourceGroup>::iterator iter =
    this->Internal->GroupChildren.begin();
  std::vector<cmSourceGroup>::iterator end =
    this->Internal->GroupChildren.end();
147

148 149 150
  for (; iter != end; ++iter) {
    cmSourceGroup* result = iter->MatchChildrenRegex(name);
    if (result) {
151 152
      return result;
    }
153 154
  }
  if (this->MatchesRegex(name)) {
155
    return this;
156
  }
157

Daniel Pfeifer's avatar
Daniel Pfeifer committed
158
  return nullptr;
159 160
}

161
std::vector<cmSourceGroup> const& cmSourceGroup::GetGroupChildren() const
162
{
163
  return this->Internal->GroupChildren;
164
}