Symbian
Symbian OS Library

FAQ-0454 How do I pass collections around in EPOC?

[Index][spacer] [Previous] [Next]



 

Classification: C++ Category: Base
Created: 12/16/99 Modified: 06/12/2001
Number: FAQ-0454
Platform: ER5

Question:
EPOC defines several different kinds of templated collection: TFixedArray<>, CArrayFixFlat<>, CArrayFixSeg<>, CArrayPakFlat<>, etc. How do I write a function that returns a collection without revealing which one I've used (and without constraining me never to change implementation)?

Answer:
The templated class TArray is an iterator that gives access to members of any collection without the ability to change it. It's defined in E32BASE.H. You can pass it by value across a function call:
All of the CArray and TFixedArray collection classes provide the function Array() that returns a TArray instance. See for example the example code \EPOC32EX\E32\EUFIXARR.CPP

This, for example, is a possible function in some plug-in interface:


    // Supply an array of pointers to embedded objects.
    TBool GetEmbeddedObjectArray(TArray& aArray) const;

    (Note that RArray and RPointerArray do not support Array() for EPOC release ER5 and below.)