BUG: Fix find_* search order with path suffixes
[cmake.git] / Source / cmSourceGroup.cxx
blob38da21562ebe233114a647e1fe1281941525aff6
1 /*=========================================================================
3 Program: CMake - Cross-Platform Makefile Generator
4 Module: $RCSfile: cmSourceGroup.cxx,v $
5 Language: C++
6 Date: $Date: 2008-05-16 20:56:41 $
7 Version: $Revision: 1.20 $
9 Copyright (c) 2002 Kitware, Inc., Insight Consortium. All rights reserved.
10 See Copyright.txt or http://www.cmake.org/HTML/Copyright.html for details.
12 This software is distributed WITHOUT ANY WARRANTY; without even
13 the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
14 PURPOSE. See the above copyright notices for more information.
16 =========================================================================*/
17 #include "cmSourceGroup.h"
19 class cmSourceGroupInternals
21 public:
22 std::vector<cmSourceGroup> GroupChildren;
25 //----------------------------------------------------------------------------
26 cmSourceGroup::cmSourceGroup(const char* name, const char* regex): Name(name)
28 this->Internal = new cmSourceGroupInternals;
29 this->SetGroupRegex(regex);
32 //----------------------------------------------------------------------------
33 cmSourceGroup::~cmSourceGroup()
35 delete this->Internal;
38 //----------------------------------------------------------------------------
39 cmSourceGroup::cmSourceGroup(cmSourceGroup const& r)
41 this->Name = r.Name;
42 this->GroupRegex = r.GroupRegex;
43 this->GroupFiles = r.GroupFiles;
44 this->SourceFiles = r.SourceFiles;
45 this->Internal = new cmSourceGroupInternals(*r.Internal);
48 //----------------------------------------------------------------------------
49 cmSourceGroup& cmSourceGroup::operator=(cmSourceGroup const& r)
51 this->Name = r.Name;
52 this->GroupRegex = r.GroupRegex;
53 this->GroupFiles = r.GroupFiles;
54 this->SourceFiles = r.SourceFiles;
55 *(this->Internal) = *(r.Internal);
56 return *this;
59 //----------------------------------------------------------------------------
60 void cmSourceGroup::SetGroupRegex(const char* regex)
62 if(regex)
64 this->GroupRegex.compile(regex);
66 else
68 this->GroupRegex.compile("^$");
72 //----------------------------------------------------------------------------
73 void cmSourceGroup::AddGroupFile(const char* name)
75 this->GroupFiles.insert(name);
78 //----------------------------------------------------------------------------
79 const char* cmSourceGroup::GetName() const
81 return this->Name.c_str();
84 //----------------------------------------------------------------------------
85 bool cmSourceGroup::MatchesRegex(const char* name)
87 return this->GroupRegex.find(name);
90 //----------------------------------------------------------------------------
91 bool cmSourceGroup::MatchesFiles(const char* name)
93 std::set<cmStdString>::const_iterator i = this->GroupFiles.find(name);
94 if(i != this->GroupFiles.end())
96 return true;
98 return false;
101 //----------------------------------------------------------------------------
102 void cmSourceGroup::AssignSource(const cmSourceFile* sf)
104 this->SourceFiles.push_back(sf);
107 //----------------------------------------------------------------------------
108 const std::vector<const cmSourceFile*>& cmSourceGroup::GetSourceFiles() const
110 return this->SourceFiles;
113 //----------------------------------------------------------------------------
114 std::vector<const cmSourceFile*>& cmSourceGroup::GetSourceFiles()
116 return this->SourceFiles;
119 //----------------------------------------------------------------------------
120 void cmSourceGroup::AddChild(cmSourceGroup child)
122 this->Internal->GroupChildren.push_back(child);
125 //----------------------------------------------------------------------------
126 cmSourceGroup *cmSourceGroup::lookupChild(const char* name)
128 // initializing iterators
129 std::vector<cmSourceGroup>::iterator iter =
130 this->Internal->GroupChildren.begin();
131 std::vector<cmSourceGroup>::iterator end =
132 this->Internal->GroupChildren.end();
134 // st
135 for(;iter!=end; ++iter)
137 std::string sgName = iter->GetName();
139 // look if descenened is the one were looking for
140 if(sgName == name)
142 return &(*iter); // if it so return it
146 // if no child with this name was found return NULL
147 return NULL;
150 cmSourceGroup *cmSourceGroup::MatchChildrenFiles(const char *name)
152 // initializing iterators
153 std::vector<cmSourceGroup>::iterator iter =
154 this->Internal->GroupChildren.begin();
155 std::vector<cmSourceGroup>::iterator end =
156 this->Internal->GroupChildren.end();
158 if(this->MatchesFiles(name))
160 return this;
162 for(;iter!=end;++iter)
164 cmSourceGroup *result = iter->MatchChildrenFiles(name);
165 if(result)
167 return result;
170 return 0;
174 cmSourceGroup *cmSourceGroup::MatchChildrenRegex(const char *name)
176 // initializing iterators
177 std::vector<cmSourceGroup>::iterator iter =
178 this->Internal->GroupChildren.begin();
179 std::vector<cmSourceGroup>::iterator end =
180 this->Internal->GroupChildren.end();
182 if(this->MatchesRegex(name))
184 return this;
186 for(;iter!=end; ++iter)
188 cmSourceGroup *result = iter->MatchChildrenRegex(name);
189 if(result)
191 return result;
194 return 0;
197 std::vector<cmSourceGroup> const&
198 cmSourceGroup::GetGroupChildren() const
200 return this->Internal->GroupChildren;