|
1 // Copyright (c) 1998-2009 Nokia Corporation and/or its subsidiary(-ies). |
|
2 // All rights reserved. |
|
3 // This component and the accompanying materials are made available |
|
4 // under the terms of "Eclipse Public License v1.0" |
|
5 // which accompanies this distribution, and is available |
|
6 // at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
7 // |
|
8 // Initial Contributors: |
|
9 // Nokia Corporation - initial contribution. |
|
10 // |
|
11 // Contributors: |
|
12 // |
|
13 // Description: |
|
14 // |
|
15 |
|
16 #if !defined(__S32STD_H__) |
|
17 #define __S32STD_H__ |
|
18 #if !defined(__S32STRM_H__) |
|
19 #include <s32strm.h> |
|
20 #endif |
|
21 |
|
22 /** The value of the null stream ID. */ |
|
23 const TUint32 KNullStreamIdValue=0; |
|
24 const TUint32 KMaxStreamIdValue=0xfffffff; |
|
25 const TUint32 KMaskStreamIdValue=0xfffffff; |
|
26 const TInt KShiftStreamIdValue=28; |
|
27 |
|
28 /** |
|
29 * @publishedAll |
|
30 * @released |
|
31 * Provides unique identification for stream within a store. |
|
32 |
|
33 A store always assigns a new id and constructs and returns an associated TStreamId |
|
34 object when a new stream is created. |
|
35 |
|
36 @see RStoreWriteStream::CreateL() |
|
37 @see RStoreWriteStream::CreateLC() |
|
38 */ |
|
39 class TStreamId |
|
40 { |
|
41 public: |
|
42 /** Constructs an uninitialised object. It is necessary because there are also |
|
43 non-default constructors in this class. */ |
|
44 TStreamId() {} |
|
45 inline TStreamId(TUint32 aValue); |
|
46 // |
|
47 inline TBool operator==(TStreamId anId) const; |
|
48 inline TBool operator!=(TStreamId anId) const; |
|
49 // |
|
50 inline void ExternalizeL(RWriteStream& aStream) const; |
|
51 IMPORT_C void InternalizeL(RReadStream& aStream); |
|
52 // |
|
53 inline TUint32 Value() const; |
|
54 private: |
|
55 TUint32 iVal; |
|
56 private: |
|
57 IMPORT_C static void __DbgChkRange(TUint32 aValue); |
|
58 }; |
|
59 #if defined(__NO_CLASS_CONSTS__) |
|
60 #define KNullStreamId TStreamId(KNullStreamIdValue) |
|
61 #else |
|
62 /** The null stream ID; this is a stream ID which is guaranteed not to exist. */ |
|
63 const TStreamId KNullStreamId=TStreamId(KNullStreamIdValue); |
|
64 #endif |
|
65 // |
|
66 class CStreamStore; |
|
67 |
|
68 /** |
|
69 * @publishedAll |
|
70 * @released |
|
71 * Supports the opening and manipulation of an existing stream in a store. |
|
72 */ |
|
73 class RStoreReadStream : public RReadStream |
|
74 { |
|
75 public: |
|
76 IMPORT_C void OpenL(const CStreamStore& aStore,TStreamId anId); |
|
77 IMPORT_C void OpenLC(const CStreamStore& aStore,TStreamId anId); |
|
78 }; |
|
79 |
|
80 /** |
|
81 * @publishedAll |
|
82 * @released |
|
83 * Supports the writing of a stream to a store. |
|
84 |
|
85 The class allows: |
|
86 |
|
87 creation of a new stream |
|
88 |
|
89 overwriting of an existing stream |
|
90 |
|
91 replacement of an existing stream |
|
92 |
|
93 appending to an existing stream |
|
94 */ |
|
95 class RStoreWriteStream : public RWriteStream |
|
96 { |
|
97 public: |
|
98 /** Constructs an uninitialised object. It is necessary because there are also |
|
99 non-default constructors in this class. */ |
|
100 RStoreWriteStream() {} |
|
101 inline RStoreWriteStream(const MExternalizer<TStreamRef>& anExter); |
|
102 IMPORT_C TStreamId CreateL(CStreamStore& aStore); |
|
103 IMPORT_C TStreamId CreateLC(CStreamStore& aStore); |
|
104 IMPORT_C void OpenL(CStreamStore& aStore,TStreamId anId); |
|
105 IMPORT_C void OpenLC(CStreamStore& aStore,TStreamId anId); |
|
106 IMPORT_C void ReplaceL(CStreamStore& aStore,TStreamId anId); |
|
107 IMPORT_C void ReplaceLC(CStreamStore& aStore,TStreamId anId); |
|
108 IMPORT_C void AppendL(CStreamStore& aStore,TStreamId anId); |
|
109 IMPORT_C void AppendLC(CStreamStore& aStore,TStreamId anId); |
|
110 }; |
|
111 |
|
112 /** |
|
113 * @publishedAll |
|
114 * @released |
|
115 * Base class for swizzles. |
|
116 |
|
117 A swizzle maintains a dual representation for an object: |
|
118 |
|
119 by stream id, if the object is not in memory (the stream contains the external |
|
120 representation of that object). |
|
121 |
|
122 by pointer, if the object is in memory. |
|
123 |
|
124 The class is not intended for instantiation. |
|
125 */ |
|
126 class TSwizzleCBase |
|
127 { |
|
128 public: |
|
129 inline TBool operator==(const TSwizzleCBase& aSwizzle) const; |
|
130 inline TBool operator==(const TAny* aPtr) const; |
|
131 inline TBool operator!=(const TSwizzleCBase& aSwizzle) const; |
|
132 inline TBool operator!=(const TAny* aPtr) const; |
|
133 // |
|
134 inline TBool IsPtr() const; |
|
135 inline TBool IsId() const; |
|
136 IMPORT_C TStreamId AsId() const; |
|
137 IMPORT_C void InternalizeL(RReadStream& aStream); |
|
138 protected: |
|
139 TSwizzleCBase() {} |
|
140 inline TSwizzleCBase(const TAny* aPtr); |
|
141 IMPORT_C TSwizzleCBase(TStreamId anId); |
|
142 inline TSwizzleCBase(TStreamRef aRef); |
|
143 inline const TAny* Ptr() const; |
|
144 IMPORT_C void DoExternalizeL(RWriteStream& aStream,TExternalizer<TAny> anExter) const; |
|
145 private: |
|
146 IMPORT_C static TBool IsPtrRep(const TAny* aPtr); |
|
147 IMPORT_C static TBool IsIdRep(const TAny* aPtr); |
|
148 private: |
|
149 const TAny* iPtr; |
|
150 private: |
|
151 IMPORT_C static void __DbgChkPtr(const TAny* aPtr); |
|
152 IMPORT_C static void __DbgChkRef(TStreamRef aRef); |
|
153 }; |
|
154 inline TBool operator==(const TAny* aPtr,const TSwizzleCBase& aSwizzle); |
|
155 inline TBool operator!=(const TAny* aPtr,const TSwizzleCBase& aSwizzle); |
|
156 |
|
157 /** |
|
158 * @publishedAll |
|
159 * @released |
|
160 * Implementation class for swizzles. |
|
161 |
|
162 Although part of the class hierarchy, no function or data members in this |
|
163 class form part of the public application programming interface. |
|
164 |
|
165 The class is not intended for instantiation. |
|
166 |
|
167 @see TSwizzle |
|
168 */ |
|
169 class TSwizzleBase : public TSwizzleCBase |
|
170 { |
|
171 protected: |
|
172 TSwizzleBase() {} |
|
173 inline TSwizzleBase(TAny* aPtr); |
|
174 inline TSwizzleBase(TStreamId anId); |
|
175 inline TAny* Ptr() const; |
|
176 }; |
|
177 |
|
178 /** |
|
179 * @publishedAll |
|
180 * @released |
|
181 * Maintains a dual representation for an object. The representation is: |
|
182 |
|
183 by stream id, if the object is not in memory (the stream contains the external |
|
184 representation of that object). |
|
185 |
|
186 by pointer, if the object is in memory. |
|
187 |
|
188 The template class defines the type of object for which the swizzle is a representation. |
|
189 Full access to the represented object is available through the swizzle. |
|
190 |
|
191 Maintaining a dual representation for an object allows the loading of objects |
|
192 into memory from a store to be deferred; this is particularly important in |
|
193 complex applications. |
|
194 */ |
|
195 template <class T> |
|
196 class TSwizzle : public TSwizzleBase |
|
197 { |
|
198 public: |
|
199 /** Constructs an uninitialised swizzle. It is necessary because there are also |
|
200 non-default constructors in this class. */ |
|
201 TSwizzle() {} |
|
202 inline TSwizzle(T* aPtr); |
|
203 inline TSwizzle(TStreamId anId); |
|
204 inline TSwizzle<T>& operator=(T* aPtr); |
|
205 inline T* AsPtr() const; |
|
206 inline operator T*() const; |
|
207 inline T& operator*() const; |
|
208 inline T* operator->() const; |
|
209 inline void ExternalizeL(RWriteStream& aStream) const; |
|
210 }; |
|
211 |
|
212 /** |
|
213 * @publishedAll |
|
214 * @released |
|
215 * A specific instantiation of the family of TSwizzle<class T> classes that maintains |
|
216 the representation of an untyped object as a non-const pointer or as a stream |
|
217 id. |
|
218 */ |
|
219 TEMPLATE_SPECIALIZATION class TSwizzle<TAny> : public TSwizzleBase |
|
220 { |
|
221 public: |
|
222 /** Default constructor. |
|
223 |
|
224 Constructs an uninitialised swizzle. */ |
|
225 TSwizzle() {} |
|
226 inline TSwizzle(TAny* aPtr); |
|
227 inline TSwizzle(TStreamId anId); |
|
228 inline TSwizzle(const TSwizzleBase& aSwizzle); |
|
229 inline TSwizzle<TAny>& operator=(TAny* aPtr); |
|
230 inline TSwizzle<TAny>& operator=(const TSwizzleBase& aSwizzle); |
|
231 inline TAny* AsPtr() const; |
|
232 inline operator TAny*() const; |
|
233 }; |
|
234 |
|
235 /** |
|
236 * @publishedAll |
|
237 * @released |
|
238 * Maintains a dual representation for a constant object. The representation is: |
|
239 |
|
240 by stream id, if the object is not in memory (the stream contains the external |
|
241 representation of that object). |
|
242 |
|
243 by pointer, if the object is in memory. |
|
244 |
|
245 The template class defines the type of object for which the swizzle is a representation. |
|
246 Access to the to the represented object is available through the swizzle, |
|
247 but is limited. The represented object cannot be changed. |
|
248 |
|
249 Maintaining a dual representation for an object allows the loading of objects |
|
250 into memory from a store to be deferred; this is particularly important in |
|
251 complex applications. |
|
252 */ |
|
253 template <class T> |
|
254 class TSwizzleC : public TSwizzleCBase |
|
255 { |
|
256 public: |
|
257 /** Constructs an uninitialised swizzle. It is necessary because there are also |
|
258 non-default constructors in this class. */ |
|
259 TSwizzleC() {} |
|
260 inline TSwizzleC(const T* aPtr); |
|
261 inline TSwizzleC(TStreamId anId); |
|
262 inline TSwizzleC(TSwizzle<T> aSwizzle); |
|
263 inline TSwizzleC<T>& operator=(const T* aPtr); |
|
264 inline const T* AsPtr() const; |
|
265 inline operator const T*() const; |
|
266 inline const T& operator*() const; |
|
267 inline const T* operator->() const; |
|
268 inline void ExternalizeL(RWriteStream& aStream) const; |
|
269 }; |
|
270 |
|
271 /** |
|
272 * @publishedAll |
|
273 * @released |
|
274 * A specific instantiation of the family of TSwizzleC<class T> classes that maintains |
|
275 the representation of an untyped object as a const pointer or as a stream id. |
|
276 */ |
|
277 TEMPLATE_SPECIALIZATION class TSwizzleC<TAny> : public TSwizzleCBase |
|
278 { |
|
279 public: |
|
280 /** Default constructor. |
|
281 |
|
282 Constructs an uninitialised swizzle. */ |
|
283 TSwizzleC() {} |
|
284 inline TSwizzleC(const TAny* aPtr); |
|
285 inline TSwizzleC(TStreamId anId); |
|
286 inline TSwizzleC(const TSwizzleCBase& aSwizzle); |
|
287 inline TSwizzleC(TStreamRef aRef); |
|
288 inline TSwizzleC<TAny>& operator=(const TAny* aPtr); |
|
289 inline TSwizzleC<TAny>& operator=(const TSwizzleCBase& aSwizzle); |
|
290 inline const TAny* AsPtr() const; |
|
291 inline operator const TAny*() const; |
|
292 }; |
|
293 |
|
294 /** |
|
295 * @publishedAll |
|
296 * @released |
|
297 * Store map used when externalising swizzled in-memory objects. |
|
298 |
|
299 It has three main characteristics: |
|
300 |
|
301 it acts as an in-memory repository of stream ids and associated swizzles |
|
302 |
|
303 it acts as an externaliser for swizzles |
|
304 |
|
305 it offers cleanup support |
|
306 */ |
|
307 class CStoreMap : public CBase,public MExternalizer<TStreamRef> |
|
308 { |
|
309 public: |
|
310 /** |
|
311 * @publishedAll |
|
312 * @released |
|
313 */ |
|
314 struct TEntry {TSwizzleC<TAny> swizzle;TStreamId id;}; |
|
315 typedef const TEntry* TIterator; |
|
316 public: |
|
317 IMPORT_C static CStoreMap* NewL(CStreamStore& aStore); |
|
318 IMPORT_C static CStoreMap* NewLC(CStreamStore& aStore); |
|
319 IMPORT_C CStoreMap(CStreamStore& aStore); |
|
320 IMPORT_C ~CStoreMap(); |
|
321 // |
|
322 IMPORT_C void BindL(TSwizzleC<TAny> aSwizzle,TStreamId anId); |
|
323 IMPORT_C void Unbind(TSwizzleC<TAny> aSwizzle); |
|
324 IMPORT_C void Forget(TStreamId anId); |
|
325 IMPORT_C void Reset(); |
|
326 IMPORT_C void ResetAndDestroy(); |
|
327 // |
|
328 IMPORT_C TStreamId At(TSwizzleC<TAny> aSwizzle) const; |
|
329 IMPORT_C TSwizzleC<TAny> Label(TStreamId anId) const; |
|
330 IMPORT_C TIterator Begin() const; |
|
331 IMPORT_C TIterator End() const; |
|
332 private: |
|
333 void ExternalizeL(const TStreamRef& aRef,RWriteStream& aStream) const; |
|
334 private: |
|
335 CArrayFixFlat<TEntry> iArray; |
|
336 TStreamId iFree; |
|
337 CStreamStore* iStore; |
|
338 }; |
|
339 |
|
340 /** |
|
341 * @publishedAll |
|
342 * @released |
|
343 * Maintains two way associations between a UID (a TUid type) and a stream id |
|
344 (a TStreamId type) . |
|
345 |
|
346 Each UID and stream id pair forms an entry in an array. The class provides |
|
347 member functions to manage these entries, for example, to add a new entry |
|
348 or to change the stream id associated with a UID. |
|
349 |
|
350 @see TUid |
|
351 @see TStreamId |
|
352 @see CDictionaryStore |
|
353 */ |
|
354 class CStreamDictionary : public CBase |
|
355 { |
|
356 public: |
|
357 IMPORT_C static CStreamDictionary* NewL(); |
|
358 IMPORT_C static CStreamDictionary* NewLC(); |
|
359 IMPORT_C CStreamDictionary(); |
|
360 IMPORT_C ~CStreamDictionary(); |
|
361 // |
|
362 IMPORT_C void AssignL(TUid aUid,TStreamId anId); |
|
363 IMPORT_C void Remove(TUid aUid); |
|
364 IMPORT_C TStreamId At(TUid aUid) const; |
|
365 IMPORT_C TBool IsNull() const; |
|
366 // |
|
367 IMPORT_C void ExternalizeL(RWriteStream& aStream) const; |
|
368 IMPORT_C void InternalizeL(RReadStream& aStream); |
|
369 private: |
|
370 |
|
371 class TEntry |
|
372 { |
|
373 public: |
|
374 TEntry() {} |
|
375 inline TEntry(TUid aUid,TStreamId anId); |
|
376 void ExternalizeL(RWriteStream& aStream) const; |
|
377 void InternalizeL(RReadStream& aStream); |
|
378 public: |
|
379 TUid iUid; |
|
380 TStreamId iId; |
|
381 }; |
|
382 private: |
|
383 CArrayFixSeg<TEntry> iArray; |
|
384 }; |
|
385 |
|
386 #include <s32std.inl> |
|
387 #endif |