2005-09-22 Marek Sieradzki <marek.sieradzki@gmail.com>
[mono.git] / mcs / class / Microsoft.Build.Engine / Microsoft.Build.BuildEngine / GroupingCollection.cs
1 //
2 // GroupingCollection.cs: Represents group of BuildItemGroup,
3 // BuildPropertyGroup and BuildChoose.
4 //
5 // Author:
6 //   Marek Sieradzki (marek.sieradzki@gmail.com)
7 // 
8 // (C) 2005 Marek Sieradzki
9 //
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:
17 //
18 // The above copyright notice and this permission notice shall be
19 // included in all copies or substantial portions of the Software.
20 //
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.
28
29 #if NET_2_0
30
31 using System.Collections;
32
33 namespace Microsoft.Build.BuildEngine {
34         public class GroupingCollection : IEnumerable {
35                 
36                 IList   allGroups;
37                 int     itemGroups;
38                 int     propertyGroups;
39                 int     chooses;
40         
41                 public GroupingCollection ()
42                 {
43                         allGroups = new ArrayList ();
44                 }
45
46                 public IEnumerator GetChooseEnumerator ()
47                 {
48                         foreach (object o in allGroups)
49                                 if (o is BuildChoose)
50                                         yield return o;
51                 }
52
53                 public IEnumerator GetEnumerator ()
54                 {
55                         foreach (object o in allGroups) {
56                                 if (o is BuildItemGroup) {
57                                         yield return o;
58                                         continue;
59                                 }
60                                 if (o is BuildPropertyGroup) {
61                                         yield return o;
62                                         continue;
63                                 }
64                                 if (o is BuildChoose) {
65                                         yield return o;
66                                 }
67                         }
68                 }
69
70                 public IEnumerator GetItemGroupAndChooseEnumerator ()
71                 {
72                         foreach (object o in allGroups) {
73                                 if (o is BuildItemGroup) {
74                                         yield return o;
75                                         continue;
76                                 }
77                                 if (o is BuildChoose) {
78                                         yield return o;
79                                 }
80                         }
81                 }
82
83                 public IEnumerator GetItemGroupEnumerator ()
84                 {
85                         foreach (object o in allGroups)
86                                 if (o is BuildItemGroup)
87                                         yield return o;
88                 }
89
90                 public IEnumerator GetPropertyGroupAndChooseEnumerator ()
91                 {
92                         foreach (object o in allGroups) {
93                                 if (o is BuildPropertyGroup) {
94                                         yield return o;
95                                         continue;
96                                 }
97                                 if (o is BuildChoose) {
98                                         yield return o;
99                                 }
100                         }
101                 }
102
103                 public IEnumerator GetPropertyGroupEnumerator ()
104                 {
105                         foreach (object o in allGroups) {
106                                 if (o is BuildPropertyGroup)
107                                         yield return o;
108                         }
109                 }
110                 
111                 internal void Add (BuildPropertyGroup bpg) {
112                         bpg.GroupingCollection = this;
113                         allGroups.Add (bpg);
114                         propertyGroups++;
115                 }
116                 
117                 internal void Add (BuildItemGroup big) {
118                         allGroups.Add (big);
119                         itemGroups++;
120                 }
121                 
122                 internal void Add (BuildChoose bc) {
123                         allGroups.Add (bc);
124                         chooses++;
125                 }
126                 
127                 internal int ItemGroups {
128                         get { return this.itemGroups; }
129                 }
130                 
131                 internal int PropertyGroups {
132                         get { return this.propertyGroups; }
133                 }
134                 
135                 internal int Chooses {
136                         get { return this.chooses; }
137                 } 
138         }
139 }
140
141 #endif