Symbian Developer Library

SYMBIAN OS V6.1 EDITION FOR C++

[Index] [Glossary] [Previous] [Next]



Location: e32std.h
Link against: euser.lib

Class TBufC

template <TInt S>
#ifdef _UNICODE
class TBufC : public TBufCBase16
#else
class TBufC : public TBufCBase8
#endif

Support

Supported from 5.0

Description

Build independent non-modifiable buffer descriptor.

This is a descriptor class which provides a buffer of fixed length for containing and accessing TText data.

The class intended for instantiation. The data that the descriptor represents is part of the descriptor object itself.

The class is templated, based on an integer value which defines the size of the descriptor's data area.

The data is intended to be accessed, but not modified; however, it can be completely replaced using the assignment operators of this class. The base class provides the functions through which the data is accessed.

NOTE: The derivation of this class is dependent on the build. The chart shown here is for 16-bit (Unicode) builds only. For 8-bit builds, read an "8" for each "16". The TBufCBase16 mentioned in the prototype is an intermediate class derived from TDesC16.

Derivation

TBufCBuild independent non-modifiable buffer descriptor
TDesC16Abstract base class for 16 bit descriptors

Defined in TBufC:
Des(), TBufC(), operator=()

Inherited from TDesC16:
Alloc(), AllocL(), AllocLC(), Compare(), CompareC(), CompareF(), Find(), FindC(), FindF(), Left(), Length(), Locate(), LocateF(), LocateReverse(), LocateReverseF(), Match(), MatchC(), MatchF(), Mid(), Ptr(), Right(), Size(), operator!=(), operator<(), operator<=(), operator==(), operator>(), operator>=(), operator[]()

See also:


Construction


TBufC()

TBufC();

Description

Constructor. Constructs an empty build independent non-modifiable buffer descriptor. It contains no data.

The integer template parameter determines the size of the data area which is created as part of the buffer descriptor object.

Data can, subsequently, be assigned into this buffer descriptor using the assignment operators.

See also:


TBufC()

TBufC(const TBufC<S>& aLcb);

Description

Copy constructor. Constructs the build independent non-modifiable buffer descriptor from an existing build independent non-modifiable buffer descriptor having the same template value.

The integer template parameter of this buffer descriptor determines the size of the data area which is created as part of this object.

Data is copied from the source buffer descriptor into this buffer descriptor and the length of this buffer descriptor is set to the length of the source.

Parameters

const TBufC<S>& aLcb

The source build independent non-modifiable buffer descriptor with the same template length as this descriptor.


TBufC()

TBufC(const TDesC& aDes);

Description

Constructs the build-independent non-modifiable buffer descriptor from any existing build independent descriptor.

The integer template parameter determines the size of the data area which is created as part of this object.

Data is copied from the source descriptor into this buffer descriptor and the length of this buffer descriptor is set to the length of the source descriptor.

The length of the source descriptor must not be greater than the value of the integer template parameter, otherwise the constructor raises a USER 20 panic for an 8 bit build variant or a USER 8 panic for a 16 bit (Unicode) build variant.

Parameters

const TDesC& aDes

The source build independent non-modifiable descriptor.


TBufC()

TBufC(const TText* aString);

Description

Construction from a C-style string. Constructs the build independent non-modifiable buffer descriptor from a zero terminated string.

The integer template parameter determines the size of the data area which is created as part of this object.

The string, excluding the zero terminator, is copied into this buffer descriptor’s data area. The length of this buffer descriptor is set to the length of the string, excluding the zero terminator.

The length of the string, excluding the zero terminator, must not be greater than the value of the integer template parameter, otherwise the constructor raises a USER 20 panic for an 8 bit build variant or a USER 8 panic for a 16 bit (Unicode) build variant.

Parameters

const TText* aString

A pointer to a zero terminated string.

[Top]


Copying data, replacing existing data


operator=()

TBufC<S> operator=(const TBufC<S>& aLcb);
TBufC<S> operator=(const TDesC& aDes);
TBufC<S> operator=(const TText* aString);

Description

Copies and replaces data. Copies data into this build independent non-modifiable buffer descriptor replacing any existing data. The length of this descriptor is set to reflect the new data.

Parameters

const TBufC<S>& aLcb

The source build independent non-modifiable buffer descriptor with the same template value.

const TDesC& aDes

A build independent non-modifiable descriptor. The length of the data cannot be greater than the maximum length of the target descriptor otherwise the function raises a USER 23 panic for an 8 bit build variant or a USER 11 panic for a 16 bit (Unicode) build variant.

const TText* aString

A pointer to a zero-terminated string. The length of the string, excluding the zero terminator, must not be greater than the maximum length of the target descriptor, otherwise the function raises a USER 23 panic for an 8 bit build variant or a USER 11 panic for a 16 bit (Unicode) build variant.

Return value

TBufC&

A reference to this build independent non-modifiable buffer descriptor.

[Top]


Create a modifiable pointer descriptor for the data


Des()

TPtr Des();

Description

Return a build independent modifiable pointer descriptor. Creates and returns a build-independent modifiable pointer descriptor for the data represented by this build-independent non-modifiable buffer descriptor.

The content of a non-modifiable buffer descriptor normally cannot be altered, other than by complete replacement of the data. Creating a modifiable pointer descriptor provides a way of changing the data.

The modifiable pointer descriptor is set to point to this non-modifiable buffer descriptor's data.

The length of the modifiable pointer descriptor is set to the length of this non-modifiable buffer descriptor.

The maximum length of the modifiable pointer descriptor is set to the value of the integer template parameter.

When data is modified through this new pointer descriptor, the lengths of both it and this constant buffer descriptor are changed.

Return value

TPtr

A build independent modifiable pointer descriptor representing the data in this build independent non-modifiable buffer descriptor.