Constructing Descriptor Arrays

Descriptor arrays provide normal array operations for inserting, appending, deleting, and accessing elements.

Procedure

Follow the steps listed below to construct descriptor arrays:

  1. Construct a set of descriptors.

    The following code fragments illustrate how to construct a CDesCArrayFlat and a CPtrCArray. Both array types can accept any type of descriptor as source when adding a new array element.

    _LIT( KText1,"abcdefg" );
    _LIT( KText2,"hijk" );
    _LIT( KText3,"lmnopqr" );
    _LIT( KText4,"stuvwxyz" );
    ...
    TBufC<8> buffer1( KText1 );  // a non-modifiable buffer descriptor
    TBuf<8>  buffer2( Ktext2 );  // a modifiable buffer descriptor
    ...
    TPtrC  ptr1( Ktext3 );       // a non-modifiable pointer descriptor
    TPtr   ptr2;                 // a modifiable pointer descriptor 
    ptr2 = buffer1.Des();        // pointing to the data in buffer1
    ...
    HBufC* heapbuff = HBufC::NewL( 8 );  // a heap descriptor
    *heapbuff = KText4;

    Note: Constructing and using a CDesCArraySeg is same as using CDesCArrayFlat.

  2. Add the five descriptors to CDesCArrayFlat as shown in the following code.

    CDesCArrayFlat* descarray;
    ...
    descarray = new( ELeave ) CDesCArrayFlat( 5 );
    ...
    descarray->AppendL( buffer1 );
    descarray->AppendL( buffer2 );
    descarray->AppendL( ptr1 );
    descarray->AppendL( ptr2 );
    descarray->AppendL( *heapbuff );
    ...
    TInt len = descarray->MdcaPoint( 2 ).Length();  // information about
                                                    // the third element
    ...
  3. Add the five descriptors to CPtrCArray as shown in the following code.

    CPtrCArray* ptrcarray;
    ...
    ptrcarray = new( ELeave ) CPtrCArray( 5 );
    ...
    ptrcarray->AppendL( buffer1 );
    ptrcarray->AppendL( buffer2 );
    ptrcarray->AppendL( ptr1 );
    ptrcarray->AppendL( ptr2 );
    ptrcarray->AppendL( *heapbuff );
    ...
    TInt len = ptrcarray->MdcaPoint( 2 ).Length();  // information about
                                                    // the third element
    ...

Related concepts