|
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 |
|
45 namespace HeapLib.Reconstructor.DataSources |
|
46 { |
|
47 public class HeapReconstructorDataSourceThreadCollection : IEnumerable<HeapReconstructorDataSourceThread> |
|
48 { |
|
49 #region Constructors & destructor |
|
50 public HeapReconstructorDataSourceThreadCollection() |
|
51 { |
|
52 } |
|
53 #endregion |
|
54 |
|
55 #region API |
|
56 public void Add( string aThreadName ) |
|
57 { |
|
58 iItems.Add( new HeapReconstructorDataSourceThread( aThreadName ) ); |
|
59 } |
|
60 |
|
61 public void Add( string aThreadName, string aPrefix ) |
|
62 { |
|
63 iItems.Add( new HeapReconstructorDataSourceThread( aThreadName, aPrefix ) ); |
|
64 } |
|
65 |
|
66 public void Add( HeapReconstructorDataSourceThread aItem ) |
|
67 { |
|
68 iItems.Add( aItem ); |
|
69 } |
|
70 |
|
71 public bool Contains( string aThread ) |
|
72 { |
|
73 bool ret = false; |
|
74 // |
|
75 foreach ( HeapReconstructorDataSourceThread item in iItems ) |
|
76 { |
|
77 if ( item.Name == aThread ) |
|
78 { |
|
79 ret = true; |
|
80 break; |
|
81 } |
|
82 } |
|
83 // |
|
84 return ret; |
|
85 } |
|
86 |
|
87 public int IndexOf( string aThread ) |
|
88 { |
|
89 string thread = aThread.ToLower(); |
|
90 int index = -1; |
|
91 // |
|
92 for ( int i = 0; i < iItems.Count; i++ ) |
|
93 { |
|
94 HeapReconstructorDataSourceThread item = iItems[ i ]; |
|
95 if ( item.Name.ToLower() == thread ) |
|
96 { |
|
97 index = i; |
|
98 break; |
|
99 } |
|
100 } |
|
101 // |
|
102 return index; |
|
103 } |
|
104 #endregion |
|
105 |
|
106 #region Properties |
|
107 public int Count |
|
108 { |
|
109 get { return iItems.Count; } |
|
110 } |
|
111 |
|
112 public HeapReconstructorDataSourceThread this[ int aIndex ] |
|
113 { |
|
114 get { return iItems[ aIndex ]; } |
|
115 } |
|
116 #endregion |
|
117 |
|
118 #region IEnumerable<HeapReconstructorDataSourceThread> Members |
|
119 IEnumerator<HeapReconstructorDataSourceThread> IEnumerable<HeapReconstructorDataSourceThread>.GetEnumerator() |
|
120 { |
|
121 return new HeapReconstructorDataSourceThreadEnumerator( this ); |
|
122 } |
|
123 #endregion |
|
124 |
|
125 #region IEnumerable Members |
|
126 IEnumerator IEnumerable.GetEnumerator() |
|
127 { |
|
128 return new HeapReconstructorDataSourceThreadEnumerator( this ); |
|
129 } |
|
130 #endregion |
|
131 |
|
132 #region Data members |
|
133 private List<HeapReconstructorDataSourceThread> iItems = new List<HeapReconstructorDataSourceThread>(); |
|
134 #endregion |
|
135 } |
|
136 |
|
137 #region Enumerator |
|
138 internal class HeapReconstructorDataSourceThreadEnumerator : IEnumerator<HeapReconstructorDataSourceThread> |
|
139 { |
|
140 #region Constructors & destructor |
|
141 public HeapReconstructorDataSourceThreadEnumerator( HeapReconstructorDataSourceThreadCollection aCollection ) |
|
142 { |
|
143 iCollection = aCollection; |
|
144 } |
|
145 #endregion |
|
146 |
|
147 #region IEnumerator<HeapReconstructorDataSourceThread> Members |
|
148 HeapReconstructorDataSourceThread IEnumerator<HeapReconstructorDataSourceThread>.Current |
|
149 { |
|
150 get |
|
151 { |
|
152 return iCollection[ iCurrentIndex ]; |
|
153 } |
|
154 } |
|
155 #endregion |
|
156 |
|
157 #region IDisposable Members |
|
158 void IDisposable.Dispose() |
|
159 { |
|
160 } |
|
161 #endregion |
|
162 |
|
163 #region IEnumerator Members |
|
164 object IEnumerator.Current |
|
165 { |
|
166 get |
|
167 { |
|
168 return iCollection[ iCurrentIndex ]; |
|
169 } |
|
170 } |
|
171 |
|
172 bool IEnumerator.MoveNext() |
|
173 { |
|
174 return ( ++iCurrentIndex < iCollection.Count ); |
|
175 } |
|
176 |
|
177 void IEnumerator.Reset() |
|
178 { |
|
179 iCurrentIndex = -1; |
|
180 } |
|
181 #endregion |
|
182 |
|
183 #region Data members |
|
184 private readonly HeapReconstructorDataSourceThreadCollection iCollection; |
|
185 private int iCurrentIndex = -1; |
|
186 #endregion |
|
187 } |
|
188 #endregion |
|
189 } |