|
1 #ifndef __e32base_h__ |
|
2 #define __e32base_h__/* |
|
3 * Copyright (c) 2008-2009 Nokia Corporation and/or its subsidiary(-ies). |
|
4 * All rights reserved. |
|
5 * This component and the accompanying materials are made available |
|
6 * under the terms of the License "Eclipse Public License v1.0" |
|
7 * which accompanies this distribution, and is available |
|
8 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
9 * |
|
10 * Initial Contributors: |
|
11 * Nokia Corporation - initial contribution. |
|
12 * |
|
13 * Contributors: |
|
14 * |
|
15 * Description: |
|
16 * |
|
17 */ |
|
18 |
|
19 |
|
20 |
|
21 |
|
22 /** |
|
23 @file |
|
24 @internalComponent |
|
25 */ |
|
26 |
|
27 #include <string> |
|
28 #include <vector> |
|
29 #include <stdint.h> |
|
30 #define __ASSERT_ALWAYS(cond, func) if(!(cond)) func |
|
31 #define __ASSERT_DEBUG(cond, func) if(!(cond)) func |
|
32 #define REINTERPRET_CAST(type,val) reinterpret_cast<type>(val) |
|
33 #define CleanupClosePushL(xx) |
|
34 #define _LIT(name,str) TLIT16 name(str) |
|
35 #define _LIT16(name,str) TLIT16 name(str) |
|
36 #define _LIT8(name,str) TLIT8 name(str) |
|
37 #define _L8(str) TLIT8(str) |
|
38 #define _L16(str) TLIT16(str) |
|
39 //#define _L(str) TLIT16(str) |
|
40 #define LOCAL_C static |
|
41 #define GLDEF_C |
|
42 #define IMPORT_C |
|
43 #define EXPORT_C |
|
44 #define __UHEAP_MARK |
|
45 #define __UHEAP_MARKEND |
|
46 #define __LEAVE(err) FatalError() |
|
47 |
|
48 extern void FatalError(); |
|
49 |
|
50 typedef uint64_t TUint64; |
|
51 typedef int64_t TInt64; |
|
52 |
|
53 typedef int TInt32; |
|
54 typedef unsigned int TUint32; |
|
55 |
|
56 typedef short TInt16; |
|
57 typedef unsigned short TUint16; |
|
58 |
|
59 typedef signed char TInt8; |
|
60 typedef unsigned char TUint8; |
|
61 |
|
62 typedef TUint32 TChar; |
|
63 |
|
64 typedef int TBool; |
|
65 |
|
66 typedef void TAny; |
|
67 |
|
68 #define _MAKE_TINT64_ZX(x) ((TInt64)((TUint32)(x))) |
|
69 #define _MAKE_TUINT64_ZX(x) ((TUint64)((TUint32)(x))) |
|
70 #define MAKE_TINT64(h,l) ( (_MAKE_TINT64_ZX(h)<<32) | _MAKE_TINT64_ZX(l) ) |
|
71 #define MAKE_TUINT64(h,l) ( (_MAKE_TUINT64_ZX(h)<<32) | _MAKE_TUINT64_ZX(l) ) |
|
72 |
|
73 |
|
74 #define I64HIGH(x) ( (TUint32)((x)>>32) ) |
|
75 #define I64LOW(x) ( (TUint32)(x) ) |
|
76 #define I64INT(x) ( (TInt)(x) ) |
|
77 |
|
78 |
|
79 typedef unsigned short int TText16; |
|
80 typedef TText16 TText; |
|
81 typedef int TInt; |
|
82 typedef unsigned int TUint; |
|
83 |
|
84 #define __Size (sizeof(TUint)/sizeof(TUint16)) |
|
85 #define __Align(s) ((((s)+__Size-1)/__Size)*__Size) |
|
86 |
|
87 /** The largest integer value which can be stored as a TCardinality type. */ |
|
88 const TInt KMaxCardinality=0x1fffffff; |
|
89 const TInt KMaxName=0x80; |
|
90 |
|
91 #define FALSE false |
|
92 #define TRUE true |
|
93 enum TFalse { |
|
94 EFalse=FALSE |
|
95 }; |
|
96 enum TTrue { |
|
97 ETrue=TRUE |
|
98 }; |
|
99 |
|
100 #ifndef _FOFF |
|
101 #if __GNUC__ < 4 |
|
102 #define _FOFF(c,f) (((TInt)&(((c *)0x1000)->f))-0x1000) |
|
103 #else |
|
104 #define _FOFF(c,f) (((TInt)&(((c *)0x1000)->f))-0x1000) |
|
105 // __builtin_offset will issue warning of there are any member functions... |
|
106 //#define _FOFF(c,f) __builtin_offsetof(c,f) |
|
107 #endif |
|
108 #endif |
|
109 |
|
110 |
|
111 const TInt KMaxTInt8=0x7f; |
|
112 const TInt KMinTInt8=(-128); |
|
113 const TUint KMaxTUint8=0xffu; |
|
114 const TInt KMaxTInt16=0x7fff; |
|
115 const TInt KMinTInt16=(-32768); |
|
116 const TUint KMaxTUint16=0xffffu; |
|
117 const TInt KMaxTInt32=0x7fffffff; |
|
118 const TInt KMinTInt32=(TInt)0x80000000; |
|
119 const TUint KMaxTUint32=0xffffffffu; |
|
120 const TInt KMaxTInt=0x7fffffff; |
|
121 const TInt KMinTInt=(TInt)0x80000000; |
|
122 const TUint KMaxTUint=0xffffffffu; |
|
123 //const TInt64 KMaxTInt64 = I64LIT(0x7fffffffffffffff); |
|
124 //const TInt64 KMinTInt64 = UI64LIT(0x8000000000000000); |
|
125 //const TUint64 KMaxTUint64 = UI64LIT(0xffffffffffffffff); |
|
126 |
|
127 |
|
128 |
|
129 |
|
130 class TSize |
|
131 { |
|
132 public: |
|
133 TSize() |
|
134 { |
|
135 iWidth=0; |
|
136 iHeight=0; |
|
137 } |
|
138 TSize(TInt aWidth, TInt aHeight) |
|
139 : iWidth(aWidth), iHeight(aHeight) |
|
140 { |
|
141 } |
|
142 private: |
|
143 TInt iWidth; |
|
144 TInt iHeight; |
|
145 }; |
|
146 |
|
147 class TDesC8 |
|
148 { |
|
149 public: |
|
150 |
|
151 TInt Length() const |
|
152 { |
|
153 return iCurrentLength; |
|
154 } |
|
155 |
|
156 TInt Size() const |
|
157 { |
|
158 return iCurrentLength; |
|
159 } |
|
160 |
|
161 virtual const TUint8 *Ptr() const = 0; |
|
162 virtual const TUint8 &operator[](TInt anIndex) const = 0; |
|
163 |
|
164 TBool operator==(const TDesC8 &aDes) const; |
|
165 |
|
166 protected: |
|
167 TDesC8(); |
|
168 TDesC8(const TDesC8 &aRef); |
|
169 TDesC8(TInt aLength); |
|
170 TInt iCurrentLength; |
|
171 |
|
172 |
|
173 private: |
|
174 // Assignment is not publicly available |
|
175 TDesC8 &operator=(const TDesC8 &aRhs); |
|
176 }; |
|
177 |
|
178 class TDesC16; |
|
179 class TDes8 : public TDesC8 |
|
180 { |
|
181 public: |
|
182 |
|
183 void Copy(const TDesC16 &aDes); |
|
184 virtual void Append(TChar aChar) = 0; |
|
185 TInt MaxLength() const |
|
186 { |
|
187 return iMaxLength; |
|
188 } |
|
189 |
|
190 TInt MaxSize() const |
|
191 { |
|
192 return iMaxLength; |
|
193 } |
|
194 |
|
195 void SetLength(TInt aLength); |
|
196 |
|
197 protected: |
|
198 TDes8(); |
|
199 TDes8(const TDes8 &aRef); |
|
200 TDes8(TInt aLength,TInt aMaxLength); |
|
201 TInt iMaxLength; |
|
202 |
|
203 private: |
|
204 // Copy construction and assignment not supported |
|
205 TDes8 &operator=(const TDes8 &aRhs); |
|
206 }; |
|
207 |
|
208 class TPtr8 : public TDes8 |
|
209 { |
|
210 public: |
|
211 TPtr8(TUint8 *aBuf, TInt aLength, TInt aMaxLength) |
|
212 : TDes8(aLength, aMaxLength), iPtr(aBuf) |
|
213 { |
|
214 } |
|
215 TPtr8(TUint8 *aBuf, TInt aMaxLength) |
|
216 : TDes8(0, aMaxLength), iPtr(aBuf) |
|
217 { |
|
218 } |
|
219 |
|
220 TPtr8(const TPtr8 &aRhs); // Points at same data |
|
221 TPtr8 &operator=(const TPtr8 &aRhs); // copies data |
|
222 |
|
223 virtual const TUint8 *Ptr() const; |
|
224 virtual const TUint8 &operator[](TInt anIndex) const; |
|
225 |
|
226 virtual void Append(TChar aChar); |
|
227 |
|
228 protected: |
|
229 TUint8 *iPtr; |
|
230 }; |
|
231 |
|
232 class TPtrC8 : public TDesC8 |
|
233 { |
|
234 public: |
|
235 TPtrC8(const TUint8 *aBuf, TInt aLength) |
|
236 : TDesC8(aLength), iPtr(aBuf) |
|
237 { |
|
238 } |
|
239 TPtrC8(const TPtrC8 &aRhs); // Points at same data |
|
240 TPtrC8 &operator=(const TPtrC8 &aRhs); // copies data |
|
241 void Set(TUint8 *aBuf, TInt aLength); |
|
242 |
|
243 virtual const TUint8 *Ptr() const; |
|
244 virtual const TUint8 &operator[](TInt anIndex) const; |
|
245 |
|
246 protected: |
|
247 const TUint8 *iPtr; |
|
248 }; |
|
249 |
|
250 class TDesC16 |
|
251 { |
|
252 public: |
|
253 TInt Length() const |
|
254 { |
|
255 return iCurrentLength; |
|
256 } |
|
257 |
|
258 TInt Size() const |
|
259 { |
|
260 return iCurrentLength * sizeof(TUint16); |
|
261 } |
|
262 |
|
263 virtual const TUint16 *Ptr() const = 0; |
|
264 virtual const TUint16 &operator[](TInt anIndex) const = 0; |
|
265 |
|
266 TBool operator==(const TDesC8 &aDes) const; |
|
267 |
|
268 protected: |
|
269 TDesC16(); |
|
270 TDesC16(const TDesC16 &aRef); |
|
271 TDesC16( TInt aLength); |
|
272 TInt iCurrentLength; |
|
273 |
|
274 private: |
|
275 // Disable assignment |
|
276 TDesC16 &operator=(const TDesC16 &aRhs); |
|
277 }; |
|
278 |
|
279 class TDes16 : public TDesC16 |
|
280 { |
|
281 public: |
|
282 TInt MaxLength() const |
|
283 { |
|
284 return iMaxLength; |
|
285 } |
|
286 TInt MaxSize() const |
|
287 { |
|
288 return iMaxLength * sizeof(TUint16); |
|
289 } |
|
290 void SetLength(TInt aLength); |
|
291 |
|
292 virtual void Append(TChar aChar) = 0; |
|
293 |
|
294 protected: |
|
295 TDes16(); |
|
296 TDes16(const TDes16 &aRef); |
|
297 TDes16(TInt aLength, TInt aMaxLength); |
|
298 TInt iMaxLength; |
|
299 private: |
|
300 // Disabled assignment |
|
301 TDes16 &operator=(const TDes16 &aRhs); |
|
302 }; |
|
303 |
|
304 class TPtr16 : public TDes16 |
|
305 { |
|
306 public: |
|
307 TPtr16(TUint16 *aBuf, TInt aLength, TInt aMaxLength) |
|
308 : TDes16(aLength, aMaxLength), iPtr(aBuf) |
|
309 { |
|
310 } |
|
311 TPtr16(TUint16 *aBuf, TInt aMaxLength) |
|
312 : TDes16(0, aMaxLength), iPtr(aBuf) |
|
313 { |
|
314 } |
|
315 TPtr16(const TPtr16 &aRhs); // Points at same data |
|
316 TPtr16 &operator=(const TPtr16 &aRhs); // copies data |
|
317 |
|
318 void Copy(const TDesC8 &aDes); |
|
319 |
|
320 virtual const TUint16 *Ptr() const; |
|
321 virtual const TUint16 &operator[](TInt anIndex) const; |
|
322 virtual void Append(TChar aChar); |
|
323 |
|
324 protected: |
|
325 TUint16 *iPtr; |
|
326 }; |
|
327 |
|
328 class TPtrC16 : public TDesC16 |
|
329 { |
|
330 public: |
|
331 TPtrC16(const TUint16 *aBuf, TInt aLength) |
|
332 : TDesC16(aLength), iPtr(aBuf) |
|
333 { |
|
334 } |
|
335 TPtrC16(const TPtrC16 &aRhs); // Points at same data |
|
336 TPtrC16 &operator=(const TPtrC16 &aRhs); // copies data |
|
337 |
|
338 void Set(TUint16 *aBuf, TInt aLength); |
|
339 |
|
340 virtual const TUint16 *Ptr() const; |
|
341 |
|
342 virtual const TUint16 &operator[](TInt anIndex) const; |
|
343 |
|
344 protected: |
|
345 const TUint16 *iPtr; |
|
346 }; |
|
347 |
|
348 |
|
349 typedef TDesC16 TDesC; |
|
350 |
|
351 /** |
|
352 Packages a modifiable pointer descriptor which represents an object of specific |
|
353 type. |
|
354 |
|
355 The template parameter defines the type of object. |
|
356 |
|
357 The object represented by the packaged pointer descriptor is accessible through |
|
358 the package. |
|
359 */ |
|
360 template <class T> |
|
361 class TPckg : public TPtr8 |
|
362 { |
|
363 public: |
|
364 inline TPckg(const T& aRef); |
|
365 inline T& operator()(); |
|
366 private: |
|
367 TPckg<T>& operator=(const TPckg<T>& aRef); |
|
368 }; |
|
369 |
|
370 // Template class TPckg |
|
371 template <class T> |
|
372 inline TPckg<T>::TPckg(const T &aRef) |
|
373 : TPtr8((TUint8 *)&aRef,sizeof(T),sizeof(T)) |
|
374 /** |
|
375 Constructs a packaged modifiable pointer descriptor to represent the specified |
|
376 object whose type is defined by the template parameter. |
|
377 |
|
378 @param aRef The object to be represented by this packaged modifiable pointer |
|
379 descriptor. |
|
380 */ |
|
381 {} |
|
382 |
|
383 template <class T> |
|
384 inline T &TPckg<T>::operator()() |
|
385 /** |
|
386 Gets a reference to the object represented by this packaged |
|
387 modifiable pointer descriptor. |
|
388 |
|
389 @return The packaged object. |
|
390 */ |
|
391 {return(*((T *)iPtr));} |
|
392 |
|
393 |
|
394 |
|
395 |
|
396 |
|
397 // TLIT16 is an internal port class |
|
398 class TLIT16 |
|
399 { |
|
400 public: |
|
401 TLIT16(const char *aStr); |
|
402 TLIT16(const TLIT16 &); |
|
403 virtual ~TLIT16(); |
|
404 const TDesC16* operator&() const; |
|
405 operator const TDesC16&() const; |
|
406 const TDesC16& operator()() const; |
|
407 private: |
|
408 TLIT16 &operator=(const TLIT16 &); |
|
409 TPtrC16 iDes; |
|
410 }; |
|
411 |
|
412 // TLIT8 is an internal port class |
|
413 class TLIT8 : public TPtrC8 |
|
414 { |
|
415 public: |
|
416 TLIT8(const char *aStr); |
|
417 TLIT8(const TLIT8 &); |
|
418 }; |
|
419 |
|
420 |
|
421 |
|
422 template <TInt S> |
|
423 class TBuf : public TPtr16 |
|
424 { |
|
425 public: |
|
426 inline TBuf(); |
|
427 inline explicit TBuf(TInt aLength); |
|
428 inline TBuf(const TDesC& aDes); |
|
429 private: |
|
430 TText iBuf[__Align(S)]; |
|
431 }; |
|
432 |
|
433 template <TInt S>TBuf<S>::TBuf() |
|
434 : TPtr16(iBuf, 0, S) |
|
435 { |
|
436 } |
|
437 |
|
438 template <TInt S>TBuf<S>::TBuf(TInt aLength) |
|
439 : TPtr16(iBuf, aLength, S) |
|
440 { |
|
441 } |
|
442 |
|
443 template <TInt S>TBuf<S>::TBuf(const TDesC& aDes) |
|
444 : TPtr16(iBuf, aDes.Length(), S) |
|
445 { |
|
446 if(aDes.Length() > S) FatalError(); |
|
447 memcpy(iBuf, aDes.Ptr(), aDes.Length()*2); // *2 for 16 bit copy |
|
448 } |
|
449 |
|
450 |
|
451 template <TInt S> |
|
452 class TBuf8 : public TPtr8 |
|
453 { |
|
454 public: |
|
455 inline TBuf8(); |
|
456 inline explicit TBuf8(TInt aLength); |
|
457 inline TBuf8(const TDesC8& aDes); |
|
458 private: |
|
459 TUint8 iBuf[__Align(S)]; |
|
460 }; |
|
461 |
|
462 template <TInt S>TBuf8<S>::TBuf8() |
|
463 : TPtr8(iBuf, 0, S) |
|
464 { |
|
465 } |
|
466 |
|
467 template <TInt S>TBuf8<S>::TBuf8(TInt aLength) |
|
468 : TPtr8(iBuf, aLength, S) |
|
469 { |
|
470 } |
|
471 |
|
472 template <TInt S>TBuf8<S>::TBuf8(const TDesC8& aDes) |
|
473 : TPtr8(iBuf, aDes.Length(), S) |
|
474 { |
|
475 if(aDes.Length() > S) FatalError(); |
|
476 memcpy(iBuf, aDes.Ptr(), aDes.Length()); |
|
477 } |
|
478 |
|
479 |
|
480 typedef TBuf<KMaxName> TName; |
|
481 |
|
482 class TUid |
|
483 { |
|
484 public: |
|
485 enum { KNullUidValue }; |
|
486 |
|
487 static TUid Uid(TInt aUid) |
|
488 {TUid uid={aUid};return uid;} |
|
489 |
|
490 static TUid Null() |
|
491 {TUid uid={KNullUidValue};return uid;} |
|
492 |
|
493 TBool operator==(const TUid &aUid) const |
|
494 { |
|
495 return iUid == aUid.iUid; |
|
496 } |
|
497 |
|
498 TBool operator!=(const TUid &aUid) const |
|
499 { |
|
500 return iUid != aUid.iUid; |
|
501 } |
|
502 |
|
503 |
|
504 TInt32 iUid; |
|
505 }; |
|
506 |
|
507 const TInt KMaxCheckedUid=3; |
|
508 |
|
509 |
|
510 class TUidType |
|
511 { |
|
512 public: |
|
513 #ifndef __KERNEL_MODE__ |
|
514 IMPORT_C TUidType(); |
|
515 IMPORT_C TUidType(TUid aUid1); |
|
516 IMPORT_C TUidType(TUid aUid1,TUid aUid2); |
|
517 IMPORT_C TUidType(TUid aUid1,TUid aUid2,TUid aUid3); |
|
518 IMPORT_C TBool operator==(const TUidType& aUidType) const; |
|
519 IMPORT_C TBool operator!=(const TUidType& aUidType) const; |
|
520 IMPORT_C const TUid& operator[](TInt anIndex) const; |
|
521 IMPORT_C TUid MostDerived() const; |
|
522 IMPORT_C TBool IsPresent(TUid aUid) const; |
|
523 IMPORT_C TBool IsValid() const; |
|
524 private: |
|
525 #endif |
|
526 TUid iUid[KMaxCheckedUid]; |
|
527 }; |
|
528 |
|
529 class TCheckedUid |
|
530 { |
|
531 public: |
|
532 IMPORT_C TCheckedUid(); |
|
533 IMPORT_C TCheckedUid(const TUidType& aUidType); |
|
534 IMPORT_C TCheckedUid(const TDesC8& aPtr); |
|
535 IMPORT_C void Set(const TUidType& aUidType); |
|
536 IMPORT_C void Set(const TDesC8& aPtr); |
|
537 IMPORT_C TPtrC8 Des() const; |
|
538 const TUidType& UidType() const {return iType;}; |
|
539 protected: |
|
540 IMPORT_C TUint Check() const; |
|
541 private: |
|
542 TUidType iType; |
|
543 TUint iCheck; |
|
544 }; |
|
545 |
|
546 |
|
547 |
|
548 class RArrayBase |
|
549 { |
|
550 public: |
|
551 virtual ~RArrayBase() {} |
|
552 virtual void Close() = 0; |
|
553 }; |
|
554 |
|
555 template<typename T> class RArray : public RArrayBase |
|
556 { |
|
557 public: |
|
558 RArray(); |
|
559 explicit RArray(TInt); |
|
560 TInt Count() const; |
|
561 const T& operator[](TInt aIndex) const; |
|
562 T& operator[](TInt aIndex); |
|
563 void Remove(TInt aIndex); |
|
564 void AppendL(const T &aEntry); |
|
565 virtual void Close() {vec.clear();}; |
|
566 private: |
|
567 typedef std::vector<T> VectorT; |
|
568 VectorT vec; |
|
569 }; |
|
570 |
|
571 class Mem |
|
572 { |
|
573 public: |
|
574 static void FillZ(TAny *aTrg, TInt aLength); |
|
575 static void Crc(TUint16& aCrc,const TAny* aPtr,TInt aLength); |
|
576 static void Crc32(TUint32& aCrc, const TAny* aPtr, TInt aLength); |
|
577 static TUint8* Move(TAny *aTrg, const TAny *aSrc, TInt aLength); |
|
578 }; |
|
579 |
|
580 void Panic(TInt aCode); |
|
581 |
|
582 |
|
583 #define KNullUid TUid::Null() |
|
584 |
|
585 class RWriteStream; |
|
586 class RReadStream; |
|
587 class CFileStore; |
|
588 class CConsoleBase; |
|
589 class RFs; |
|
590 class CleanupStack |
|
591 { |
|
592 public: |
|
593 static void PopAndDestroy(RWriteStream *aStream); |
|
594 static void PopAndDestroy(RReadStream *aStream); |
|
595 static void PopAndDestroy(CFileStore *aStore); |
|
596 static void PopAndDestroy(RArrayBase *aRArray); |
|
597 static void PopAndDestroy(CConsoleBase *aCons); |
|
598 static void PopAndDestroy(RFs *aFs); |
|
599 static void PushL(void *) |
|
600 { |
|
601 } |
|
602 |
|
603 |
|
604 }; |
|
605 |
|
606 |
|
607 class User |
|
608 { |
|
609 public: |
|
610 static void LeaveIfError(TInt aError); |
|
611 static void Leave(TInt aError); // Not supported!!!! |
|
612 static void Invariant(); |
|
613 static void Panic(const TDesC &aCategory, TInt aReason); |
|
614 }; |
|
615 |
|
616 |
|
617 |
|
618 template <typename T> RArray<T>::RArray() |
|
619 { |
|
620 } |
|
621 |
|
622 template<typename T> RArray<T>::RArray(TInt) |
|
623 { |
|
624 } |
|
625 |
|
626 template<typename T> TInt RArray<T>::Count() const |
|
627 { |
|
628 return vec.size(); |
|
629 } |
|
630 |
|
631 |
|
632 template<typename T> const T& RArray<T>::operator[](TInt aIndex) const |
|
633 { |
|
634 return vec[aIndex]; |
|
635 } |
|
636 |
|
637 template<typename T> T& RArray<T>::operator[](TInt aIndex) |
|
638 { |
|
639 return vec[aIndex]; |
|
640 } |
|
641 |
|
642 |
|
643 template<typename T> void RArray<T>::Remove(TInt aIndex) |
|
644 { |
|
645 typename std::vector<T>::itrator it = vec.begin(); |
|
646 while(aIndex) ++it; |
|
647 vec.erase(it); |
|
648 } |
|
649 |
|
650 template<typename T> void RArray<T>::AppendL(const T &aEntry) |
|
651 { |
|
652 vec.push_back(aEntry); |
|
653 } |
|
654 |
|
655 #endif |