1 /*=========================================================================
3 Program: CMake - Cross-Platform Makefile Generator
4 Module: $RCSfile: cmSourceGroup.cxx,v $
6 Date: $Date: 2009-07-11 04:05:20 $
7 Version: $Revision: 1.21 $
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
22 std::vector
<cmSourceGroup
> GroupChildren
;
25 //----------------------------------------------------------------------------
26 cmSourceGroup::cmSourceGroup(const char* name
, const char* regex
,
27 const char* parentName
): Name(name
)
29 this->Internal
= new cmSourceGroupInternals
;
30 this->SetGroupRegex(regex
);
33 this->FullName
= parentName
;
34 this->FullName
+= "\\";
36 this->FullName
+= this->Name
;
39 //----------------------------------------------------------------------------
40 cmSourceGroup::~cmSourceGroup()
42 delete this->Internal
;
45 //----------------------------------------------------------------------------
46 cmSourceGroup::cmSourceGroup(cmSourceGroup
const& r
)
49 this->FullName
= r
.FullName
;
50 this->GroupRegex
= r
.GroupRegex
;
51 this->GroupFiles
= r
.GroupFiles
;
52 this->SourceFiles
= r
.SourceFiles
;
53 this->Internal
= new cmSourceGroupInternals(*r
.Internal
);
56 //----------------------------------------------------------------------------
57 cmSourceGroup
& cmSourceGroup::operator=(cmSourceGroup
const& r
)
60 this->GroupRegex
= r
.GroupRegex
;
61 this->GroupFiles
= r
.GroupFiles
;
62 this->SourceFiles
= r
.SourceFiles
;
63 *(this->Internal
) = *(r
.Internal
);
67 //----------------------------------------------------------------------------
68 void cmSourceGroup::SetGroupRegex(const char* regex
)
72 this->GroupRegex
.compile(regex
);
76 this->GroupRegex
.compile("^$");
80 //----------------------------------------------------------------------------
81 void cmSourceGroup::AddGroupFile(const char* name
)
83 this->GroupFiles
.insert(name
);
86 //----------------------------------------------------------------------------
87 const char* cmSourceGroup::GetName() const
89 return this->Name
.c_str();
92 //----------------------------------------------------------------------------
93 const char* cmSourceGroup::GetFullName() const
95 return this->FullName
.c_str();
98 //----------------------------------------------------------------------------
99 bool cmSourceGroup::MatchesRegex(const char* name
)
101 return this->GroupRegex
.find(name
);
104 //----------------------------------------------------------------------------
105 bool cmSourceGroup::MatchesFiles(const char* name
)
107 std::set
<cmStdString
>::const_iterator i
= this->GroupFiles
.find(name
);
108 if(i
!= this->GroupFiles
.end())
115 //----------------------------------------------------------------------------
116 void cmSourceGroup::AssignSource(const cmSourceFile
* sf
)
118 this->SourceFiles
.push_back(sf
);
121 //----------------------------------------------------------------------------
122 const std::vector
<const cmSourceFile
*>& cmSourceGroup::GetSourceFiles() const
124 return this->SourceFiles
;
127 //----------------------------------------------------------------------------
128 std::vector
<const cmSourceFile
*>& cmSourceGroup::GetSourceFiles()
130 return this->SourceFiles
;
133 //----------------------------------------------------------------------------
134 void cmSourceGroup::AddChild(cmSourceGroup child
)
136 this->Internal
->GroupChildren
.push_back(child
);
139 //----------------------------------------------------------------------------
140 cmSourceGroup
*cmSourceGroup::lookupChild(const char* name
)
142 // initializing iterators
143 std::vector
<cmSourceGroup
>::iterator iter
=
144 this->Internal
->GroupChildren
.begin();
145 std::vector
<cmSourceGroup
>::iterator end
=
146 this->Internal
->GroupChildren
.end();
149 for(;iter
!=end
; ++iter
)
151 std::string sgName
= iter
->GetName();
153 // look if descenened is the one were looking for
156 return &(*iter
); // if it so return it
160 // if no child with this name was found return NULL
164 cmSourceGroup
*cmSourceGroup::MatchChildrenFiles(const char *name
)
166 // initializing iterators
167 std::vector
<cmSourceGroup
>::iterator iter
=
168 this->Internal
->GroupChildren
.begin();
169 std::vector
<cmSourceGroup
>::iterator end
=
170 this->Internal
->GroupChildren
.end();
172 if(this->MatchesFiles(name
))
176 for(;iter
!=end
;++iter
)
178 cmSourceGroup
*result
= iter
->MatchChildrenFiles(name
);
188 cmSourceGroup
*cmSourceGroup::MatchChildrenRegex(const char *name
)
190 // initializing iterators
191 std::vector
<cmSourceGroup
>::iterator iter
=
192 this->Internal
->GroupChildren
.begin();
193 std::vector
<cmSourceGroup
>::iterator end
=
194 this->Internal
->GroupChildren
.end();
196 if(this->MatchesRegex(name
))
200 for(;iter
!=end
; ++iter
)
202 cmSourceGroup
*result
= iter
->MatchChildrenRegex(name
);
211 std::vector
<cmSourceGroup
> const&
212 cmSourceGroup::GetGroupChildren() const
214 return this->Internal
->GroupChildren
;