|
1 /* |
|
2 * Copyright (c) 2004-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 * Note: This file may contain code to generate corrupt files for test purposes. |
|
16 * Such code is excluded from production builds by use of compiler defines; |
|
17 * it is recommended that such code should be removed if this code is ever published publicly. |
|
18 * zero or more of a specific SIS structure |
|
19 * |
|
20 */ |
|
21 |
|
22 |
|
23 /** |
|
24 @file |
|
25 @internalComponent |
|
26 @released |
|
27 */ |
|
28 |
|
29 #ifndef __SEQUENCE_H__ |
|
30 #define __SEQUENCE_H__ |
|
31 |
|
32 #include "container.h" |
|
33 #include "element.h" |
|
34 |
|
35 #define SequenceMemSize(aType, aFieldType) ContainerMemSize(CElement <aType>, aFieldType) |
|
36 #define SequenceMem(aType, aFieldType) ContainerMem(CElement <aType>, aFieldType) |
|
37 #define SequenceIter(aType) ContainerIter(CElement <aType>) |
|
38 |
|
39 template <class T, CSISFieldRoot::TFieldType FieldType> class CSequence : public CContainer <CElement <T>, FieldType> |
|
40 // zero or more occurences of a SISField of the given type |
|
41 { |
|
42 public: |
|
43 CSequence (); |
|
44 |
|
45 virtual void Read (TSISStream& aFile, const CSISFieldRoot::TFieldSize& aContainerSize, const CSISFieldRoot::TFieldType aArrayType = CSISFieldRoot::ESISUndefined); |
|
46 virtual void Skip (TSISStream& aFile, const CSISFieldRoot::TFieldSize& aContainerSize) const; |
|
47 virtual void Write (TSISStream& aFile, const bool aIsArrayElement) const; |
|
48 virtual CSISFieldRoot::TFieldSize ByteCount (const bool aIsArray) const; |
|
49 virtual CSISFieldRoot::TFieldSize ByteCountWithHeader (const bool aInsideArray) const; |
|
50 virtual void SkipOldWriteNew (TSISStream& aFile) const; |
|
51 |
|
52 const T& operator [] (const SequenceMemSize(T, FieldType) &aIndex) const; |
|
53 T& operator [] (const SequenceMemSize(T, FieldType) &aIndex); |
|
54 |
|
55 void Push (const T& aData); |
|
56 const T& Last () const; |
|
57 T& Last (); |
|
58 |
|
59 private: |
|
60 TUint32 iLastRead; |
|
61 }; |
|
62 |
|
63 |
|
64 |
|
65 template <class T, CSISFieldRoot::TFieldType FieldType> inline |
|
66 CSequence <T, FieldType>::CSequence () : |
|
67 iLastRead (0), |
|
68 CContainer <CElement <T>, FieldType> (false) |
|
69 { |
|
70 } |
|
71 |
|
72 template <class T, CSISFieldRoot::TFieldType FieldType> |
|
73 void CSequence <T, FieldType>::Read (TSISStream& aFile, const CSISFieldRoot::TFieldSize& aContainerSize, const CSISFieldRoot::TFieldType aArrayType) |
|
74 { |
|
75 assert ( (aArrayType == CSISFieldRoot::ESISUndefined) || |
|
76 (aArrayType == CSISFieldRoot::ESISUnknown)); // sequences in arrays don't work |
|
77 TSISStream::pos_type pos = aFile.tell (); |
|
78 SetPreHeaderPos (pos); |
|
79 SetPostHeaderPos (pos); |
|
80 CSISHeader header (FieldType); |
|
81 CSISFieldRoot::TFieldSize available = aContainerSize; |
|
82 iLastRead = 0; |
|
83 while ((available > 0) && IsDataThere (aFile, header, aArrayType, true)) |
|
84 { |
|
85 T* item = new T (); |
|
86 try { |
|
87 item -> Read (aFile, header.DataSize ()); |
|
88 SequenceMem(T,FieldType).push_back (new CElement <T> (item)); |
|
89 } |
|
90 catch (...) |
|
91 { |
|
92 delete item; |
|
93 throw; |
|
94 } |
|
95 available = available - item -> ByteCountWithHeader (false); |
|
96 iLastRead++; |
|
97 } |
|
98 ReadFiller (aFile); |
|
99 } |
|
100 |
|
101 template <class T, CSISFieldRoot::TFieldType FieldType> |
|
102 void CSequence <T, FieldType>::Skip (TSISStream& aFile, const CSISFieldRoot::TFieldSize& aContainerSize) const |
|
103 { |
|
104 CSISHeader header (FieldType); |
|
105 CSISFieldRoot::TFieldSize available = aContainerSize; |
|
106 while ((available > 0) && IsDataThere (aFile, header, CSISFieldRoot::ESISUndefined, true)) |
|
107 { |
|
108 CSISFieldRoot::TFieldSize size = AlignedSize (header.DataSize ()); |
|
109 aFile.seek (size + header.ByteCount (false), std::ios_base::cur); |
|
110 available = available - size; |
|
111 } |
|
112 ReadFiller (aFile); |
|
113 } |
|
114 |
|
115 template <class T, CSISFieldRoot::TFieldType FieldType> |
|
116 void CSequence <T, FieldType>::Write (TSISStream& aFile, const bool aIsArrayElement) const |
|
117 { |
|
118 assert (! aIsArrayElement); // sequences in arrays don't work |
|
119 for (SequenceIter(T) iterMemb = SequenceMem(T,FieldType).begin (); iterMemb != SequenceMem(T,FieldType).end (); iterMemb++) |
|
120 { |
|
121 (**iterMemb) -> Write (aFile, false); |
|
122 } |
|
123 WriteFiller (aFile); |
|
124 } |
|
125 |
|
126 template <class T, CSISFieldRoot::TFieldType FieldType> |
|
127 CSISFieldRoot::TFieldSize CSequence <T, FieldType>::ByteCount (const bool aIsArray) const |
|
128 { |
|
129 assert (! aIsArray); |
|
130 return CContainer <CElement <T>, FieldType>::ByteCount (false); |
|
131 } |
|
132 |
|
133 template <class T, CSISFieldRoot::TFieldType FieldType> |
|
134 CSISFieldRoot::TFieldSize CSequence <T, FieldType>::ByteCountWithHeader (const bool aInsideArray) const |
|
135 { |
|
136 assert (! aInsideArray); |
|
137 return ByteCount (aInsideArray); |
|
138 } |
|
139 |
|
140 template <class T, CSISFieldRoot::TFieldType FieldType> inline |
|
141 void CSequence <T, FieldType>::Push (const T& aData) |
|
142 { |
|
143 T* ptr = new T (aData); |
|
144 try |
|
145 { |
|
146 CContainer<CElement <T>, FieldType>::Push (new CElement <T> (ptr)); |
|
147 } |
|
148 catch (...) |
|
149 { |
|
150 delete ptr; |
|
151 throw; |
|
152 } |
|
153 } |
|
154 |
|
155 template <class T, CSISFieldRoot::TFieldType FieldType> inline |
|
156 const T& CSequence <T, FieldType>::Last () const |
|
157 { |
|
158 return * (CContainer <CElement <T>, FieldType>::Last ()); |
|
159 } |
|
160 |
|
161 template <class T, CSISFieldRoot::TFieldType FieldType> inline |
|
162 T& CSequence <T, FieldType>::Last () |
|
163 { |
|
164 return * (CContainer <CElement <T>, FieldType>::Last ()); |
|
165 } |
|
166 |
|
167 template <class T, CSISFieldRoot::TFieldType FieldType> inline |
|
168 const T& CSequence <T, FieldType>::operator [] (const SequenceMemSize(T,FieldType)& aIndex) const |
|
169 { |
|
170 return * (CContainer <CElement <T>, FieldType>::operator [] (aIndex)); |
|
171 } |
|
172 |
|
173 template <class T, CSISFieldRoot::TFieldType FieldType> inline |
|
174 T& CSequence <T, FieldType>::operator [] (const SequenceMemSize(T,FieldType)& aIndex) |
|
175 { |
|
176 return * (CContainer <CElement <T>, FieldType>::operator [] (aIndex)); |
|
177 } |
|
178 |
|
179 |
|
180 template <class T, CSISFieldRoot::TFieldType FieldType> |
|
181 void CSequence <T, FieldType>::SkipOldWriteNew (TSISStream& aFile) const |
|
182 { |
|
183 TUint32 count = 0; |
|
184 for (SequenceIter(T) iterMemb = SequenceMem(T,FieldType).begin (); iterMemb != SequenceMem(T,FieldType).end (); iterMemb++) |
|
185 { |
|
186 if (count++ >= iLastRead) |
|
187 { |
|
188 (**iterMemb) -> Write (aFile, false); |
|
189 } |
|
190 } |
|
191 WriteFiller (aFile); |
|
192 } |
|
193 |
|
194 #endif // SEQUENCE |
|
195 |