Symbian Programming - PowerPoint PPT Presentation

1 / 22
About This Presentation
Title:

Symbian Programming

Description:

Array class allocates a HBufC automatically when a CDesC is added ... Iterator:TDblQueIter myObj iter (LinkList) Collection classes. Arrays. CArray. Flexible ... – PowerPoint PPT presentation

Number of Views:72
Avg rating:3.0/5.0
Slides: 23
Provided by: TKT2
Category:

less

Transcript and Presenter's Notes

Title: Symbian Programming


1
Symbian Programming
  • Part V
  • Programming Symbian devices with Symbian C

Arrays
2
Content
  • Array classes
  • Linked lists

3
Fixed Arrays
  • TFixedArraylttype,sizegt name
  • TFixedArrayltTInt,10gt myNumbers
  • for(TInt j 0 j lt 10 j)
  • myNumbersj j

4
Descriptor Arrays
  • CDesC16ArrayFlat
  • CDesC16ArraySeg
  • CDesC8ArrayFlat
  • CDesC8ArraySeg
  • CDesCArrayFlat
  • CDesCArraySeg

5
Descriptor Arrays
  • CPtrC16Array
  • CPtrC8Array
  • CPtrCArray
  • Last three only available flat

6
CDesC
  • Array of HBufC pointers
  • Array class allocates a HBufC automatically when
    a CDesC is added
  • Content is copied into the HBufC

7
Example
  • _LIT(KStr1, "Coding")
  • _LIT(KStr2, " Symbian")
  • TBufClt10gt Test1(KStr1)
  • TBufClt10gt Test2(KStr2)
  • CDesCArrayFlat myArray
  • new (ELeave) CDesCArrayFlat(5)
  • CleanupStackPushL(myArray)

8
Example (cont.)
  • myArray-gtAppendL(Test1)
  • myArray-gtAppendL(Test2)
  • CleanupStackPopAndDestroy()

9
Dynamic Arrays
  • Based on dynamic Buffers
  • Templated
  • Any type elements
  • For Example
  • CArrayFixFlatltclass Tgt
  • CArrayFixSegltclass Tgt
  • CArrayPtrFlatltclass Tgt
  • CArrayPtrSegltclass Tgt
  • RArrayltclass Tgt
  • RPointerArrayltclass T

10
RArray and RPointerArray
  • RArray
  • simple array of objects
  • objects must have fixed length
  • max 640 bytes elemet size
  • RPointerArray
  • array of pointers to objects
  • arbitrarily large elements

11
RArray
  • RArrayltanyObjgt array
  • Size not preallocated
  • Can be declared as an automatic
  • goes into stack
  • The dynamic buffer is in the heap
  • Like with resources call Close when deleting

12
Granularity
  • Can be changed
  • default 8
  • RArrayltanyObjgt array(10)

13
Key order and Key offset
  • Elements can be assigned a key
  • TInt
  • Key order can be used to sort the array
  • Class offset can be declared when creating the
    array RArrayltanyObjgt array(10, 12)
  • Default 0, multiple of 4
  • _FOFF(class,member)

14
Inserting
  • Insert()
  • InsertSignedKeyOrder()
  • InsertUnsignedKeyOrder()
  • InsertInOrder()
  • InsertInOrderAllowRepeat()

15
Callback
  • You can create your own callback function for
    comparing two values
  • wrapper class TLinearOrder
  • InsertInOrder(const T aEntry,
  • TLinearOrder ltTgt AOrder)
  • the callback function in TLinearOrder

16
Appending and searching
  • Append()
  • Array automatically allocates memory as needed
  • Find()
  • FindInOrder()
  • FindInSignedOrder()
  • FindInUnsignedOrder()
  • The 3 last ones assume the array is in order

17
Searching
  • Returns either an index or KErrNotFound
  • Find(const T anObject)
  • compares keys in the array and anObject
  • also possible to create a callback using
    TIdentityRelation

18
Sorting
  • Sort()
  • SortSigned()
  • SortUnsigned()
  • Sort(TLinearOrder) callback can be used
  • Others...
  • Remove(TInt index)
  • Reset() Close() releases heap memory

19
RPointerArray
  • Like RArray, excepts holds only pointers
  • granularity
  • no keys, but you can use TLinearOrder
  • Append
  • Insert
  • etc...

20
Linked Lists
  • TDblQueltclass Tgt
  • doubly linked list
  • AddFirst()
  • AddLastC()
  • First()
  • Last()

21
Linked Lists
  • LinkTDblQueLink
  • TDblQueLink.Enque() // insert
  • TDblQueLink.Deque() // delete
  • IteratorTDblQueIterltmyObjgt iter (LinkList)

22
Collection classes
  • Arrays
  • CArray
  • Flexible
  • RArray
  • Efficient

23
Console applications
  • Testing and experimenting with strings etc. can
    be easier with a simple console app than with a
    full blown GUI
  • In Carbide
  • File-gtNew-gtSymbian OS C project
  • select console application
  • Creates a project with a single source code file
  • Code your functionality in MainL and other
    functions
Write a Comment
User Comments (0)
About PowerShow.com