1 // Copyright (c) 1995-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 the License "Symbian Foundation License v1.0" to Symbian Foundation members and "Symbian Foundation End User License Agreement v1.0" to non-members
5 // which accompanies this distribution, and is available
6 // at the URL "http://www.symbianfoundation.org/legal/licencesv10.html".
8 // Initial Contributors:
9 // Nokia Corporation - initial contribution.
14 // e32\include\e32des8.h
24 const TUint KMaskDesLength8=0xfffffff;
28 const TInt KShiftDesType8=28;
35 #ifndef __KERNEL_MODE__
43 Abstract base class for 8-bit non-modifiable descriptors.
45 The class encapsulates the data member containing the length of data
46 represented by an 8-bit descriptor. It also provides member functions through
47 which the data can be accessed, but not modified.
49 Data represented by this class is treated as a contiguous set of 8-bit (i.e.
50 single byte) values or data items.
52 This class cannot be instantiated as it is intended to form part of a class
53 hierarchy; it provides a well defined part of descriptor behaviour. It can,
54 however, be passed as an argument type for functions which want access to
55 descriptor data but do not need to modify that data.
62 inline TBool operator<(const TDesC8 &aDes) const;
63 inline TBool operator<=(const TDesC8 &aDes) const;
64 inline TBool operator>(const TDesC8 &aDes) const;
65 inline TBool operator>=(const TDesC8 &aDes) const;
66 inline TBool operator==(const TDesC8 &aDes) const;
67 inline TBool operator!=(const TDesC8 &aDes) const;
68 inline const TUint8 &operator[](TInt anIndex) const;
69 inline TInt Length() const;
70 inline TInt Size() const;
71 IMPORT_C const TUint8 *Ptr() const;
72 IMPORT_C TInt Compare(const TDesC8 &aDes) const;
73 IMPORT_C TInt Match(const TDesC8 &aDes) const;
74 IMPORT_C TInt MatchF(const TDesC8 &aDes) const;
75 IMPORT_C TInt MatchC(const TDesC8 &aDes) const;
76 IMPORT_C TInt Locate(TChar aChar) const;
77 IMPORT_C TInt LocateReverse(TChar aChar) const;
78 IMPORT_C TInt Find(const TDesC8 &aDes) const;
79 IMPORT_C TInt Find(const TUint8 *pS,TInt aLenS) const;
80 IMPORT_C TPtrC8 Left(TInt aLength) const;
81 IMPORT_C TPtrC8 Right(TInt aLength) const;
82 IMPORT_C TPtrC8 Mid(TInt aPos) const;
83 IMPORT_C TPtrC8 Mid(TInt aPos,TInt aLength) const;
84 IMPORT_C TInt CompareF(const TDesC8 &aDes) const;
85 #ifndef __KERNEL_MODE__
86 IMPORT_C TInt CompareC(const TDesC8 &aDes) const;
87 IMPORT_C TInt LocateF(TChar aChar) const;
88 IMPORT_C TInt LocateReverseF(TChar aChar) const;
89 IMPORT_C TInt FindF(const TDesC8 &aDes) const;
90 IMPORT_C TInt FindF(const TUint8 *pS,TInt aLenS) const;
91 IMPORT_C TInt FindC(const TDesC8 &aDes) const;
92 IMPORT_C TInt FindC(const TUint8 *pS,TInt aLenS) const;
93 IMPORT_C HBufC8 *Alloc() const;
94 IMPORT_C HBufC8 *AllocL() const;
95 IMPORT_C HBufC8 *AllocLC() const;
98 inline TDesC8(TInt aType,TInt aLength);
100 // delay this for a while
101 #ifdef SYMBIAN_FIX_TDESC_CONSTRUCTORS
102 inline TDesC8( const TDesC8& aOther) : iLength(aOther.iLength) {}
104 // inline ~TDesC8() {} Commented out for the moment since it breaks code
105 inline TInt Type() const;
106 inline void DoSetLength(TInt aLength);
107 IMPORT_C const TUint8 &AtC(TInt anIndex) const;
113 class TPtrC8 : public TDesC8
118 8-bit non-modifiable pointer descriptor.
120 This is a descriptor class intended for instantiation and encapsulates a
121 pointer to the 8-bit data that it represents. The data can live in ROM or RAM
122 and this location is separate from the descriptor object itself.
124 The data is intended to be accessed, but not changed, through this descriptor.
125 The base class provides the functions through which data is accessed.
137 IMPORT_C TPtrC8(const TDesC8 &aDes);
138 IMPORT_C TPtrC8(const TUint8 *aString);
139 IMPORT_C TPtrC8(const TUint8 *aBuf,TInt aLength);
140 inline void Set(const TUint8 *aBuf,TInt aLength);
141 inline void Set(const TDesC8 &aDes);
142 inline void Set(const TPtrC8& aPtr);
144 TPtrC8& operator=(const TPtrC8 &aDes);
156 An interface that defines an overflow handler for an 8-bit descriptor.
158 The interface encapsulates a function that is called when an attempt to append
159 formatted text fails because the descriptor is already at its maximum length.
161 A derived class must provide an implementation for the Overflow() member
164 @see TDes8::AppendFormat
169 Handles the overflow.
171 This function is called when the TDes8::AppendFormat() variant that takes
172 an overflow handler argument, fails.
174 @param aDes The 8-bit modifiable descriptor whose overflow results in the
175 call to this overflow handler.
177 virtual void Overflow(TDes8 &aDes)=0;
180 class TDes8IgnoreOverflow : public TDes8Overflow
185 A derived class which provides an implementation for the Overflow() member function
186 where truncation is required.
188 @see TDes16::AppendFormat
193 Handles the overflow.
195 This function is called when the TDes8::AppendFormat()
196 variant that takes an overflow handler argument, fails.
198 @param aDes The 8-bit modifiable descriptor whose overflow results in the
199 call to this overflow handler.
201 IMPORT_C virtual void Overflow(TDes8 &aDes);
206 class TDes8 : public TDesC8
211 Abstract base class for 8-bit modifiable descriptors.
213 The class encapsulates the data member containing the maximum length of data
214 represented by an 8-bit descriptor. It also provides member functions through
215 which the data can be modified.
217 The class adds to the behaviour provided by TDesC8.
219 This class cannot be instantiated as it is intended to form part of a class
220 hierarchy; it provides a well defined part of descriptor behaviour. It can,
221 however, be passed as an argument type for functions which need to both modify
222 and access descriptor data.
230 inline TDes8& operator=(const TUint8 *aString);
231 inline TDes8& operator=(const TDesC8 &aDes);
232 inline TDes8& operator=(const TDes8 &aDes);
233 inline TInt MaxLength() const;
234 inline TInt MaxSize() const;
235 inline const TUint8 &operator[](TInt anIndex) const;
236 inline TUint8 &operator[](TInt anIndex);
237 inline TDes8 &operator+=(const TDesC8 &aDes);
238 IMPORT_C void Zero();
239 IMPORT_C void SetLength(TInt aLength);
240 IMPORT_C void SetMax();
241 IMPORT_C void Copy(const TDesC8 &aDes);
242 IMPORT_C void Copy(const TUint8 *aBuf,TInt aLength);
243 IMPORT_C void Copy(const TUint8 *aString);
244 IMPORT_C void Copy(const TDesC16 &aDes);
245 IMPORT_C void Append(TChar aChar);
246 IMPORT_C void Append(const TDesC8 &aDes);
247 IMPORT_C void Append(const TDesC16 &aDes);
248 IMPORT_C void Append(const TUint8 *aBuf,TInt aLength);
249 IMPORT_C void Fill(TChar aChar);
250 IMPORT_C void Fill(TChar aChar,TInt aLength);
251 IMPORT_C void FillZ();
252 IMPORT_C void FillZ(TInt aLength);
253 IMPORT_C void Num(TInt64 aVal);
254 IMPORT_C void Num(TUint64 aVal, TRadix aRadix);
255 IMPORT_C void NumFixedWidth(TUint aVal,TRadix aRadix,TInt aWidth);
256 IMPORT_C void AppendNum(TInt64 aVal);
257 IMPORT_C void AppendNum(TUint64 aVal, TRadix aRadix);
258 IMPORT_C void AppendNumFixedWidth(TUint aVal,TRadix aRadix,TInt aWidth);
259 #ifndef __KERNEL_MODE__
260 IMPORT_C TPtr8 LeftTPtr(TInt aLength) const;
261 IMPORT_C TPtr8 RightTPtr(TInt aLength) const;
262 IMPORT_C TPtr8 MidTPtr(TInt aPos) const;
263 IMPORT_C TPtr8 MidTPtr(TInt aPos,TInt aLength) const;
264 IMPORT_C const TUint8 *PtrZ();
265 IMPORT_C void CopyF(const TDesC8 &aDes);
266 IMPORT_C void CopyC(const TDesC8 &aDes);
267 IMPORT_C void CopyLC(const TDesC8 &aDes);
268 IMPORT_C void CopyUC(const TDesC8 &aDes);
269 IMPORT_C void CopyCP(const TDesC8 &aDes);
270 IMPORT_C void Swap(TDes8 &aDes);
271 IMPORT_C void AppendFill(TChar aChar,TInt aLength);
272 IMPORT_C void ZeroTerminate();
273 IMPORT_C void Fold();
274 IMPORT_C void Collate();
275 IMPORT_C void LowerCase();
276 IMPORT_C void UpperCase();
277 IMPORT_C void Capitalize();
278 IMPORT_C void Repeat(const TUint8 *aBuf,TInt aLength);
279 IMPORT_C void Repeat(const TDesC8 &aDes);
280 IMPORT_C void Trim();
281 IMPORT_C void TrimAll();
282 IMPORT_C void TrimLeft();
283 IMPORT_C void TrimRight();
284 IMPORT_C void Insert(TInt aPos,const TDesC8 &aDes);
285 IMPORT_C void Delete(TInt aPos,TInt aLength);
286 IMPORT_C void Replace(TInt aPos,TInt aLength,const TDesC8 &aDes);
287 IMPORT_C void Justify(const TDesC8 &aDes,TInt aWidth,TAlign anAlignment,TChar aFill);
288 IMPORT_C void NumFixedWidthUC(TUint aVal,TRadix aRadix,TInt aWidth);
289 IMPORT_C void NumUC(TUint64 aVal, TRadix aRadix=EDecimal);
290 IMPORT_C TInt Num(TReal aVal,const TRealFormat &aFormat) __SOFTFP;
291 IMPORT_C void AppendNumFixedWidthUC(TUint aVal,TRadix aRadix,TInt aWidth);
292 IMPORT_C TInt AppendNum(TReal aVal,const TRealFormat &aFormat) __SOFTFP;
293 IMPORT_C void AppendNumUC(TUint64 aVal,TRadix aRadix=EDecimal);
294 IMPORT_C void Format(TRefByValue<const TDesC8> aFmt,...);
295 IMPORT_C void FormatList(const TDesC8 &aFmt,VA_LIST aList);
296 IMPORT_C void AppendJustify(const TDesC8 &Des,TInt aWidth,TAlign anAlignment,TChar aFill);
297 IMPORT_C void AppendJustify(const TDesC8 &Des,TInt aLength,TInt aWidth,TAlign anAlignment,TChar aFill);
298 IMPORT_C void AppendJustify(const TUint8 *aString,TInt aWidth,TAlign anAlignment,TChar aFill);
299 IMPORT_C void AppendJustify(const TUint8 *aString,TInt aLength,TInt aWidth,TAlign anAlignment,TChar aFill);
300 IMPORT_C void AppendFormat(TRefByValue<const TDesC8> aFmt,TDes8Overflow *aOverflowHandler,...);
301 IMPORT_C void AppendFormat(TRefByValue<const TDesC8> aFmt,...);
302 IMPORT_C void AppendFormatList(const TDesC8 &aFmt,VA_LIST aList,TDes8Overflow *aOverflowHandler=NULL);
303 IMPORT_C TPtr16 Expand();
304 IMPORT_C void Collapse();
305 #endif //__KERNEL_MODE__
307 inline TDes8(TInt aType,TInt aLength,TInt aMaxLength);
308 inline TUint8 *WPtr() const;
310 // delay this for a while
311 #ifdef SYMBIAN_FIX_TDESC_CONSTRUCTORS
312 inline TDes8(const TDes8& aOther) : TDesC8(aOther), iMaxLength(aOther.iMaxLength) {}
314 void DoAppendNum(TUint64 aVal, TRadix aRadix, TUint aA, TInt aW);
315 void DoPadAppendNum(TInt aLength, TInt aW, const TUint8* aBuf);
321 class TPtr8 : public TDes8
326 8-bit modifiable pointer descriptor.
328 This is a descriptor class intended for instantiation and encapsulates a
329 pointer to the 8-bit data that it represents. The data can live in ROM or
330 RAM and this location is separate from the descriptor object itself.
332 The data is intended to be accessed and modified through this descriptor.
333 The base classes provide the functions through which the data can be
346 IMPORT_C TPtr8(TUint8 *aBuf,TInt aMaxLength);
347 IMPORT_C TPtr8(TUint8 *aBuf,TInt aLength,TInt aMaxLength);
348 inline TPtr8& operator=(const TUint8 *aString);
349 inline TPtr8& operator=(const TDesC8& aDes);
350 inline TPtr8& operator=(const TPtr8& aPtr);
351 inline void Set(TUint8 *aBuf,TInt aLength,TInt aMaxLength);
352 inline void Set(const TPtr8 &aPtr);
354 IMPORT_C TPtr8(TBufCBase8 &aLcb,TInt aMaxLength);
358 friend class TBufCBase8;
362 class TBufCBase8 : public TDesC8
368 IMPORT_C TBufCBase8();
369 inline TBufCBase8(TInt aLength);
370 IMPORT_C TBufCBase8(const TUint8 *aString,TInt aMaxLength);
371 IMPORT_C TBufCBase8(const TDesC8 &aDes,TInt aMaxLength);
372 IMPORT_C void Copy(const TUint8 *aString,TInt aMaxLength);
373 IMPORT_C void Copy(const TDesC8 &aDes,TInt aMaxLength);
374 inline TPtr8 DoDes(TInt aMaxLength);
375 inline TUint8 *WPtr() const;
378 #ifndef __KERNEL_MODE__
380 class HBufC8 : public TBufCBase8
385 8-bit heap descriptor.
387 This is a descriptor class which provides a buffer of fixed length, allocated
388 on the heap, for containing and accessing data.
390 The class is intended for instantiation.
392 Heap descriptors have the important property that they can be made larger
393 or smaller, changing the size of the descriptor buffer. This is achieved by
394 reallocating the descriptor. Unlike the behaviour of dynamic buffers,
395 reallocation is not done automatically.
397 Data is intended to be accessed, but not modified; however, it can be
398 completely replaced using the assignment operators of this class. The base
399 class (TDesC8) provides the functions through which the data is accessed.
401 The descriptor is hosted by a heap cell, and the 8-bit data that the
402 descriptor represents is part of the descriptor object itself. The size of the
403 cell depends on the requested maximum length of the descriptor buffer when the
404 descriptor is created or re-allocated.
406 It is important to note that the size of the allocated cell, and, therefore,
407 the resulting maximum length of the descriptor, may be larger than requested
408 due to the way memory is allocated in Symbian OS. The amount by which this
409 may be rounded up depends on the platform and build type.
417 IMPORT_C static HBufC8 *New(TInt aMaxLength);
418 IMPORT_C static HBufC8 *NewL(TInt aMaxLength);
419 IMPORT_C static HBufC8 *NewLC(TInt aMaxLength);
420 IMPORT_C static HBufC8 *NewMax(TInt aMaxLength);
421 IMPORT_C static HBufC8 *NewMaxL(TInt aMaxLength);
422 IMPORT_C static HBufC8 *NewMaxLC(TInt aMaxLength);
423 IMPORT_C static HBufC8 *NewL(RReadStream &aStream,TInt aMaxLength);
424 IMPORT_C static HBufC8 *NewLC(RReadStream &aStream,TInt aMaxLength);
425 IMPORT_C HBufC8& operator=(const TUint8 *aString);
426 IMPORT_C HBufC8& operator=(const TDesC8 &aDes);
427 inline HBufC8& operator=(const HBufC8 &aLcb);
428 IMPORT_C HBufC8 *ReAlloc(TInt aMaxLength);
429 IMPORT_C HBufC8 *ReAllocL(TInt aMaxLength);
430 IMPORT_C TPtr8 Des();
432 inline HBufC8(TInt aLength);
442 #define __Size8 (sizeof(TInt)/sizeof(TInt8))
446 #define __Align8(s) ((((s)+__Size8-1)/__Size8)*__Size8)
449 class TBufC8 : public TBufCBase8
454 8-bit non-modifiable buffer descriptor.
456 This is a descriptor class which provides a buffer of fixed length for
457 containing and accessing TUint8 data.
459 The class intended for instantiation. The 8-bit data that the descriptor
460 represents is part of the descriptor object itself.
462 The class is templated, based on an integer value which defines the size of
463 the descriptor's data area.
465 The data is intended to be accessed, but not modified; however, it can be
466 completely replaced using the assignment operators of this class. The base
467 class provides the functions through which the data is accessed.
477 inline TBufC8(const TUint8 *aString);
478 inline TBufC8(const TDesC8 &aDes);
479 inline TBufC8<S> &operator=(const TUint8 *aString);
480 inline TBufC8<S> &operator=(const TDesC8 &aDes);
483 TUint8 iBuf[__Align8(S)];
486 class TBufBase8 : public TDes8
492 IMPORT_C TBufBase8(TInt aMaxLength);
493 IMPORT_C TBufBase8(TInt aLength,TInt aMaxLength);
494 IMPORT_C TBufBase8(const TUint8* aString,TInt aMaxLength);
495 IMPORT_C TBufBase8(const TDesC8& aDes,TInt aMaxLength);
499 class TBuf8 : public TBufBase8
504 A descriptor class which provides a buffer of fixed length for
505 containing, accessing and manipulating TUint8 data.
507 The class is intended for instantiation. The 8-bit data that the descriptor
508 represents is part of the descriptor object itself.
510 The class is templated, based on an integer value which determines the size
511 of the data area which is created as part of the buffer descriptor object;
512 this is also the maximum length of the descriptor.
514 The data is intended to be both accessed and modified. The base classes provide
515 the functions through which the data is accessed.
525 inline explicit TBuf8(TInt aLength);
526 inline TBuf8(const TUint8* aString);
527 inline TBuf8(const TDesC8& aDes);
528 inline TBuf8<S>& operator=(const TUint8* aString);
529 inline TBuf8<S>& operator=(const TDesC8& aDes);
530 inline TBuf8<S>& operator=(const TBuf8<S>& aBuf);
532 TUint8 iBuf[__Align8(S)];
537 class TAlignedBuf8 : public TBufBase8
541 A descriptor class functionally identical to TBuf8, the only
542 difference from it being that TAlignedBuf8's internal buffer
543 is guaranteed to be 64-bit aligned.
545 At present this class is not intended for general use. It exists
546 solely to support TPckgBuf which derives from it.
553 inline TAlignedBuf8();
554 inline explicit TAlignedBuf8(TInt aLength);
555 inline TAlignedBuf8(const TUint8* aString);
556 inline TAlignedBuf8(const TDesC8& aDes);
557 inline TAlignedBuf8<S>& operator=(const TUint8* aString);
558 inline TAlignedBuf8<S>& operator=(const TDesC8& aDes);
559 inline TAlignedBuf8<S>& operator=(const TAlignedBuf8<S>& aBuf);
562 double only_here_to_force_8byte_alignment;
563 TUint8 iBuf[__Align8(S)];
567 #ifndef __KERNEL_MODE__
569 class RBuf8 : public TDes8
574 8 bit resizable buffer descriptor.
576 The class provides a buffer that contains, accesses and manipulates
577 TUint8 data. The buffer itself is on the heap, and is managed by the class.
579 Internally, RBuf8 behaves in one of two ways:
581 - as a TPtr8 descriptor type, where the buffer just contains data
582 - as a pointer to a heap descriptor, an HBufC8* type, where the buffer
583 contains both descriptor information and the data.
585 Note that the handling of the distinction is hidden from view.
587 An RBuf8 object can allocate its own buffer. Alternatively, it can take
588 ownership of a pre-existing section of allocated memory, or it can take
589 ownership of a pre-existing heap descriptor. It can also reallocate the buffer
590 to resize it. Regardless of the way in which the buffer has been allocated,
591 the RBuf8 object is responsible for freeing memory when the object itself is closed.
593 The class is intended for instantiation.
595 The class is derived from TDes8, which means that data can be both accessed
596 and modified. The base classes provide the functions through which the data is
597 accessed. In addition, an RBuf8 object can be passed to any function that is
598 prototyped to take a TDes8 or a TDesC8 type.
609 IMPORT_C explicit RBuf8(HBufC8* aHBuf);
610 inline RBuf8& operator=(const TUint8* aString);
611 inline RBuf8& operator=(const TDesC8& aDes);
612 inline RBuf8& operator=(const RBuf8& aDes);
613 IMPORT_C void Assign(const RBuf8& aRBuf);
614 IMPORT_C void Assign(TUint8 *aHeapCell,TInt aMaxLength);
615 IMPORT_C void Assign(TUint8 *aHeapCell,TInt aLength,TInt aMaxLength);
616 IMPORT_C void Assign(HBufC8* aHBuf);
617 IMPORT_C void Swap(RBuf8& aRBuf);
618 IMPORT_C TInt Create(TInt aMaxLength);
619 IMPORT_C void CreateL(TInt aMaxLength);
620 IMPORT_C TInt CreateMax(TInt aMaxLength);
621 IMPORT_C void CreateMaxL(TInt aMaxLength);
622 inline void CreateL(RReadStream &aStream,TInt aMaxLength);
623 IMPORT_C TInt Create(const TDesC8& aDes);
624 IMPORT_C void CreateL(const TDesC8& aDes);
625 IMPORT_C TInt Create(const TDesC8& aDes,TInt aMaxLength);
626 IMPORT_C void CreateL(const TDesC8& aDes,TInt aMaxLength);
627 IMPORT_C TInt ReAlloc(TInt aMaxLength);
628 IMPORT_C void ReAllocL(TInt aMaxLength);
629 IMPORT_C void Close();
630 IMPORT_C void CleanupClosePushL();
633 IMPORT_C RBuf8(TInt aType,TInt aLength,TInt aMaxLength);
634 RBuf8(const RBuf8&); // Outlaw copy construction
637 TUint8* iEPtrType; //Pointer to data used when RBuf is of EPtr type
638 HBufC8* iEBufCPtrType; //Pointer to data used when RBuf is of EBufCPtr type
649 Value reference used in operator TLitC8::__TRefDesC8()
653 typedef TRefByValue<const TDesC8> __TRefDesC8;
664 Encapsulates literal text.
666 This is always constructed using an _LIT8 macro.
668 This class is build independent; i.e. an explicit 8-bit build variant
669 is generated for both a non-Unicode build and a Unicode build.
671 The class has no explicit constructors.
677 inline const TDesC8* operator&() const;
678 inline operator const TDesC8&() const;
679 inline const TDesC8& operator()() const;
680 inline operator const __TRefDesC8() const;
690 TText8 iBuf[__Align8(S)];