Imported Upstream version 2.8.11.2
[platform/upstream/cmake.git] / Source / cmSourceGroup.cxx
1 /*============================================================================
2   CMake - Cross Platform Makefile Generator
3   Copyright 2000-2009 Kitware, Inc., Insight Software Consortium
4
5   Distributed under the OSI-approved BSD License (the "License");
6   see accompanying file Copyright.txt for details.
7
8   This software is distributed WITHOUT ANY WARRANTY; without even the
9   implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
10   See the License for more information.
11 ============================================================================*/
12 #include "cmSourceGroup.h"
13
14 class cmSourceGroupInternals
15 {
16 public:
17   std::vector<cmSourceGroup> GroupChildren;
18 };
19
20 //----------------------------------------------------------------------------
21 cmSourceGroup::cmSourceGroup(const char* name, const char* regex,
22                              const char* parentName): Name(name)
23 {
24   this->Internal = new cmSourceGroupInternals;
25   this->SetGroupRegex(regex);
26   if(parentName)
27     {
28     this->FullName = parentName;
29     this->FullName += "\\";
30     }
31   this->FullName += this->Name;
32 }
33
34 //----------------------------------------------------------------------------
35 cmSourceGroup::~cmSourceGroup()
36 {
37   delete this->Internal;
38 }
39
40 //----------------------------------------------------------------------------
41 cmSourceGroup::cmSourceGroup(cmSourceGroup const& r)
42 {
43   this->Name = r.Name;
44   this->FullName = r.FullName;
45   this->GroupRegex = r.GroupRegex;
46   this->GroupFiles = r.GroupFiles;
47   this->SourceFiles = r.SourceFiles;
48   this->Internal = new cmSourceGroupInternals(*r.Internal);
49 }
50
51 //----------------------------------------------------------------------------
52 cmSourceGroup& cmSourceGroup::operator=(cmSourceGroup const& r)
53 {
54   this->Name = r.Name;
55   this->GroupRegex = r.GroupRegex;
56   this->GroupFiles = r.GroupFiles;
57   this->SourceFiles = r.SourceFiles;
58   *(this->Internal) = *(r.Internal);
59   return *this;
60 }
61
62 //----------------------------------------------------------------------------
63 void cmSourceGroup::SetGroupRegex(const char* regex)
64 {
65   if(regex)
66     {
67     this->GroupRegex.compile(regex);
68     }
69   else
70     {
71     this->GroupRegex.compile("^$");
72     }
73 }
74
75 //----------------------------------------------------------------------------
76 void cmSourceGroup::AddGroupFile(const char* name)
77 {
78   this->GroupFiles.insert(name);
79 }
80
81 //----------------------------------------------------------------------------
82 const char* cmSourceGroup::GetName() const
83 {
84   return this->Name.c_str();
85 }
86
87 //----------------------------------------------------------------------------
88 const char* cmSourceGroup::GetFullName() const
89 {
90   return this->FullName.c_str();
91 }
92
93 //----------------------------------------------------------------------------
94 bool cmSourceGroup::MatchesRegex(const char* name)
95 {
96   return this->GroupRegex.find(name);
97 }
98
99 //----------------------------------------------------------------------------
100 bool cmSourceGroup::MatchesFiles(const char* name)
101 {
102   std::set<cmStdString>::const_iterator i = this->GroupFiles.find(name);
103   if(i != this->GroupFiles.end())
104     {
105     return true;
106     }
107   return false;
108 }
109
110 //----------------------------------------------------------------------------
111 void cmSourceGroup::AssignSource(const cmSourceFile* sf)
112 {
113   this->SourceFiles.push_back(sf);
114 }
115
116 //----------------------------------------------------------------------------
117 const std::vector<const cmSourceFile*>& cmSourceGroup::GetSourceFiles() const
118 {
119   return this->SourceFiles;
120 }
121
122 //----------------------------------------------------------------------------
123 void cmSourceGroup::AddChild(cmSourceGroup child)
124 {
125   this->Internal->GroupChildren.push_back(child);
126 }
127
128 //----------------------------------------------------------------------------
129 cmSourceGroup *cmSourceGroup::lookupChild(const char* name)
130 {
131   // initializing iterators
132   std::vector<cmSourceGroup>::iterator iter =
133     this->Internal->GroupChildren.begin();
134   std::vector<cmSourceGroup>::iterator end =
135     this->Internal->GroupChildren.end();
136
137   // st
138   for(;iter!=end; ++iter)
139     {
140     std::string sgName = iter->GetName();
141
142     // look if descenened is the one were looking for
143     if(sgName == name)
144       {
145       return &(*iter); // if it so return it
146       }
147     }
148
149   // if no child with this name was found return NULL
150   return NULL;
151 }
152
153 cmSourceGroup *cmSourceGroup::MatchChildrenFiles(const char *name)
154 {
155   // initializing iterators
156   std::vector<cmSourceGroup>::iterator iter =
157     this->Internal->GroupChildren.begin();
158   std::vector<cmSourceGroup>::iterator end =
159     this->Internal->GroupChildren.end();
160
161   if(this->MatchesFiles(name))
162     {
163     return this;
164     }
165   for(;iter!=end;++iter)
166     {
167     cmSourceGroup *result = iter->MatchChildrenFiles(name);
168     if(result)
169       {
170       return result;
171       }
172     }
173   return 0;
174 }
175
176
177 cmSourceGroup *cmSourceGroup::MatchChildrenRegex(const char *name)
178 {
179   // initializing iterators
180   std::vector<cmSourceGroup>::iterator iter =
181     this->Internal->GroupChildren.begin();
182   std::vector<cmSourceGroup>::iterator end =
183     this->Internal->GroupChildren.end();
184
185   for(;iter!=end; ++iter)
186     {
187     cmSourceGroup *result = iter->MatchChildrenRegex(name);
188     if(result)
189       {
190       return result;
191       }
192     }
193   if(this->MatchesRegex(name))
194     {
195     return this;
196     }
197
198   return 0;
199 }
200
201 std::vector<cmSourceGroup> const&
202 cmSourceGroup::GetGroupChildren() const
203 {
204   return this->Internal->GroupChildren;
205 }