2 // GroupingCollection.cs: Represents group of BuildItemGroup,
3 // BuildPropertyGroup and BuildChoose.
6 // Marek Sieradzki (marek.sieradzki@gmail.com)
8 // (C) 2005 Marek Sieradzki
10 // Permission is hereby granted, free of charge, to any person obtaining
11 // a copy of this software and associated documentation files (the
12 // "Software"), to deal in the Software without restriction, including
13 // without limitation the rights to use, copy, modify, merge, publish,
14 // distribute, sublicense, and/or sell copies of the Software, and to
15 // permit persons to whom the Software is furnished to do so, subject to
16 // the following conditions:
18 // The above copyright notice and this permission notice shall be
19 // included in all copies or substantial portions of the Software.
21 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
22 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
23 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
24 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
25 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
26 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
27 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
31 using System.Collections;
32 using System.Collections.Generic;
34 namespace Microsoft.Build.BuildEngine {
35 internal class GroupingCollection : IEnumerable {
43 LinkedList <object> list;
44 LinkedListNode <object> add_iterator;
46 public GroupingCollection (Project project)
48 list = new LinkedList <object> ();
50 this.project = project;
53 public IEnumerator GetChooseEnumerator ()
55 foreach (object o in list)
60 public IEnumerator GetEnumerator ()
62 return list.GetEnumerator ();
65 public IEnumerator GetImportEnumerator ()
67 foreach (object o in list)
72 public IEnumerator GetItemGroupAndChooseEnumerator ()
74 foreach (object o in list)
75 if (o is BuildItemGroup || o is BuildPropertyGroup)
79 public IEnumerator GetItemGroupEnumerator ()
81 foreach (object o in list)
82 if (o is BuildItemGroup)
86 public IEnumerator GetPropertyGroupAndChooseEnumerator ()
88 foreach (object o in list)
89 if (o is BuildPropertyGroup || o is BuildChoose)
93 public IEnumerator GetPropertyGroupEnumerator ()
95 foreach (object o in list)
96 if (o is BuildPropertyGroup)
100 internal void Add (BuildPropertyGroup bpg)
102 bpg.GroupingCollection = this;
104 if (add_iterator == null)
107 list.AddAfter (add_iterator, bpg);
108 add_iterator = add_iterator.Next;
112 internal void Add (BuildItemGroup big)
115 if (add_iterator == null)
118 list.AddAfter (add_iterator, big);
119 add_iterator = add_iterator.Next;
123 internal void Add (BuildChoose bc)
126 if (add_iterator == null)
129 list.AddAfter (add_iterator, bc);
130 add_iterator = add_iterator.Next;
134 internal void Add (Import import)
137 if (add_iterator == null)
138 list.AddLast (import);
140 list.AddAfter (add_iterator, import);
141 add_iterator = add_iterator.Next;
145 internal void Remove (BuildItemGroup big)
151 internal void Remove (BuildPropertyGroup bpg)
153 // FIXME: add bpg.Detach ();
154 bpg.XmlElement.ParentNode.RemoveChild (bpg.XmlElement);
158 internal void Evaluate ()
160 Evaluate (EvaluationType.Property);
161 Evaluate (EvaluationType.Item);
164 void Evaluate (EvaluationType type)
167 BuildPropertyGroup bpg;
169 LinkedListNode <object> evaluate_iterator;
171 if (type == EvaluationType.Property) {
172 evaluate_iterator = list.First;
173 add_iterator = list.First;
175 while (evaluate_iterator != null) {
176 if (evaluate_iterator.Value is BuildPropertyGroup) {
177 bpg = (BuildPropertyGroup) evaluate_iterator.Value;
178 if (ConditionParser.ParseAndEvaluate (bpg.Condition, project))
180 } else if (evaluate_iterator.Value is Import) {
181 import = (Import) evaluate_iterator.Value;
182 if (ConditionParser.ParseAndEvaluate (import.Condition, project))
186 // if it wasn't moved by adding anything because of evaluating a Import shift it
187 if (add_iterator == evaluate_iterator)
188 add_iterator = add_iterator.Next;
190 evaluate_iterator = evaluate_iterator.Next;
193 evaluate_iterator = list.First;
194 add_iterator = list.First;
196 while (evaluate_iterator != null) {
197 if (evaluate_iterator.Value is BuildItemGroup) {
198 big = (BuildItemGroup) evaluate_iterator.Value;
199 if (ConditionParser.ParseAndEvaluate (big.Condition, project))
203 evaluate_iterator = evaluate_iterator.Next;
210 internal int Imports {
211 get { return this.imports; }
214 internal int ItemGroups {
215 get { return this.itemGroups; }
218 internal int PropertyGroups {
219 get { return this.propertyGroups; }
222 internal int Chooses {
223 get { return this.chooses; }
227 enum EvaluationType {