1 /*============================================================================
2 CMake - Cross Platform Makefile Generator
3 Copyright 2000-2009 Kitware, Inc., Insight Software Consortium
5 Distributed under the OSI-approved BSD License (the "License");
6 see accompanying file Copyright.txt for details.
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"
14 class cmSourceGroupInternals
17 std::vector<cmSourceGroup> GroupChildren;
20 //----------------------------------------------------------------------------
21 cmSourceGroup::cmSourceGroup(const char* name, const char* regex,
22 const char* parentName): Name(name)
24 this->Internal = new cmSourceGroupInternals;
25 this->SetGroupRegex(regex);
28 this->FullName = parentName;
29 this->FullName += "\\";
31 this->FullName += this->Name;
34 //----------------------------------------------------------------------------
35 cmSourceGroup::~cmSourceGroup()
37 delete this->Internal;
40 //----------------------------------------------------------------------------
41 cmSourceGroup::cmSourceGroup(cmSourceGroup const& r)
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);
51 //----------------------------------------------------------------------------
52 cmSourceGroup& cmSourceGroup::operator=(cmSourceGroup const& r)
55 this->GroupRegex = r.GroupRegex;
56 this->GroupFiles = r.GroupFiles;
57 this->SourceFiles = r.SourceFiles;
58 *(this->Internal) = *(r.Internal);
62 //----------------------------------------------------------------------------
63 void cmSourceGroup::SetGroupRegex(const char* regex)
67 this->GroupRegex.compile(regex);
71 this->GroupRegex.compile("^$");
75 //----------------------------------------------------------------------------
76 void cmSourceGroup::AddGroupFile(const char* name)
78 this->GroupFiles.insert(name);
81 //----------------------------------------------------------------------------
82 const char* cmSourceGroup::GetName() const
84 return this->Name.c_str();
87 //----------------------------------------------------------------------------
88 const char* cmSourceGroup::GetFullName() const
90 return this->FullName.c_str();
93 //----------------------------------------------------------------------------
94 bool cmSourceGroup::MatchesRegex(const char* name)
96 return this->GroupRegex.find(name);
99 //----------------------------------------------------------------------------
100 bool cmSourceGroup::MatchesFiles(const char* name)
102 std::set<cmStdString>::const_iterator i = this->GroupFiles.find(name);
103 if(i != this->GroupFiles.end())
110 //----------------------------------------------------------------------------
111 void cmSourceGroup::AssignSource(const cmSourceFile* sf)
113 this->SourceFiles.push_back(sf);
116 //----------------------------------------------------------------------------
117 const std::vector<const cmSourceFile*>& cmSourceGroup::GetSourceFiles() const
119 return this->SourceFiles;
122 //----------------------------------------------------------------------------
123 void cmSourceGroup::AddChild(cmSourceGroup child)
125 this->Internal->GroupChildren.push_back(child);
128 //----------------------------------------------------------------------------
129 cmSourceGroup *cmSourceGroup::lookupChild(const char* name)
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();
138 for(;iter!=end; ++iter)
140 std::string sgName = iter->GetName();
142 // look if descenened is the one were looking for
145 return &(*iter); // if it so return it
149 // if no child with this name was found return NULL
153 cmSourceGroup *cmSourceGroup::MatchChildrenFiles(const char *name)
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();
161 if(this->MatchesFiles(name))
165 for(;iter!=end;++iter)
167 cmSourceGroup *result = iter->MatchChildrenFiles(name);
177 cmSourceGroup *cmSourceGroup::MatchChildrenRegex(const char *name)
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();
185 if(this->MatchesRegex(name))
189 for(;iter!=end; ++iter)
191 cmSourceGroup *result = iter->MatchChildrenRegex(name);
200 std::vector<cmSourceGroup> const&
201 cmSourceGroup::GetGroupChildren() const
203 return this->Internal->GroupChildren;