|
1 /* |
|
2 * Copyright (c) 1997-2009 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 the License "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 |
|
19 #include <assert.h> |
|
20 #include <stdlib.h> |
|
21 #include "STRUCTST.H" |
|
22 #include "RESOURCE.H" |
|
23 #include "TOKENS.H" |
|
24 #include "ERRORHAN.H" |
|
25 |
|
26 // StructItem |
|
27 |
|
28 StructItem::StructItem(String aLabelToSet): |
|
29 iLabel(aLabelToSet) |
|
30 {} |
|
31 |
|
32 StructItem::~StructItem() |
|
33 {} |
|
34 |
|
35 StructItem::StructItem(StructItem& /*aSource*/): ArrayItem() |
|
36 { |
|
37 assert(0); |
|
38 } |
|
39 |
|
40 // SimpleStructItem |
|
41 |
|
42 SimpleStructItem::SimpleStructItem(DataType aItemTypeToSet,String aLabelToSet): |
|
43 StructItem(aLabelToSet), |
|
44 iItemType(aItemTypeToSet) |
|
45 { |
|
46 switch(iItemType) |
|
47 { |
|
48 case L_BYTE: |
|
49 case L_WORD: |
|
50 case L_LONG: |
|
51 iDefault = "0"; |
|
52 break; |
|
53 case L_DOUBLE: |
|
54 iDefault = "0.0"; |
|
55 break; |
|
56 } |
|
57 } |
|
58 |
|
59 SimpleStructItem::SimpleStructItem(DataType aItemTypeToSet,String aLabelToSet,String aMaxLength): |
|
60 StructItem(aLabelToSet), |
|
61 iItemType(aItemTypeToSet), |
|
62 iLengthLimit(aMaxLength) |
|
63 { |
|
64 switch(iItemType) |
|
65 { |
|
66 case L_BYTE: |
|
67 case L_WORD: |
|
68 case L_LONG: |
|
69 iDefault = "0"; |
|
70 break; |
|
71 case L_DOUBLE: |
|
72 iDefault = "0.0"; |
|
73 break; |
|
74 } |
|
75 } |
|
76 |
|
77 ResourceItem* SimpleStructItem::NewResourceItem() |
|
78 { |
|
79 SimpleResourceItem* item=new SimpleResourceItem(this); |
|
80 return(item); |
|
81 } |
|
82 |
|
83 SimpleStructItem::~SimpleStructItem() |
|
84 {} |
|
85 |
|
86 SimpleStructItem::SimpleStructItem(SimpleStructItem& aSource): |
|
87 StructItem(aSource) |
|
88 { |
|
89 assert(0); |
|
90 } |
|
91 |
|
92 SimpleStructItem& SimpleStructItem::operator=(SimpleStructItem& /*Source*/) |
|
93 { |
|
94 assert(0); |
|
95 return *this; |
|
96 } |
|
97 |
|
98 // ArrayStructItem |
|
99 |
|
100 ArrayStructItem::ArrayStructItem(DataType aItemTypeToSet,String aLabelToSet): |
|
101 StructItem(aLabelToSet), |
|
102 iItemType(aItemTypeToSet), |
|
103 iLenType(0) |
|
104 {} |
|
105 |
|
106 ArrayStructItem::~ArrayStructItem() |
|
107 { |
|
108 iDefaults.DeleteAll(); |
|
109 } |
|
110 |
|
111 ResourceItem * ArrayStructItem::NewResourceItem() |
|
112 { |
|
113 return new ArrayResourceItem( this); |
|
114 } |
|
115 |
|
116 // StructTypeStructItem |
|
117 |
|
118 StructTypeStructItem::StructTypeStructItem(String aLabelToSet): |
|
119 StructItem(aLabelToSet) |
|
120 {} |
|
121 |
|
122 ResourceItem * StructTypeStructItem::NewResourceItem() |
|
123 { |
|
124 return new StructTypeResourceItem( this); |
|
125 } |
|
126 |
|
127 // StructArrayStructItem |
|
128 |
|
129 StructArrayStructItem::StructArrayStructItem(String aLabelToSet): |
|
130 StructItem(aLabelToSet), |
|
131 iLenType(0) |
|
132 {} |
|
133 |
|
134 StructArrayStructItem::StructArrayStructItem(String aLabelToSet,String aSizeToSet): |
|
135 StructItem(aLabelToSet), |
|
136 iLenType(0), |
|
137 iSize(aSizeToSet) |
|
138 {} |
|
139 |
|
140 ResourceItem * StructArrayStructItem::NewResourceItem() |
|
141 { |
|
142 return new StructArrayResourceItem( this); |
|
143 } |
|
144 |
|
145 StructArrayStructItem::~StructArrayStructItem() |
|
146 {} |
|
147 |
|
148 // StructItemArray |
|
149 |
|
150 StructItemArray::StructItemArray() |
|
151 {} |
|
152 |
|
153 StructItemArray::~StructItemArray() |
|
154 { |
|
155 DeleteAll(); |
|
156 } |
|
157 |
|
158 void StructItemArray::Add( StructItem * pNewItem) |
|
159 { |
|
160 StructItemArrayIterator next( * this); |
|
161 StructItem * p; |
|
162 |
|
163 while( ( p = next() ) != NULL) |
|
164 { |
|
165 if ( p->iLabel == pNewItem->iLabel) |
|
166 { |
|
167 ErrorHandler::OutputErrorLine( "Label already in this structure."); |
|
168 exit(1); |
|
169 } |
|
170 } |
|
171 Array::Add( pNewItem); |
|
172 } |
|
173 |
|
174 // StructItemArrayIterator |
|
175 |
|
176 StructItemArrayIterator::StructItemArrayIterator(const StructItemArray& aArray): |
|
177 ArrayIterator(aArray) |
|
178 {} |
|
179 |
|
180 StructItem* StructItemArrayIterator::operator()() |
|
181 { |
|
182 return ( StructItem *) ArrayIterator::operator()(); |
|
183 } |
|
184 |
|
185 // StructHeader |
|
186 |
|
187 StructHeader::StructHeader(String aLabelToSet): |
|
188 iLabel(aLabelToSet), |
|
189 iLenType( 0) |
|
190 {} |
|
191 |
|
192 StructHeader::StructHeader(String aLabelToSet,DataType aLenTypeToSet): |
|
193 iLabel(aLabelToSet), |
|
194 iLenType(aLenTypeToSet) |
|
195 {} |
|
196 |
|
197 // StructHeaderArray |
|
198 |
|
199 int StructHeaderArray::iInUse = 0; |
|
200 |
|
201 StructHeaderArray::StructHeaderArray() |
|
202 { |
|
203 assert( iInUse == 0); |
|
204 iInUse = 1; |
|
205 } |
|
206 |
|
207 StructHeaderArray::~StructHeaderArray() |
|
208 { |
|
209 assert( iInUse == 1); |
|
210 iInUse = 0; |
|
211 DeleteAll(); |
|
212 } |
|
213 |
|
214 void StructHeaderArray::Add( StructHeader * pNewItem) |
|
215 { |
|
216 StructHeaderArrayIterator next( * this); |
|
217 StructHeader * p; |
|
218 |
|
219 while( ( p = next() ) != NULL) |
|
220 { |
|
221 if ( p->iLabel == pNewItem->iLabel) |
|
222 { |
|
223 ErrorHandler::OutputErrorLine( "STRUCT with this name already stored"); |
|
224 exit(1); |
|
225 } |
|
226 } |
|
227 Array::Add( pNewItem); |
|
228 } |
|
229 |
|
230 StructHeader * StructHeaderArray::Find( const String & LabelSought) |
|
231 { |
|
232 StructHeaderArrayIterator next( * this); |
|
233 StructHeader * p; |
|
234 |
|
235 while( ( p = next() ) != NULL) |
|
236 if ( p->iLabel == LabelSought) |
|
237 return p; |
|
238 |
|
239 ErrorHandler::OutputErrorLine( "Label not found"); |
|
240 exit(1); |
|
241 } |
|
242 |
|
243 // StructHeaderArrayIterator |
|
244 |
|
245 StructHeaderArrayIterator::StructHeaderArrayIterator(const StructHeaderArray& aArray): |
|
246 ArrayIterator(aArray) |
|
247 {} |
|
248 |
|
249 StructHeader * StructHeaderArrayIterator::operator()() |
|
250 { |
|
251 return (StructHeader*)ArrayIterator::operator()(); |
|
252 } |