|
1 /* |
|
2 * Copyright (c) 2004-2008 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: |
|
15 * |
|
16 */ |
|
17 |
|
18 using System; |
|
19 using System.Text; |
|
20 using System.Collections; |
|
21 |
|
22 namespace SymBuildParsingLib.Token |
|
23 { |
|
24 public class SymTokenContainer : IEnumerable |
|
25 { |
|
26 #region Observer interface |
|
27 public delegate void TokenHandler( SymToken aNewToken ); |
|
28 #endregion |
|
29 |
|
30 #region Events |
|
31 public event TokenHandler iTokenHandlers; |
|
32 #endregion |
|
33 |
|
34 #region Constructors & destructor |
|
35 public SymTokenContainer() |
|
36 { |
|
37 } |
|
38 |
|
39 public SymTokenContainer( SymTokenContainer aCopy ) |
|
40 { |
|
41 foreach( SymToken t in aCopy ) |
|
42 { |
|
43 Append( t ); |
|
44 } |
|
45 } |
|
46 #endregion |
|
47 |
|
48 #region API |
|
49 public void Append( SymToken aToken ) |
|
50 { |
|
51 iTokens.Add( aToken ); |
|
52 // |
|
53 if ( iTokenHandlers != null ) |
|
54 { |
|
55 iTokenHandlers( aToken ); |
|
56 } |
|
57 } |
|
58 |
|
59 public SymToken PopTail() |
|
60 { |
|
61 System.Diagnostics.Debug.Assert( Count > 0 ); |
|
62 SymToken ret = PeekTail; |
|
63 iTokens.RemoveAt( iTokens.Count - 1 ); |
|
64 return ret; |
|
65 } |
|
66 |
|
67 public SymToken PopHead() |
|
68 { |
|
69 System.Diagnostics.Debug.Assert( Count > 0 ); |
|
70 SymToken ret = PeekHead; |
|
71 iTokens.RemoveAt( 0 ); |
|
72 return ret; |
|
73 } |
|
74 |
|
75 public void Reset() |
|
76 { |
|
77 iTokens.Clear(); |
|
78 } |
|
79 |
|
80 public void Remove( int aIndex ) |
|
81 { |
|
82 iTokens.RemoveAt( aIndex ); |
|
83 } |
|
84 #endregion |
|
85 |
|
86 #region Query API |
|
87 public bool IsPresent( SymToken aToken ) |
|
88 { |
|
89 int index = IndexOf( aToken ); |
|
90 return ( index >= 0 && index < Count ); |
|
91 } |
|
92 |
|
93 public int IndexOf( SymToken aToken ) |
|
94 { |
|
95 int index = iTokens.IndexOf( aToken ); |
|
96 return index; |
|
97 } |
|
98 |
|
99 public int IndexOf( SymToken aToken, int aStartIndex ) |
|
100 { |
|
101 int index = iTokens.IndexOf( aToken, aStartIndex ); |
|
102 return index; |
|
103 } |
|
104 |
|
105 public int LastIndexOf( SymToken aToken ) |
|
106 { |
|
107 int index = iTokens.LastIndexOf( aToken ); |
|
108 return index; |
|
109 } |
|
110 |
|
111 public int LastIndexOf( SymToken aToken, int aStartIndex ) |
|
112 { |
|
113 int index = iTokens.LastIndexOf( aToken, aStartIndex ); |
|
114 return index; |
|
115 } |
|
116 |
|
117 public int TokenCount( SymToken aTokenToCount ) |
|
118 { |
|
119 int count = 0; |
|
120 // |
|
121 foreach( SymToken t in this ) |
|
122 { |
|
123 if ( t.Equals( aTokenToCount ) ) |
|
124 { |
|
125 ++count; |
|
126 } |
|
127 } |
|
128 // |
|
129 return count; |
|
130 } |
|
131 #endregion |
|
132 |
|
133 #region Properties |
|
134 public SymToken PeekHead |
|
135 { |
|
136 get |
|
137 { |
|
138 // System.Diagnostics.Debug.Assert( Count > 0 ); - bloody visual debugger stuffs this assert up. |
|
139 SymToken ret = null; |
|
140 // |
|
141 if ( Count > 0 ) |
|
142 { |
|
143 ret = (SymToken) iTokens[ 0 ]; |
|
144 } |
|
145 // |
|
146 return ret; |
|
147 } |
|
148 } |
|
149 |
|
150 public SymToken PeekTail |
|
151 { |
|
152 get |
|
153 { |
|
154 // System.Diagnostics.Debug.Assert( Count > 0 ); - bloody visual debugger stuffs this assert up. |
|
155 SymToken ret = null; |
|
156 // |
|
157 if ( Count > 0 ) |
|
158 { |
|
159 ret = (SymToken) iTokens[ iTokens.Count - 1 ]; |
|
160 } |
|
161 // |
|
162 return ret; |
|
163 } |
|
164 } |
|
165 |
|
166 public int Count |
|
167 { |
|
168 get { return iTokens.Count; } |
|
169 } |
|
170 |
|
171 public string CoalescedTokenValue |
|
172 { |
|
173 get |
|
174 { |
|
175 StringBuilder ret = new StringBuilder(); |
|
176 // |
|
177 foreach( SymToken token in this ) |
|
178 { |
|
179 ret.Append( token ); |
|
180 } |
|
181 // |
|
182 return ret.ToString(); |
|
183 } |
|
184 } |
|
185 #endregion |
|
186 |
|
187 #region IEnumerable Members |
|
188 IEnumerator IEnumerable.GetEnumerator() |
|
189 { |
|
190 return new SymTokenContainerEnumerator( this ); |
|
191 } |
|
192 #endregion |
|
193 |
|
194 #region Indexers |
|
195 public SymToken this[ int aIndex ] |
|
196 { |
|
197 get |
|
198 { |
|
199 return (SymToken) iTokens[ aIndex ]; |
|
200 } |
|
201 } |
|
202 #endregion |
|
203 |
|
204 #region Data members |
|
205 private ArrayList iTokens = new ArrayList( 250 ); |
|
206 #endregion |
|
207 } |
|
208 } |