|
1 /* |
|
2 * Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * |
|
5 * Redistribution and use in source and binary forms, with or without |
|
6 * modification, are permitted provided that the following conditions are met: |
|
7 * |
|
8 * - Redistributions of source code must retain the above copyright notice, |
|
9 * this list of conditions and the following disclaimer. |
|
10 * - Redistributions in binary form must reproduce the above copyright notice, |
|
11 * this list of conditions and the following disclaimer in the documentation |
|
12 * and/or other materials provided with the distribution. |
|
13 * - Neither the name of Nokia Corporation nor the names of its contributors |
|
14 * may be used to endorse or promote products derived from this software |
|
15 * without specific prior written permission. |
|
16 * |
|
17 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
|
18 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
|
19 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
|
20 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE |
|
21 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
|
22 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
|
23 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
|
24 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
|
25 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
|
26 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
|
27 * POSSIBILITY OF SUCH DAMAGE. |
|
28 * |
|
29 * Initial Contributors: |
|
30 * Nokia Corporation - initial contribution. |
|
31 * |
|
32 * Contributors: |
|
33 * |
|
34 * Description: |
|
35 * |
|
36 */ |
|
37 |
|
38 using System; |
|
39 using System.IO; |
|
40 using System.Text; |
|
41 using System.Text.RegularExpressions; |
|
42 using System.Collections; |
|
43 using System.Collections.Generic; |
|
44 using SymbianUtils.FileSystem.FilePair; |
|
45 |
|
46 namespace HeapLib.Reconstructor.DataSources |
|
47 { |
|
48 public sealed class DataSourceCollection : IEnumerable<DataSource> |
|
49 { |
|
50 #region Constructors & destructor |
|
51 public DataSourceCollection() |
|
52 { |
|
53 } |
|
54 |
|
55 public DataSourceCollection( DataSourceCollection aList1, DataSourceCollection aList2 ) |
|
56 { |
|
57 foreach ( DataSource source in aList1 ) |
|
58 { |
|
59 if ( aList2.IndexOf( source.ThreadName ) >= 0 ) |
|
60 { |
|
61 Add( source ); |
|
62 } |
|
63 } |
|
64 } |
|
65 #endregion |
|
66 |
|
67 #region API |
|
68 public int IndexOf( string aThread ) |
|
69 { |
|
70 int ret = -1; |
|
71 // |
|
72 for ( int i = 0; i < Count; i++ ) |
|
73 { |
|
74 DataSource src = this[ i ]; |
|
75 if ( src.ThreadName.ToUpper() == aThread.ToUpper() ) |
|
76 { |
|
77 ret = i; |
|
78 break; |
|
79 } |
|
80 } |
|
81 // |
|
82 return ret; |
|
83 } |
|
84 |
|
85 public void RemoveAt( int aIndex ) |
|
86 { |
|
87 iEntries.RemoveAt( aIndex ); |
|
88 } |
|
89 |
|
90 public void Clear() |
|
91 { |
|
92 iEntries.Clear(); |
|
93 } |
|
94 |
|
95 internal void RemoveEmptySources() |
|
96 { |
|
97 int count = Count; |
|
98 for ( int i = count - 1; i >= 0; i-- ) |
|
99 { |
|
100 DataSource src = this[ i ]; |
|
101 if ( src.IsEmpty ) |
|
102 { |
|
103 iEntries.RemoveAt( i ); |
|
104 } |
|
105 } |
|
106 } |
|
107 |
|
108 internal void Add( DataSource aSource ) |
|
109 { |
|
110 iEntries.Add( aSource ); |
|
111 } |
|
112 #endregion |
|
113 |
|
114 #region Properties |
|
115 public int Count |
|
116 { |
|
117 get { return iEntries.Count; } |
|
118 } |
|
119 |
|
120 public DataSource this[ int aIndex ] |
|
121 { |
|
122 get |
|
123 { |
|
124 DataSource ret = iEntries[ aIndex ]; |
|
125 return ret; |
|
126 } |
|
127 } |
|
128 |
|
129 public DataSource this[ string aThread ] |
|
130 { |
|
131 get |
|
132 { |
|
133 DataSource ret = null; |
|
134 // |
|
135 int index = IndexOf( aThread ); |
|
136 if ( index >= 0 && index < Count ) |
|
137 { |
|
138 ret = this[ index ]; |
|
139 } |
|
140 // |
|
141 return ret; |
|
142 } |
|
143 } |
|
144 |
|
145 public DataSource Last |
|
146 { |
|
147 get |
|
148 { |
|
149 DataSource ret = this[ Count - 1 ]; |
|
150 return ret; |
|
151 } |
|
152 } |
|
153 #endregion |
|
154 |
|
155 #region IEnumerable<DataSource> Members |
|
156 IEnumerator<DataSource> IEnumerable<DataSource>.GetEnumerator() |
|
157 { |
|
158 return new DataSourceCollectionEnumerator( this ); |
|
159 } |
|
160 |
|
161 IEnumerator IEnumerable.GetEnumerator() |
|
162 { |
|
163 return new DataSourceCollectionEnumerator( this ); |
|
164 } |
|
165 #endregion |
|
166 |
|
167 #region Data members |
|
168 private List<DataSource> iEntries = new List<DataSource>(); |
|
169 #endregion |
|
170 } |
|
171 |
|
172 #region Internal enumerator class |
|
173 internal sealed class DataSourceCollectionEnumerator : IEnumerator<DataSource> |
|
174 { |
|
175 #region Constructors & destructor |
|
176 public DataSourceCollectionEnumerator( DataSourceCollection aCollection ) |
|
177 { |
|
178 iCollection = aCollection; |
|
179 } |
|
180 #endregion |
|
181 |
|
182 #region IEnumerator Members |
|
183 public void Reset() |
|
184 { |
|
185 iCurrentIndex = -1; |
|
186 } |
|
187 |
|
188 public object Current |
|
189 { |
|
190 get |
|
191 { |
|
192 return (DataSource) iCollection[ iCurrentIndex ]; |
|
193 } |
|
194 } |
|
195 |
|
196 public bool MoveNext() |
|
197 { |
|
198 return ( ++iCurrentIndex < iCollection.Count ); |
|
199 } |
|
200 #endregion |
|
201 |
|
202 #region From IEnumerator<DataSource> |
|
203 DataSource IEnumerator<DataSource>.Current |
|
204 { |
|
205 get { return iCollection[ iCurrentIndex ]; } |
|
206 } |
|
207 #endregion |
|
208 |
|
209 #region From IDisposable |
|
210 public void Dispose() |
|
211 { |
|
212 } |
|
213 #endregion |
|
214 |
|
215 #region Data members |
|
216 private readonly DataSourceCollection iCollection; |
|
217 private int iCurrentIndex = -1; |
|
218 #endregion |
|
219 } |
|
220 #endregion |
|
221 } |