00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030 #include "CommonFramework.h"
00031 #include <e32math.h>
00032 #include <e32std.h>
00033
00034 _LIT(KMsgNewLine,"\n");
00035 _LIT(KMsgPressAnyKey," (press any key to continue)\n");
00036 _LIT(KFormat1,"X%u");
00037
00038 const TText* firstElement = _S("DynamicArray: first");
00039 const TText* secondElement = _S("Example Code: second");
00040 const TText* thirdElement = _S("ArrayKeys Ex: third");
00041
00042
00043
00044
00045
00046 class TElement
00047 {
00048 public :
00049 TElement();
00050 public :
00051 TBuf<4> iData;
00052 };
00053
00054 TElement::TElement()
00055 {
00056 _LIT(KTextBase,"BASE");
00057 iData = KTextBase;
00058 }
00059
00060 class CArrayElement
00061 {
00062 public :
00063 CArrayElement();
00064 TBool operator==(const CArrayElement& aElement) const;
00065 public :
00066 TBuf<4> iData;
00067 };
00068
00069 CArrayElement::CArrayElement()
00070 {
00071 _LIT(KTextBase,"BASE");
00072 iData = KTextBase;
00073 }
00074
00075 TBool CArrayElement::operator==(const CArrayElement& aElement) const
00076 {
00077 return (iData == aElement.iData);
00078 }
00079
00080
00081
00082
00083
00084 class CElement : public CBase
00085 {
00086 public :
00087 CElement();
00088 ~CElement();
00089 void SetTextL(const TDesC& aText);
00090 public :
00091 HBufC* iBuf;
00092 };
00093
00094 CElement::CElement()
00095 {
00096 }
00097
00098 CElement::~CElement()
00099 {
00100 delete iBuf;
00101 }
00102
00107 void CElement::SetTextL(const TDesC& aText)
00108 {
00109 if (!iBuf)
00110 {
00111
00112
00113
00114 iBuf = HBufC::NewL(aText.Length());
00115 }
00116
00117 else if(iBuf->Length() != aText.Length() )
00118 {
00119
00120 iBuf = iBuf->ReAllocL(aText.Length());
00121 }
00122
00123 *iBuf = aText;
00124 }
00125
00126 TInt Order64Bit(const TInt64& aLeft, const TInt64& aRight)
00127 {
00128 if (aLeft<aRight)
00129 return -1;
00130 if (aLeft==aRight)
00131 return 0;
00132 return 1;
00133 }
00134
00141 class TIntPtrElement
00142 {
00143 public :
00144 TIntPtrElement();
00145 void SetIntPtr(TInt* aPtr);
00146 public :
00147 TBuf<4> iData;
00152 TInt* iIntPtr;
00153 };
00154
00158 TIntPtrElement::TIntPtrElement()
00159 {
00160 _LIT(KTextBase,"BASE");
00161 iData = KTextBase;
00162 }
00163
00168 void TIntPtrElement::SetIntPtr(TInt* aPtr)
00169 {
00170 iIntPtr = aPtr;
00171 }
00179 class TKeyTIntPtr : public TKeyArrayFix
00180 {
00181 public:
00182 TKeyTIntPtr(TInt aOffset, TKeyCmpText aType);
00183 TKeyTIntPtr(TInt aOffset, TKeyCmpNumeric aType);
00184 TAny* At(TInt aIndex);
00185 };
00186
00192 TKeyTIntPtr::TKeyTIntPtr(TInt aOffset, TKeyCmpText aType):TKeyArrayFix(aOffset,aType)
00193 {
00194 }
00195
00200 TKeyTIntPtr::TKeyTIntPtr(TInt aOffset, TKeyCmpNumeric aType):TKeyArrayFix(aOffset,aType)
00201 {
00202 }
00203
00210 TAny* TKeyTIntPtr::At(TInt aIndex)
00211 {
00212 if (aIndex==KIndexPtr)
00213 {
00214 return((TUint8 *)iPtr+iKeyOffset);
00215 }
00216
00217 TIntPtrElement* ptr = (TIntPtrElement *)(iBase->Ptr(aIndex*sizeof(TIntPtrElement)).Ptr()+iKeyOffset);
00218
00219
00220 return(ptr->iIntPtr);
00221 }
00222
00227 void PrintFixIntPtrArray(CArrayFixFlat<TIntPtrElement>& aFixFlat)
00228 {
00229 _LIT(KMsgContentsIntPtr,"Contents of the array of TIntPtrElement objects.\n");
00230 console->Printf(KMsgContentsIntPtr);
00231 for (TInt forix = 0; forix < aFixFlat.Count(); forix++)
00232 {
00233 console->Printf(KMsgNewLine);
00234 _LIT(KMsgBuf,"Index: %d\n Descriptor:");
00235 console->Printf(KMsgBuf,forix);
00236 console->Printf(aFixFlat[forix].iData);
00237 _LIT(KMsgInt,"\t\tInteger Value: %d");
00238 console->Printf(KMsgInt,*(aFixFlat[forix].iIntPtr));
00239 }
00240 console->Printf(KMsgNewLine);
00241 }
00242
00247 void PrintFixArray(CArrayFixFlat<TElement>& aFixFlat)
00248 {
00249 for (TInt forix = 0; forix < aFixFlat.Count(); forix++)
00250 {
00251 console->Printf(KMsgNewLine);
00252 console->Printf(aFixFlat[forix].iData);
00253 }
00254 console->Printf(KMsgNewLine);
00255 }
00256
00261 void PrintPtrArray(CArrayPtrFlat<CElement>* aPtrFlat)
00262 {
00263 _LIT(KCommonFormat4,"\n%S");
00264 for (TInt forix = 0; forix < aPtrFlat->Count(); forix++)
00265 {
00266 console->Printf(KCommonFormat4,((*aPtrFlat)[forix])->iBuf);
00267 }
00268 }
00269
00273 class TMySwap : public TSwap
00274 {
00275 public:
00276 TMySwap(CArrayFixFlat<TElement>* aArray);
00277 void Swap(TInt aLeft,TInt aRight);
00278 private:
00279
00280 CArrayFixFlat<TElement>* iArray;
00281 };
00282
00286 TMySwap::TMySwap(CArrayFixFlat<TElement>* aArray):iArray(aArray)
00287 {
00288 }
00289
00295 void TMySwap::Swap(TInt aLeft,TInt aRight)
00296 {
00297 TBuf<4> tbuf(iArray->At(aLeft).iData);
00298 iArray->At(aLeft).iData.Copy(iArray->At(aRight).iData);
00299 iArray->At(aRight).iData.Copy(tbuf);
00300 }
00301
00307 void DemoPakArrayFindL(CArrayPak<TText>& aPakFlat)
00308 {
00309
00310
00311
00312
00313
00314 aPakFlat.AppendL(*firstElement,(User::StringLength(firstElement)+1)*sizeof(TText));
00315
00316
00317 aPakFlat.AppendL(*secondElement,(User::StringLength(secondElement)+1)*sizeof(TText));
00318
00319
00320 aPakFlat.AppendL(*thirdElement,(User::StringLength(thirdElement)+1)*sizeof(TText));
00321
00322
00323 _LIT(KCommonFormat7,"Array Contents");
00324 console->Printf(KCommonFormat7);
00325 console->Printf(KMsgPressAnyKey);
00326 console->Getch();
00327
00328 TInt length = aPakFlat.Count();
00329 for(TInt ix = 0; ix < length; ix++)
00330 {
00331 console->Printf(TPtrC(&aPakFlat[ix]));
00332 console->Printf(KMsgNewLine);
00333 }
00334
00335
00336 _LIT(KMsgFind,"\n--->Find");
00337 console->Printf(KMsgFind);
00338 _LIT(KMsgFindElement,"\nSearching the array for:");
00339 console->Printf(KMsgFindElement);
00340
00341
00342
00343 console->Printf(TPtrC(thirdElement));
00344
00345
00346
00347
00348 TKeyArrayPak keypak(0,ECmpNormal,12);
00349
00350
00351 TInt index = -1;
00352
00353
00354 if(aPakFlat.Find(*thirdElement,keypak,index) == 0)
00355 {
00356
00357
00358 _LIT(KElementFound,"\nElement found at %d\n");
00359 console->Printf(KElementFound,index);
00360 }
00361 else
00362 {
00363
00364
00365 _LIT(KElementNotFound,"\nElement not found");
00366 console->Printf(KElementNotFound);
00367 }
00368 }
00369
00375 void DemoVarArraySortL(CArrayVar<TText>& aVarFlat)
00376 {
00377
00378
00379
00380
00381
00382 aVarFlat.AppendL(*firstElement,(User::StringLength(firstElement)+1)*sizeof(TText));
00383
00384
00385 aVarFlat.AppendL(*secondElement,(User::StringLength(secondElement)+1)*sizeof(TText));
00386 aVarFlat.AppendL(*thirdElement,(User::StringLength(thirdElement)+1)*sizeof(TText));
00387
00388
00389 _LIT(KCommonFormat6,"Array Contents [Before Sort]");
00390 console->Printf(KCommonFormat6);
00391
00392 console->Printf(KMsgPressAnyKey);
00393 console->Getch();
00394
00395 TInt length = aVarFlat.Count();
00396 for(TInt ix = 0; ix < length; ix++)
00397 {
00398 console->Printf(TPtrC(&aVarFlat[ix]));
00399 console->Printf(KMsgNewLine);
00400 }
00401
00402
00403
00404
00405 TKeyArrayVar keyvar(0,ECmpFolded,12);
00406
00407
00408 aVarFlat.Sort(keyvar);
00409
00410
00411 _LIT(KMsgSort,"\n--->Sort");
00412 console->Printf(KMsgSort);
00413 console->Printf(KMsgPressAnyKey);
00414 console->Getch();
00415
00416 for(TInt ix = 0; ix < length; ix++)
00417 {
00418 console->Printf(TPtrC(&aVarFlat[ix]));
00419 console->Printf(KMsgNewLine);
00420 }
00421 }
00426 void DemoFlatArrayL(CArrayFixFlat<TElement>& aFixFlat)
00427 {
00428 TElement theElement;
00429
00430 TInt value;
00431 for (value = 0; value < 3; value++)
00432 {
00433 theElement.iData.Format(KFormat1,value);
00434 aFixFlat.AppendL(theElement);
00435 }
00436
00437
00438
00439
00440 _LIT(KCommonFormat2,"\nLength()=%d");
00441 console->Printf(KCommonFormat2,aFixFlat.Length());
00442
00443
00444 _LIT(KCommonFormat3,"\nCount()=%d");
00445 console->Printf(KCommonFormat3,aFixFlat.Count());
00446
00447
00448 PrintFixArray(aFixFlat);
00449
00450
00451
00452 _LIT(KMsgInsert,"\n\n--->InsertL");
00453 console->Printf(KMsgInsert);
00454 _LIT(KMsgPressAnyKey," (press any key to continue)\n");
00455 console->Printf(KMsgPressAnyKey);
00456 console->Getch();
00457
00458
00459
00460 _LIT(KMsgBEG,"BEG");
00461 theElement.iData = KMsgBEG;
00462 aFixFlat.InsertL(0,theElement);
00463
00464
00465 _LIT(KMsgMID,"MID");
00466 theElement.iData = KMsgMID;
00467 aFixFlat.InsertL(2,theElement);
00468
00469
00470
00471 _LIT(KMsgEND,"END");
00472 theElement.iData = KMsgEND;
00473 aFixFlat.InsertL(aFixFlat.Count(),theElement);
00474
00475
00476 _LIT(KCommonFormat5,"Count()=%d");
00477 console->Printf(KCommonFormat5,aFixFlat.Count());
00478
00479
00480 PrintFixArray(aFixFlat);
00481
00482
00483
00484 TKeyArrayFix keyfix(_FOFF(TElement,iData),ECmpFolded);
00485
00486
00487 aFixFlat.Sort(keyfix);
00488
00489
00490 _LIT(KMsgSort,"\n--->Sort");
00491 console->Printf(KMsgSort);
00492 console->Printf(KMsgPressAnyKey);
00493 console->Getch();
00494
00495 PrintFixArray(aFixFlat);
00496
00497
00498
00499
00500 _LIT(KMsgDelete,"\n\n--->Delete");
00501 console->Printf(KMsgDelete);
00502 console->Printf(KMsgPressAnyKey);
00503 console->Getch();
00504
00505
00506
00507
00508
00509
00510
00511 aFixFlat.Delete(1);
00512 aFixFlat.Delete(2,2);
00513
00514 aFixFlat.Compress();
00515
00516
00517 console->Printf(KCommonFormat5,aFixFlat.Count());
00518
00519
00520 PrintFixArray(aFixFlat);
00521
00522
00523
00524 _LIT(KMsgReset,"\n\n--->Reset");
00525 console->Printf(KMsgReset);
00526 console->Printf(KMsgPressAnyKey);
00527 console->Getch();
00528
00529
00530 aFixFlat.Reset();
00531
00532
00533 console->Printf(KCommonFormat5,aFixFlat.Count());
00534
00535
00536 PrintFixArray(aFixFlat);
00537
00538
00539
00540
00541 _LIT(KMsgExpandExtend,"\n\n--->ExpandL & ExtendL");
00542 console->Printf(KMsgExpandExtend);
00543 console->Printf(KMsgPressAnyKey);
00544 console->Getch();
00545
00546
00547 _LIT(KFormat6,"%u");
00548 for (value = 0; value < 3; value++)
00549 {
00550 theElement.iData.Format(KFormat6,value);
00551 aFixFlat.AppendL(theElement);
00552 }
00553
00554
00555
00556
00557
00558 aFixFlat.ExpandL(1);
00559 aFixFlat.ExtendL();
00560
00561
00562 console->Printf(KCommonFormat5,aFixFlat.Count());
00563
00564
00565 PrintFixArray(aFixFlat);
00566
00567
00568
00569
00570 _LIT(KMsgResize,"\n\n--->ResizeL");
00571 console->Printf(KMsgResize);
00572 console->Printf(KMsgPressAnyKey);
00573 console->Getch();
00574
00575
00576
00577 aFixFlat.ResizeL(1);
00578
00579
00580
00581
00582
00583 aFixFlat.ResizeL(3);
00584
00585
00586
00587
00588
00589 _LIT(KMsgXXX,"XXX");
00590 theElement.iData = KMsgXXX;
00591 aFixFlat.ResizeL(5,theElement);
00592
00593
00594 console->Printf(KCommonFormat5,aFixFlat.Count());
00595
00596
00597 PrintFixArray(aFixFlat);
00598
00599
00600
00601
00602 _LIT(KMsgSetReserve,"\n\n--->SetReserveL");
00603 console->Printf(KMsgSetReserve);
00604 console->Printf(KMsgPressAnyKey);
00605 console->Getch();
00606
00607
00608
00609
00610
00611
00612
00613 aFixFlat.SetReserveL(5);
00614
00615
00616
00617 _LIT(KMsgDoubleAtoE,"AABBCCDDEE");
00618 TBufC<10> source(KMsgDoubleAtoE);
00619 TInt forix;
00620 for (forix = 0; forix < source.Length(); forix+=2)
00621 {
00622 theElement.iData = source.Mid(forix,2);
00623 aFixFlat.AppendL(theElement);
00624 }
00625
00626
00627 console->Printf(KCommonFormat5,aFixFlat.Count());
00628
00629
00630 PrintFixArray(aFixFlat);
00631
00632
00633
00634 TMySwap swap(&aFixFlat);
00635
00636
00637 swap.Swap(0,(aFixFlat.Count() - 1));
00638
00639
00640 _LIT(KMsgSwap,"\n--->Swap [First and Last element]");
00641 console->Printf(KMsgSwap);
00642 console->Printf(KMsgPressAnyKey);
00643 console->Getch();
00644
00645 PrintFixArray(aFixFlat);
00646 console->Printf(KMsgPressAnyKey);
00647 console->Getch();
00648 }
00649
00654 void DemoPtrArrayL(CArrayPtrFlat<CElement>& aPtrFlat)
00655 {
00656 CElement* ptr;
00657 ptr = new (ELeave) CElement;
00658 _LIT(KMsgFirstElement,"First Element");
00659 ptr->SetTextL(KMsgFirstElement);
00660 aPtrFlat.AppendL(ptr);
00661
00662
00663 ptr = new (ELeave) CElement;
00664 _LIT(KMsgSecondElement,"Second Element");
00665 ptr->SetTextL(KMsgSecondElement);
00666 aPtrFlat.AppendL(ptr);
00667
00668
00669 ptr = new (ELeave) CElement;
00670 _LIT(KMsgThirdElement,"Third Element");
00671 ptr->SetTextL(KMsgThirdElement);
00672 aPtrFlat.AppendL(ptr);
00673
00674
00675
00676 _LIT(KCommonFormat2,"\nLength()=%d");
00677 console->Printf(KCommonFormat2,aPtrFlat.Length());
00678
00679
00680 _LIT(KCommonFormat3,"\nCount()=%d");
00681 console->Printf(KCommonFormat3,aPtrFlat.Count());
00682
00683
00684 PrintPtrArray(&aPtrFlat);
00685
00686
00687
00688 _LIT(KMsgInsert,"\n\n--->InsertL");
00689 console->Printf(KMsgInsert);
00690 console->Printf(KMsgPressAnyKey);
00691 console->Getch();
00692
00693
00694
00695
00696 ptr = new (ELeave) CElement;
00697 _LIT(KMsgInsertedBeg,"Inserted @ beginning Element");
00698 ptr->SetTextL(KMsgInsertedBeg);
00699 aPtrFlat.InsertL(0,ptr);
00700
00701
00702 _LIT(KCommonFormat5,"Count()=%d");
00703 console->Printf(KCommonFormat5,aPtrFlat.Count());
00704
00705
00706 PrintPtrArray(&aPtrFlat);
00707
00708
00709
00710
00711 _LIT(KMsgDelete,"\n\n--->Delete");
00712 console->Printf(KMsgDelete);
00713 console->Printf(KMsgPressAnyKey);
00714 console->Getch();
00715
00716
00717
00718
00719
00720
00721
00722
00723
00724
00725
00726
00727
00728
00729
00730
00731
00732 TInt index = -1;
00733 index = aPtrFlat.Count();
00734
00735 ptr = aPtrFlat[--index];
00736 aPtrFlat.Delete(index);
00737 delete ptr;
00738
00739 ptr = aPtrFlat.At(--index);
00740 aPtrFlat.Delete(index);
00741 delete ptr;
00742
00743
00744 console->Printf(KCommonFormat5,aPtrFlat.Count());
00745
00746
00747 PrintPtrArray(&aPtrFlat);
00748
00749
00750
00751
00752 _LIT(KMsgAt,"\n\n--->At() and the operator []");
00753 console->Printf(KMsgAt);
00754 console->Printf(KMsgPressAnyKey);
00755 console->Getch();
00756
00757
00758 _LIT(KMsgNewTextFirst,"New text for the first CElement");
00759 _LIT(KMsgNewTextSecond,"New text for the second CElement");
00760 aPtrFlat[0]->SetTextL(KMsgNewTextFirst);
00761 aPtrFlat.At(1)->SetTextL(KMsgNewTextSecond);
00762
00763
00764 console->Printf(KCommonFormat5,aPtrFlat.Count());
00765
00766
00767 PrintPtrArray(&aPtrFlat);
00768
00769
00770
00771
00772 _LIT(KMsgResetDestroy,"\n\n--->ResetAndDestroy");
00773 console->Printf(KMsgResetDestroy);
00774 console->Printf(KMsgPressAnyKey);
00775 console->Getch();
00776
00777
00778
00779 aPtrFlat.ResetAndDestroy();
00780
00781
00782 console->Printf(KCommonFormat3,aPtrFlat.Count());
00783
00784
00785 PrintPtrArray(&aPtrFlat);
00786
00787 console->Printf(KMsgNewLine);
00788 }
00789
00795 void DemoTKeyDerivedL(CArrayFixFlat<TIntPtrElement>& aFixFlat)
00796 {
00797 TIntPtrElement theIntPtrElement;
00798
00799
00800 TInt* ptrInt1 = new(ELeave)TInt(10);
00801 CleanupStack::PushL(ptrInt1);
00802 TInt* ptrInt2 = new(ELeave)TInt(0);
00803 CleanupStack::PushL(ptrInt2);
00804 TInt* ptrInt3 = new(ELeave)TInt(5);
00805 CleanupStack::PushL(ptrInt3);
00806
00807
00808 TInt* ptrInt[3] = {ptrInt1,ptrInt2,ptrInt3};
00809
00810
00811 TInt value;
00812 for (value = 0; value < 3; value++)
00813 {
00814 theIntPtrElement.iData.Format(KFormat1,value);
00815 theIntPtrElement.SetIntPtr(ptrInt[value]);
00816 aFixFlat.AppendL(theIntPtrElement);
00817 }
00818
00819
00820 PrintFixIntPtrArray(aFixFlat);
00821
00822
00823
00824 TKeyTIntPtr keyIntPtr(_FOFF(TIntPtrElement,iIntPtr),ECmpTInt);
00825
00826 _LIT(KMsgFind,"\n--->Find");
00827 console->Printf(KMsgFind);
00828 console->Printf(KMsgPressAnyKey);
00829 console->Getch();
00830
00831
00832
00833 TInt index = -1;
00834
00835
00836 TInt res = aFixFlat.Find (
00837 theIntPtrElement,
00838
00839 keyIntPtr,
00840
00841 index
00842 );
00843
00844 if(res == 0)
00845 {
00846
00847 _LIT(KElementFound,"\nElement found at index: %d\n");
00848 console->Printf(KElementFound,index);
00849 }
00850
00851 else
00852 {
00853
00854 _LIT(KElementNotFound,"\nElement not found");
00855 console->Printf(KElementNotFound);
00856 }
00857
00858 CleanupStack::PopAndDestroy(3, ptrInt1);
00859 }
00860
00865 void DemoRArrayL(RArray<CArrayElement>& aArray)
00866 {
00867 CArrayElement arrayElement;
00868
00869
00870
00871
00872 _LIT(KMsgAppend,"\n\n--->AppendL");
00873 console->Printf(KMsgAppend);
00874
00875 console->Printf(KMsgPressAnyKey);
00876 console->Getch();
00877
00878 TInt value;
00879 for (value = 0; value < 3; value++)
00880 {
00881
00882 arrayElement.iData.Format(KFormat1,value);
00883 aArray.AppendL(arrayElement);
00884 }
00885
00886
00887 _LIT(KCommonFormat3,"\nCount()=%d");
00888 console->Printf(KCommonFormat3,aArray.Count());
00889
00890
00891 TInt forix;
00892 _LIT(KCommonFormat4,"\n%S");
00893 for (forix = 0; forix < aArray.Count(); forix++)
00894 {
00895 console->Printf(KCommonFormat4,&(aArray)[forix].iData);
00896 }
00897
00898
00899
00900
00901 _LIT(KMsgInsert,"\n\n--->InsertL");
00902 console->Printf(KMsgInsert);
00903 console->Printf(KMsgPressAnyKey);
00904 console->Getch();
00905
00906
00907
00908
00909
00910
00911
00912 _LIT(KMsgBEG,"BEG");
00913 arrayElement.iData = KMsgBEG;
00914 aArray.InsertL(arrayElement, 0);
00915
00916
00917 _LIT(KMsgMID,"MID");
00918 arrayElement.iData = KMsgMID;
00919 aArray.InsertL(arrayElement, 2);
00920
00921
00922
00923 _LIT(KMsgEND,"END");
00924 arrayElement.iData = KMsgEND;
00925 aArray.InsertL(arrayElement,aArray.Count());
00926
00927
00928 _LIT(KCommonFormat5,"Count()=%d");
00929 console->Printf(KCommonFormat5,aArray.Count());
00930
00931
00932
00933
00934 _LIT(KMsgAccess,"\n\n--->Access");
00935 console->Printf(KMsgAccess);
00936 console->Printf(KMsgPressAnyKey);
00937 console->Getch();
00938
00939
00940 for (forix = 0; forix < aArray.Count(); forix++)
00941 console->Printf(KCommonFormat4,&(aArray)[forix].iData);
00942
00943
00944
00945
00946 _LIT(KMsgDelete,"\n\n--->Delete");
00947 console->Printf(KMsgDelete);
00948 console->Printf(KMsgPressAnyKey);
00949 console->Getch();
00950
00951 TInt index2;
00952 index2 = aArray.Count();
00953
00954
00955
00956
00957
00958 arrayElement = (aArray)[--index2];
00959 aArray.Remove(index2);
00960
00961
00962 console->Printf(KCommonFormat5,aArray.Count());
00963
00964
00965 for (forix = 0; forix < aArray.Count(); forix++)
00966 console->Printf(KCommonFormat4,&(aArray)[forix].iData);
00967
00968
00969
00970
00971 _LIT(KMsgFind,"\n\n--->Find in various ways");
00972 console->Printf(KMsgFind);
00973 console->Printf(KMsgPressAnyKey);
00974 console->Getch();
00975
00976 TInt pos =0;
00977
00978
00979 arrayElement = (aArray)[--index2];
00980
00981 _LIT(KCommonFormat6,"\nElement %S is found at position %d");
00982
00983
00984 pos=aArray.Find(arrayElement, TIdentityRelation<CArrayElement>());
00985 console->Printf(KCommonFormat6, &(aArray)[pos].iData, pos);
00986
00987
00988 pos=aArray.FindReverse(arrayElement, TIdentityRelation<CArrayElement>());
00989 console->Printf(KCommonFormat6, &(aArray)[pos].iData, pos);
00990
00991
00992 pos=aArray.FindInSignedKeyOrder(arrayElement);
00993 console->Printf(KCommonFormat6,&(aArray)[pos].iData, pos);
00994
00995
00996 pos=aArray.FindInUnsignedKeyOrder(arrayElement);
00997 console->Printf(KCommonFormat6,&(aArray)[pos].iData, pos);
00998
00999
01000
01001 pos=aArray.SpecificFindInSignedKeyOrder(arrayElement, EArrayFindMode_Last);
01002 console->Printf(KCommonFormat6,&(aArray)[pos].iData, pos);
01003
01004
01005
01006 pos=aArray.SpecificFindInUnsignedKeyOrder(arrayElement, EArrayFindMode_Last);
01007 console->Printf(KCommonFormat6,&(aArray)[pos].iData, pos);
01008
01009
01010 aArray.Close();
01011 }
01012
01013 void DemoRArraySort()
01014 {
01015
01016
01017
01018 _LIT(KSortFind,"\n\n--->Sort");
01019 console->Printf(KSortFind);
01020 console->Printf(KMsgPressAnyKey);
01021 console->Getch();
01022
01023 TLinearOrder<TInt64> Int64Order(Order64Bit);
01024 TInt count=10;
01025
01026
01027
01028
01029
01030 RArray<TInt64> firstArray(count);
01031 RArray<TInt64> secondArray(count);
01032
01033 for (TInt j=0; j<count; j++)
01034 {
01035 TInt64 x=(TInt64)(((TUint)Math::Random() %count));
01036
01037 firstArray.Append(x);
01038 secondArray.InsertInOrderAllowRepeats(x,Int64Order);
01039 }
01040
01041
01042 _LIT(KInitialArrayElements,"\nInitial array elements are:");
01043 console->Printf(KInitialArrayElements);
01044
01045 _LIT(KCommonFormat7," %d");
01046 TInt forix;
01047 for (forix = 0; forix < count; forix++)
01048 console->Printf(KCommonFormat7,firstArray[forix]);
01049
01050
01051 secondArray.Sort(Int64Order);
01052
01053
01054 _LIT(KSortedArrayElements,"\nSorted array elements are:");
01055 console->Printf(KSortedArrayElements);
01056 for (forix = 0; forix < count; forix++)
01057 console->Printf(KCommonFormat7,secondArray[forix]);
01058
01059 console->Getch();
01060 console->Printf(KMsgNewLine);
01061
01062
01063 firstArray.Close();
01064 secondArray.Close();
01065 }
01066
01067 void DemoRPointerArrayL(RPointerArray<CElement>& aPointerArray)
01068 {
01069 CElement* elementptr;
01070
01071
01072
01073
01074 _LIT(KMsgAppend,"\n\n--->AppendL");
01075 console->Printf(KMsgAppend);
01076 console->Printf(KMsgPressAnyKey);
01077 console->Getch();
01078
01079
01080 elementptr = new (ELeave) CElement;
01081 _LIT(KMsgFirstElement,"First Element");
01082 elementptr->SetTextL(KMsgFirstElement);
01083 aPointerArray.AppendL(elementptr);
01084
01085
01086 elementptr = new (ELeave) CElement;
01087 _LIT(KMsgSecondElement,"Second Element");
01088 elementptr->SetTextL(KMsgSecondElement);
01089 aPointerArray.AppendL(elementptr);
01090
01091
01092 elementptr = new (ELeave) CElement;
01093 _LIT(KMsgThirdElement,"Third Element");
01094 elementptr->SetTextL(KMsgThirdElement);
01095 aPointerArray.AppendL(elementptr);
01096
01097
01098 _LIT(KCommonFormat3,"\nCount()=%d");
01099 console->Printf(KCommonFormat3,aPointerArray.Count());
01100
01101
01102 _LIT(KCommonFormat4,"\n%S");
01103 TInt forix;
01104 for (forix = 0; forix < aPointerArray.Count(); forix++)
01105 {
01106 console->Printf(KCommonFormat4,aPointerArray[forix]->iBuf);
01107 }
01108
01109
01110
01111
01112 _LIT(KMsgInsert,"\n\n--->InsertL");
01113 console->Printf(KMsgInsert);
01114 console->Printf(KMsgPressAnyKey);
01115 console->Getch();
01116
01117
01118
01119
01120
01121
01122 elementptr = new (ELeave) CElement;
01123 _LIT(KMsgInsertedBeg,"Inserted @ beginning Element");
01124 elementptr->SetTextL(KMsgInsertedBeg);
01125 aPointerArray.InsertL(elementptr, 0);
01126
01127
01128 _LIT(KCommonFormat5,"Count()=%d");
01129 console->Printf(KCommonFormat5,aPointerArray.Count());
01130
01131
01132
01133
01134
01135 for (forix = 0; forix < aPointerArray.Count(); forix++)
01136 {
01137 console->Printf(KCommonFormat4,aPointerArray[forix]->iBuf);
01138 }
01139
01140
01141
01142
01143 _LIT(KMsgDelete,"\n\n--->Delete");
01144 console->Printf(KMsgDelete);
01145 console->Printf(KMsgPressAnyKey);
01146 console->Getch();
01147
01148
01149
01150
01151
01152
01153
01154
01155
01156 TInt index1;
01157 index1 = aPointerArray.Count();
01158
01159 elementptr = aPointerArray[--index1];
01160 aPointerArray.Remove(index1);
01161 delete elementptr;
01162
01163
01164 console->Printf(KCommonFormat5,aPointerArray.Count());
01165
01166
01167 for (forix = 0; forix < aPointerArray.Count(); forix++)
01168 {
01169 console->Printf(KCommonFormat4,aPointerArray[forix]->iBuf);
01170 }
01171
01172
01173
01174
01175 _LIT(KMsgFind,"\n--->Find");
01176 console->Printf(KMsgFind);
01177 console->Printf(KMsgPressAnyKey);
01178 console->Getch();
01179
01180 elementptr = aPointerArray[index1-2];
01181
01182 _LIT(KCommonFormat8,"\nElement found at position %d");
01183
01184
01185 TInt result=aPointerArray.Find(elementptr);
01186 console->Printf(KCommonFormat8, result);
01187
01188
01189 result=aPointerArray.FindReverse(elementptr);
01190 console->Printf(KCommonFormat8, result);
01191
01192
01193
01194 result=aPointerArray.FindInAddressOrder(elementptr);
01195 console->Printf(KCommonFormat8, result);
01196
01197
01198
01199
01200 _LIT(KSortFind,"\n\n--->Sort");
01201 console->Printf(KSortFind);
01202 console->Printf(KMsgPressAnyKey);
01203 console->Getch();
01204
01205
01206
01207 _LIT(KMsgResetDestroy,"\n\n--->ResetAndDestroy");
01208 console->Printf(KMsgResetDestroy);
01209 console->Printf(KMsgPressAnyKey);
01210 console->Getch();
01211
01212
01213
01214 aPointerArray.ResetAndDestroy();
01215 }
01216
01217 void DemoSortRPointerArray()
01218 {
01219
01220
01221
01222 RPointerArray<TAny> firstpointerarray;
01223 RPointerArray<TAny> secondpointerarray;
01224
01225 TInt count = 10;
01226 for (TInt i=0; i<count; i++)
01227 {
01228 TAny* x=(TAny*)(((TUint)Math::Random() %count));
01229 firstpointerarray.Append(x);
01230 secondpointerarray.InsertInAddressOrderAllowRepeats(x);
01231 }
01232
01233
01234 _LIT(KInitialArrayElements,"\nInitial array elements are:");
01235 console->Printf(KInitialArrayElements);
01236
01237 _LIT(KCommonFormat7,"Array Contents %d \n");
01238 TInt forix;
01239 for (forix = 0; forix < count; forix++)
01240 {
01241 console->Printf(KCommonFormat7,firstpointerarray[forix]);
01242 }
01243
01244
01245 secondpointerarray.SortIntoAddressOrder();
01246
01247
01248 _LIT(KSortedArrayElements,"\nSorted array elements are:");
01249 console->Printf(KSortedArrayElements);
01250 for (forix = 0; forix < count; forix++)
01251 {
01252 console->Printf(KCommonFormat7,secondpointerarray[forix]);
01253 }
01254
01255
01256 firstpointerarray.Close();
01257 secondpointerarray.Close();
01258 }
01259
01260 LOCAL_C void doExampleL()
01261 {
01262
01263
01264
01265
01266
01267 CArrayFixFlat<TElement>* fixflat;
01268
01269
01270
01271
01272 fixflat = new (ELeave) CArrayFixFlat<TElement>(3);
01273 CleanupStack::PushL(fixflat);
01274
01275
01276 DemoFlatArrayL(*fixflat);
01277
01278
01279 CleanupStack::PopAndDestroy(fixflat);
01280
01281
01282
01283
01284 _LIT(KMsgArrayOfPointers,"\nARRAYS OF POINTERS (to CBase derived objects)\n");
01285 console->Printf(KMsgArrayOfPointers);
01286
01287 CArrayPtrFlat<CElement>* ptrflat;
01288
01289
01290
01291
01292
01293 ptrflat = new (ELeave) CArrayPtrFlat<CElement>(16);
01294 CleanupStack::PushL(ptrflat);
01295
01296
01297 DemoPtrArrayL(*ptrflat);
01298
01299
01300 CleanupStack::PopAndDestroy(ptrflat);
01301
01302
01303
01304
01305
01306 _LIT(KMsgVarArray,"\n\nVAR ARRAY\n\n");
01307 console->Printf(KMsgVarArray);
01308
01309
01310 CArrayVarFlat<TText>* varflat = new (ELeave) CArrayVarFlat<TText>(3);
01311 CleanupStack::PushL(varflat);
01312
01313
01314 DemoVarArraySortL(*varflat);
01315
01316
01317 CleanupStack::PopAndDestroy(varflat);
01318
01319 _LIT(KMsgPakArray,"\n\nPAK ARRAY\n\n");
01320 console->Printf(KMsgPakArray);
01321
01322
01323 CArrayPakFlat<TText>* pakflat = new (ELeave) CArrayPakFlat<TText>(3);
01324 CleanupStack::PushL(pakflat);
01325
01326
01327 DemoPakArrayFindL(*pakflat);
01328
01329
01330 CleanupStack::PopAndDestroy(pakflat);
01331
01332
01333
01334
01335
01336 _LIT(KMsgTKeyDerived,"\nTKEY DERIVED CLASS\n");
01337 console->Printf(KMsgPressAnyKey);
01338 console->Getch();
01339
01340 console->Printf(KMsgTKeyDerived);
01341 CArrayFixFlat<TIntPtrElement>* ptrElementArray;
01342
01343
01344
01345
01346 ptrElementArray = new (ELeave) CArrayFixFlat<TIntPtrElement>(3);
01347 CleanupStack::PushL(ptrElementArray);
01348
01349
01350 DemoTKeyDerivedL(*ptrElementArray);
01351
01352 CleanupStack::PopAndDestroy(ptrElementArray);
01353
01354
01355
01356
01357
01358 _LIT(KMsgForRArray,"\n*******Arrays of fixed length objects******");
01359 console->Printf(KMsgForRArray);
01360
01361 RArray<CArrayElement>* array;
01362
01363
01364
01365
01366
01367
01368
01369
01370 array = new (ELeave) RArray<CArrayElement>(16);
01371 CleanupStack::PushL(array);
01372
01373 DemoRArrayL(*array);
01374
01375 CleanupStack::PopAndDestroy(array);
01376
01377 DemoRArraySort();
01378
01379
01380
01381
01382
01383
01384 _LIT(KMsgForRPointerArray,"\n*******Array of pointers to objects******");
01385 console->Printf(KMsgForRPointerArray);
01386
01387 RPointerArray<CElement>* ptrarray;
01388
01389
01390
01391
01392
01393
01394 ptrarray = new (ELeave) RPointerArray<CElement>(16);
01395 CleanupStack::PushL(array);
01396
01397 DemoRPointerArrayL(*ptrarray);
01398 CleanupStack::PopAndDestroy(ptrarray);
01399
01400 DemoSortRPointerArray();
01401 }
01402