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.
32 using System.Collections;
33 using System.Collections.Generic;
35 namespace Microsoft.Build.BuildEngine {
36 internal class GroupingCollection : IEnumerable {
44 LinkedList <object> list;
45 LinkedListNode <object> add_iterator;
47 public GroupingCollection (Project project)
49 list = new LinkedList <object> ();
51 this.project = project;
54 public IEnumerator GetChooseEnumerator ()
56 foreach (object o in list)
61 public IEnumerator GetEnumerator ()
63 return list.GetEnumerator ();
66 public IEnumerator GetImportEnumerator ()
68 foreach (object o in list)
73 public IEnumerator GetItemGroupAndChooseEnumerator ()
75 foreach (object o in list)
76 if (o is BuildItemGroup || o is BuildPropertyGroup)
80 public IEnumerator GetItemGroupEnumerator ()
82 foreach (object o in list)
83 if (o is BuildItemGroup)
87 public IEnumerator GetPropertyGroupAndChooseEnumerator ()
89 foreach (object o in list)
90 if (o is BuildPropertyGroup || o is BuildChoose)
94 public IEnumerator GetPropertyGroupEnumerator ()
96 foreach (object o in list)
97 if (o is BuildPropertyGroup)
101 internal void Add (BuildPropertyGroup bpg)
103 bpg.GroupingCollection = this;
105 if (add_iterator == null)
108 list.AddAfter (add_iterator, bpg);
109 add_iterator = add_iterator.Next;
113 internal void Add (BuildItemGroup big)
116 if (add_iterator == null)
119 list.AddAfter (add_iterator, big);
120 add_iterator = add_iterator.Next;
124 internal void Add (BuildChoose bc)
127 if (add_iterator == null)
130 list.AddAfter (add_iterator, bc);
131 add_iterator = add_iterator.Next;
135 internal void Add (Import import)
138 if (add_iterator == null)
139 list.AddLast (import);
141 list.AddAfter (add_iterator, import);
142 add_iterator = add_iterator.Next;
146 internal void Remove (BuildItemGroup big)
148 if (big.ParentProject != project)
149 throw new InvalidOperationException (
150 "The \"BuildItemGroup\" object specified does not belong to the correct \"Project\" object.");
156 internal void Remove (BuildPropertyGroup bpg)
158 // FIXME: add bpg.Detach ();
159 bpg.XmlElement.ParentNode.RemoveChild (bpg.XmlElement);
163 internal void Evaluate ()
165 Evaluate (EvaluationType.Property);
166 Evaluate (EvaluationType.Item);
169 void Evaluate (EvaluationType type)
172 BuildPropertyGroup bpg;
174 LinkedListNode <object> evaluate_iterator;
176 if (type == EvaluationType.Property) {
177 evaluate_iterator = list.First;
178 add_iterator = list.First;
180 while (evaluate_iterator != null) {
181 if (evaluate_iterator.Value is BuildPropertyGroup) {
182 bpg = (BuildPropertyGroup) evaluate_iterator.Value;
183 if (ConditionParser.ParseAndEvaluate (bpg.Condition, project))
185 } else if (evaluate_iterator.Value is Import) {
186 import = (Import) evaluate_iterator.Value;
187 if (ConditionParser.ParseAndEvaluate (import.Condition, project))
191 // if it wasn't moved by adding anything because of evaluating a Import shift it
192 if (add_iterator == evaluate_iterator)
193 add_iterator = add_iterator.Next;
195 evaluate_iterator = evaluate_iterator.Next;
198 evaluate_iterator = list.First;
199 add_iterator = list.First;
201 while (evaluate_iterator != null) {
202 if (evaluate_iterator.Value is BuildItemGroup) {
203 big = (BuildItemGroup) evaluate_iterator.Value;
204 if (ConditionParser.ParseAndEvaluate (big.Condition, project))
208 evaluate_iterator = evaluate_iterator.Next;
215 internal int Imports {
216 get { return this.imports; }
219 internal int ItemGroups {
220 get { return this.itemGroups; }
223 internal int PropertyGroups {
224 get { return this.propertyGroups; }
227 internal int Chooses {
228 get { return this.chooses; }
232 enum EvaluationType {