00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016 #include <f32file.h>
00017 #include <e32cons.h>
00018 #include <euserhl.h>
00019
00020
00021 _LIT(KTxtExample,"EUsableExample\n");
00022 _LIT(KTxtPressAnyKeyToContinue,"Press any key to continue\n");
00023
00024 CConsoleBase* gConsole;
00025
00032 _LIT(KPath, "c:\\a\\b\\c");
00033 _LIT(KOne, "One ");
00034 _LIT(KTwo, "Two ");
00035 _LIT(KTesting, "Testing ");
00036
00037 void MaybeLeave()
00038 {
00039
00040 }
00041
00042 HBufC* AllocateNameL(const TDesC& aDes)
00043 {
00044 return aDes.AllocL();
00045 }
00046
00047 void GetCurrentPath(TDes& aDes)
00048 {
00049 aDes = KPath;
00050 }
00051
00052 void GetCurrentPathString(LString& aString)
00053 {
00054 aString = KPath;
00055 }
00056
00057 LString AppendCurrentPathStringL(LString aString)
00058 {
00059
00060
00061
00062
00063 LString result(aString);
00064 result += KPath;
00065 return result;
00066 }
00067
00068 class CTicker : public CBase
00069 {
00070 public:
00071 void Tick() { ++iTicks; }
00072 void Tock() { ++iTocks; }
00073
00074 void Zap() { delete this; }
00075
00076 public:
00077 TInt iTicks;
00078 TInt iTocks;
00079 };
00080
00081
00082 class TTickerZapStrategy
00083 {
00084 public:
00085 static void Cleanup(CTicker* aPtr)
00086 {
00087
00088
00089
00090
00091 aPtr->Zap();
00092 _LIT(KTxtPrintZapp, "Zapped CTicker\n");
00093 gConsole->Printf(KTxtPrintZapp);
00094 }
00095 };
00096
00097 void RegisterTicker(CTicker& aTicker)
00098 {
00099 (void)aTicker;
00100 }
00101
00102 void RegisterTickerPtr(CTicker* aTicker)
00103 {
00104 (void)aTicker;
00105 }
00106
00107 void TakeTickerOwnership(CTicker* aTicker)
00108 {
00109 delete aTicker;
00110 }
00111
00112 void RegisterTimer(RTimer& aTimer)
00113 {
00114 (void)aTimer;
00115 }
00116
00117
00118 class TCancelClose
00119 {
00120 public:
00121 template <class T>
00122 static void Cleanup(T* aHandle)
00123 {
00124
00125
00126
00127
00128 aHandle->Cancel();
00129 aHandle->Close();
00130 _LIT(KTxtCancel,"Cancel Closed RTimer\n");
00131 gConsole->Printf(KTxtCancel);
00132 }
00133 };
00134
00135 void BespokeCleanupFunction(TAny* )
00136 {
00137 _LIT(KTxtCleanup,"BespokeCleanupFunction\n");
00138 gConsole->Printf(KTxtCleanup);
00139 }
00140
00141
00142
00149 class CStringUserTwoPhase : public CBase
00150 {
00151 public:
00152 static CStringUserTwoPhase* NewL(const TDesC& aName)
00153 {
00154
00155
00156
00157
00158 LCleanedupPtr<CStringUserTwoPhase> self(new(ELeave) CStringUserTwoPhase);
00159 self->Construct(aName);
00160
00161
00162
00163
00164
00165 return self.Unmanage();
00166 }
00167
00168 virtual void Construct(const TDesC& aName)
00169 {
00170
00171
00172
00173
00174 iName = aName;
00175 }
00176
00177 ~CStringUserTwoPhase()
00178 {
00179
00180 }
00181
00182 const TDesC& Name()
00183 {
00184
00185 return iName;
00186 }
00187
00188 protected:
00189 CStringUserTwoPhase()
00190 {
00191
00192
00193
00194
00195
00196
00197
00198
00199
00200 }
00201
00202 protected:
00203 LString iName;
00204 };
00205
00217 class CStringUserSinglePhase : public CBase
00218 {
00219 public:
00220
00221
00222
00223
00224
00225 CONSTRUCTORS_MAY_LEAVE
00226
00227 static CStringUserSinglePhase* NewL(const TDesC& aName)
00228 {
00229 return new(ELeave) CStringUserSinglePhase(aName);
00230 }
00231
00232 ~CStringUserSinglePhase()
00233 {
00234
00235 }
00236
00237 const TDesC& Name()
00238 {
00239
00240 return iName;
00241 }
00242
00243 protected:
00244 CStringUserSinglePhase(const TDesC& aName)
00245
00246
00247
00248
00249
00250 : iName(aName)
00251 {
00252
00253
00254
00255
00256
00257
00258 MaybeLeave();
00259 }
00260
00261 protected:
00262 LString iName;
00263 };
00264
00265
00266 void WalkthroughStringsL()
00267 {
00268 _LIT(KTxtOption1,"Option1: String handling using EUser high level library\n");
00269 gConsole->Printf(KTxtOption1);
00270 _LIT(KTxtFormatString,"String %d");
00271 _LIT(KTxtPrintString,"String %d = %S\n");
00272 {
00273
00274
00275 LCleanedupPtr<CStringUserTwoPhase> one(CStringUserTwoPhase::NewL(KOne));
00276 _LIT(KTxtSinglePhaseConstructor,"Single phase name: %S\n");
00277 gConsole->Printf(KTxtSinglePhaseConstructor, &one->Name());
00278
00279 LCleanedupPtr<CStringUserSinglePhase> two(CStringUserSinglePhase::NewL(KTwo));
00280 _LIT(KTxtTwoPhaseConstructor,"Single phase name: %S\n");
00281 gConsole->Printf(KTxtTwoPhaseConstructor, &two->Name());
00282
00283 gConsole->Printf(KTxtPressAnyKeyToContinue);
00284 gConsole->Getch();
00285
00286 }
00287
00288 {
00289
00290
00291
00292
00293
00294 LString s;
00295
00296
00297
00298
00299
00300
00301 s = KOne;
00302
00303
00304
00305
00306
00307 s.AppendL(KTwo);
00308
00309
00310 _LIT(KThree, "Three ");
00311 s += KThree;
00312
00313
00314
00315
00316
00317 s.AppendFormatL(KTesting);
00318
00319
00320
00321
00322
00323
00324
00325
00326
00327
00328
00329
00330
00331 _LIT(KTxtValue,"Value: %S\n");
00332 gConsole->Printf(KTxtValue, &s);
00333
00334
00335 _LIT(KTxtLStringCompare," Comparing LString with a literal is successful\n");
00336 _LIT(KPhrase, "One Two Three Testing ");
00337 if(s == KPhrase)
00338 {
00339 gConsole->Printf(KTxtLStringCompare);
00340 }
00341
00342
00343 _LIT(KTxtLStringSupportedAPI1,"LString supports TDesC and TDes methods\n");
00344 if(s.Find(KTwo) == 4)
00345 {
00346 gConsole->Printf(KTxtLStringSupportedAPI1);
00347 }
00348
00349 _LIT(KTxtLStringSupportedAPI2,"LString supports TDesC and TDes operators\n");
00350 if(s[4] == TChar('T'))
00351 {
00352 gConsole->Printf(KTxtLStringSupportedAPI2);
00353 }
00354 TInt untrimmed = s.Length();
00355 s.Trim();
00356 if(s.Length() == untrimmed - 1)
00357 {
00358
00359 }
00360
00361 s.UpperCase();
00362 _LIT(KTxtPrintUpperCase,"UpperCase: %S\n");
00363 gConsole->Printf(KTxtPrintUpperCase, &s);
00364 s.LowerCase();
00365 _LIT(KTxtPrintLowerCase,"UpperCase: %S\n");
00366 gConsole->Printf(KTxtPrintLowerCase, &s);
00367 gConsole->Printf(KTxtPressAnyKeyToContinue);
00368 gConsole->Getch();
00369
00370
00371
00372
00373
00374 }
00375
00376 {
00377
00378 LString s(KMaxFileName);
00379 if(s.MaxLength() == KMaxFileName)
00380 {
00381
00382 }
00383
00384
00385
00386
00387
00388
00389
00390
00391 s.SetMaxLengthL(2 * KMaxFileName);
00392 if(s.MaxLength() == 2 * KMaxFileName)
00393 {
00394
00395 }
00396
00397
00398
00399
00400
00401
00402
00403 }
00404
00405 {
00406
00407
00408
00409
00410 LString s(KOne);
00411 s += KTwo;
00412 LString half(s.Left(s.Length() / 2));
00413 _LIT(KTxtPrintAllandHalf,"All: %S, Half: %S\n");
00414 gConsole->Printf(KTxtPrintAllandHalf, &s, &half);
00415
00416
00417
00418
00419
00420 LString own(AllocateNameL(KTesting));
00421 _LIT(KTxtOwnedString,"What I own: %S\n");
00422 gConsole->Printf(KTxtOwnedString, &own);
00423
00424
00425
00426
00427
00428
00429 own = AllocateNameL(KTesting);
00430
00431
00432
00433
00434
00435
00436 own.Assign(AllocateNameL(KTesting));
00437
00438
00439
00440
00441
00442
00443 own.Assign(s);
00444
00445
00446
00447
00448
00449
00450 RBuf16 buf;
00451 buf.CreateL(KOne);
00452 own.Assign(buf);
00453
00454
00455
00456
00457
00458 own.Assign((TText*)User::Alloc(24*(TInt)sizeof(TText)), 24);
00459
00460
00461
00462
00463
00464 own.Assign((TText*)User::Alloc(24*(TInt)sizeof(TText)), 12,24);
00465 gConsole->Printf(KTxtPressAnyKeyToContinue);
00466 gConsole->Getch();
00467
00468
00469
00470
00471
00472
00473 }
00474
00475 {
00476
00477
00478
00479
00480
00481
00482 LString s(KOne);
00483 s.ReserveFreeCapacityL(4);
00484 if(s.Length() == 4)
00485 {
00486
00487 }
00488 if(s.MaxLength() >= 8)
00489 {
00490
00491 }
00492
00493
00494
00495
00496
00497
00498
00499
00500
00501
00502
00503
00504
00505
00506 s.Compress();
00507 if(s.MaxLength() >= 4)
00508 {
00509
00510 }
00511
00512
00513
00514
00515
00516
00517
00518
00519
00520
00521
00522 s.Reset();
00523 if(s.Length() == 0)
00524 {
00525
00526 }
00527 if(s.MaxLength() == 0)
00528 {
00529
00530 }
00531
00532 }
00533
00534 {
00535
00536
00537
00538
00539 TInt year = 2009;
00540
00541 LString s;
00542 _LIT(KTxtFormatYear1,"Happy New Year %d");
00543 s.FormatL(KTxtFormatYear1, year);
00544
00545 User::InfoPrint(s);
00546
00547 LString pattern;
00548 _LIT(KTxtFormatYear2,"*Year %d");
00549 pattern.FormatL(KTxtFormatYear2, year);
00550
00551 TInt loc = s.Match(pattern);
00552 if(loc == 10)
00553 {
00554
00555 }
00556 }
00557
00558 {
00559
00560
00561
00562
00563
00564
00565
00566 LString s;
00567
00568
00569
00570
00571
00572
00573
00574 if(s.MaxLength() == 0)
00575 {
00576
00577 }
00578
00579
00580
00581
00582
00583
00584 s.SetMaxLengthL(KMaxFileName);
00585 GetCurrentPath(s);
00586 _LIT(KTxtPrintPath,"Path: %S\n");
00587 gConsole->Printf(KTxtPrintPath, &s);
00588 if(s == KPath)
00589 {
00590
00591 }
00592
00593
00594
00595
00596
00597
00598 s.SetMaxLengthL(s.Length() / 2);
00599 _LIT(KTxtTruncatedPath,"Truncated path: %S\n");
00600 gConsole->Printf(KTxtTruncatedPath, &s);
00601 if(s.Length() == s.MaxLength())
00602 {
00603
00604 }
00605
00606
00607
00608
00609
00610
00611 LString s2(KMaxFileName);
00612 GetCurrentPath(s2);
00613 gConsole->Printf(KTxtPrintPath, &s2);
00614 if(s2 == KPath)
00615 {
00616
00617 }
00618
00619
00620
00621
00622
00623
00624
00625
00626 LString s3;
00627
00628 GetCurrentPathString(s3);
00629 gConsole->Printf(KTxtPrintPath, &s3);
00630 if(s3 == KPath)
00631 {
00632
00633 }
00634
00635
00636
00637
00638
00639
00640
00641 LString s4(AppendCurrentPathStringL(s3));
00642 _LIT(KTxtAppendedPath,"Appended path: %S\n");
00643 gConsole->Printf(KTxtAppendedPath, &s4);
00644 if(s4.Length() == s3.Length() * 2)
00645 {
00646
00647 }
00648 }
00649
00650 {
00651
00652
00653
00654
00655 TInt n = 5;
00656 LCleanedupHandle<RPointerArray<LString>, TResetAndDestroy> sarray;
00657
00658 for (TInt i = 0; i < n; ++i)
00659 {
00660 LString* s = new(ELeave) LString;
00661 s->FormatL(KTxtFormatString, i);
00662 sarray->Append(s);
00663 }
00664
00665 for (TInt i = 0, n = sarray->Count(); i < n; ++i)
00666 {
00667 LString tmp;
00668 tmp.FormatL(KTxtFormatString, i);
00669 if(tmp == *(*sarray)[i])
00670 {
00671
00672 }
00673 gConsole->Printf(KTxtPrintString, i, (*sarray)[i]);
00674 }
00675
00676 }
00677
00678 {
00679
00680
00681
00682
00683
00684 __UHEAP_MARK;
00685 TRAPD(status, new(ELeave) LString(100 * 1024 * 1024));
00686 if(status == KErrNoMemory)
00687 {
00688
00689 }
00690 __UHEAP_MARKEND;
00691 }
00692
00693 {
00694
00695
00696
00697
00698
00699 TInt n = 5;
00700 LCleanedupArray<LString> sarray(new(ELeave) LString[n]);
00701
00702 for (TInt i = 0; i < n; ++i)
00703 {
00704 sarray[i].FormatL(KTxtFormatString, i);
00705 }
00706
00707 for (TInt i = 0; i < n; ++i)
00708 {
00709 LString tmp;
00710 tmp.FormatL(KTxtFormatString, i);
00711 if(tmp == sarray[i])
00712 {
00713
00714 }
00715 gConsole->Printf(KTxtPrintString, i, &sarray[i]);
00716 }
00717
00718 }
00719
00720 }
00721
00727 class CManagedUserTwoPhase : public CBase
00728 {
00729 public:
00730 static CManagedUserTwoPhase* NewL(CTicker* aTicker)
00731 {
00732
00733
00734
00735
00736 LCleanedupPtr<CManagedUserTwoPhase> self(new(ELeave) CManagedUserTwoPhase);
00737 self->ConstructL(aTicker);
00738
00739
00740
00741
00742
00743 return self.Unmanage();
00744 }
00745
00746 ~CManagedUserTwoPhase()
00747 {
00748
00749
00750
00751
00752 }
00753
00754 CTicker& Ticker()
00755 {
00756
00757 return *iTicker;
00758 }
00759
00760 RTimer& Timer()
00761 {
00762
00763 return *iTimer;
00764 }
00765
00766 private:
00767
00768 virtual void ConstructL(CTicker* aTicker)
00769 {
00770
00771 iTicker = aTicker;
00772
00773
00774 iTimer->CreateLocal() OR_LEAVE;
00775 }
00776
00777 CManagedUserTwoPhase()
00778 {
00779
00780
00781
00782
00783
00784
00785
00786
00787
00788 }
00789
00790 private:
00791
00792 LManagedPtr<CTicker> iTicker;
00793 LManagedHandle<RTimer> iTimer;
00794 };
00795
00808 class CManagedUserSinglePhase : public CBase
00809 {
00810 public:
00811
00812
00813
00814
00815
00816 CONSTRUCTORS_MAY_LEAVE
00817
00818 static CManagedUserSinglePhase* NewL(CTicker* aTicker)
00819 {
00820 return new(ELeave) CManagedUserSinglePhase(aTicker);
00821 }
00822
00823 ~CManagedUserSinglePhase()
00824 {
00825
00826
00827
00828
00829 }
00830
00831 CTicker& Ticker()
00832 {
00833
00834 return *iTicker;
00835 }
00836
00837 RTimer& Timer()
00838 {
00839
00840 return *iTimer;
00841 }
00842
00843 private:
00844 CManagedUserSinglePhase(CTicker* aTicker)
00845
00846
00847
00848
00849
00850 : iTicker(aTicker)
00851 {
00852
00853
00854
00855
00856
00857
00858
00859
00860 iTimer->CreateLocal();
00861
00862
00863
00864 MaybeLeave();
00865 }
00866
00867 private:
00868
00869 LManagedPtr<CTicker, TTickerZapStrategy> iTicker;
00870 LManagedHandle<RTimer> iTimer;
00871 };
00872
00873
00874 class RSimple
00875 {
00876 public:
00877
00878 RSimple(){iData = NULL;}
00879
00880
00881 void OpenL(TInt aValue)
00882 {
00883 iData = new(ELeave) TInt(aValue);
00884 }
00885
00886
00887 void Close()
00888 {
00889 delete iData;
00890 iData = NULL;
00891 }
00892
00893
00894 void Free()
00895 {
00896 delete iData;
00897 iData = NULL;
00898 }
00899
00900
00901 void ReleaseData()
00902 {
00903 delete iData;
00904 iData = NULL;
00905 }
00906
00907
00908 static void Cleanup(TAny* aRSimple)
00909 {
00910 static_cast<RSimple*>(aRSimple)->Close();
00911 }
00912
00913
00914 private:
00915 TInt* iData;
00916
00917 };
00918
00919
00926 DEFINE_CLEANUP_FUNCTION(RSimple, ReleaseData);
00927
00928
00929 void WalkthroughManagedL()
00930 {
00931 _LIT(KTxtOption2,"Option2: Object creation and resource management using EUser high level library\n");
00932 gConsole->Printf(KTxtOption2);
00933 {
00934
00935 CTicker* ticker1 = new(ELeave) CTicker;
00936 LCleanedupPtr<CManagedUserTwoPhase> one(CManagedUserTwoPhase::NewL(ticker1));
00937 if(&one->Ticker() == ticker1)
00938 {
00939 _LIT(KTxtLCleanedupPtrDemo1,"Creating an instance of CTicker using LCleanedupPtr\n");
00940 gConsole->Printf(KTxtLCleanedupPtrDemo1);
00941 }
00942 one->Timer().Cancel();
00943
00944 CTicker* ticker2 = new(ELeave) CTicker;
00945 LCleanedupPtr<CManagedUserSinglePhase> two(CManagedUserSinglePhase::NewL(ticker2));
00946 if(&two->Ticker() == ticker2)
00947 {
00948 _LIT(KTxtLCleanedupPtrDemo2,"Creating second instance of CTicker using LCleanedupPtr\n");
00949 gConsole->Printf(KTxtLCleanedupPtrDemo2);
00950 }
00951 two->Timer().Cancel();
00952 _LIT(KTxtLCleanedupPtr,"Both instances are automatically deleted as we go out of scope\n");
00953 gConsole->Printf(KTxtLCleanedupPtr);
00954 gConsole->Printf(KTxtPressAnyKeyToContinue);
00955 gConsole->Getch();
00956 }
00957
00958
00959
00960 {
00961
00962
00963
00964
00965
00966
00967 LCleanedupPtr<CTicker> t(new(ELeave) CTicker);
00968
00969
00970
00971
00972
00973 t->Tick();
00974 t->Tock();
00975 if(t->iTicks == t->iTocks)
00976 {
00977 _LIT(KTxtLCleanedupPtrDemo3,"CTicker members access using LCleanedupPtr is successful\n");
00978 gConsole->Printf(KTxtLCleanedupPtrDemo3);
00979 gConsole->Printf(KTxtPressAnyKeyToContinue);
00980 gConsole->Getch();
00981 }
00982
00983
00984
00985
00986
00987 RegisterTicker(*t);
00988
00989
00990
00991
00992
00993 RegisterTickerPtr(&*t);
00994 RegisterTickerPtr(t.Get());
00995
00996
00997
00998
00999
01000
01001
01002
01003
01004
01005 }
01006
01007 {
01008
01009
01010
01011
01012
01013
01014 LCleanedupPtr<CTicker> t(new(ELeave) CTicker);
01015
01016
01017 MaybeLeave();
01018
01019
01020
01021
01022
01023 TakeTickerOwnership(t.Unmanage());
01024
01025
01026
01027
01028
01029 }
01030
01031 {
01032
01033
01034
01035
01036
01037
01038 LCleanedupPtr<CTicker> t;
01039 if(t.Get() == NULL)
01040 {
01041
01042 }
01043 if(&*t == NULL)
01044 {
01045
01046 }
01047
01048 for (TInt i = 0; i < 10; ++i)
01049 {
01050
01051
01052
01053
01054 t = new(ELeave) CTicker;
01055 }
01056
01057
01058
01059
01060 }
01061
01062 {
01063
01064 LCleanedupPtr<CTicker> t(new(ELeave) CTicker);
01065
01066
01067 if (!t)
01068 {
01069 _LIT(KTxtNull,"LCleanedupPtr object refers to Null\n" );
01070 gConsole->Printf(KTxtNull);
01071 }
01072
01073 t = NULL;
01074
01075
01076 if (t)
01077 {
01078 _LIT(KTxtNonNull,"LCleanedupPtr object refers to Non Null pointer\n" );
01079 gConsole->Printf(KTxtNonNull);
01080 }
01081 }
01082
01083 {
01084
01085
01086
01087 LCleanedupPtr<CTicker, TPointerFree> t(static_cast<CTicker*>(User::AllocL(sizeof(CTicker))));
01088
01089
01090 }
01091
01092 {
01093
01094
01095
01096
01097
01098 LCleanedupPtr<CTicker, TTickerZapStrategy> t(new(ELeave) CTicker);
01099
01100
01101 }
01102
01103 {
01104
01105
01106
01107
01108
01109
01110 LCleanedupHandle<RTimer> t;
01111
01112
01113 t->CreateLocal() OR_LEAVE;
01114 t->Cancel();
01115
01116
01117 RegisterTimer(*t);
01118
01119
01120
01121
01122
01123
01124 }
01125
01126 {
01127
01128
01129
01130
01131
01132
01133
01134 LCleanedupHandle<RPointerArray<HBufC>, TResetAndDestroy> array;
01135 for (TInt i = 0; i < 10; ++i)
01136 {
01137 array->AppendL(HBufC::NewL(5));
01138 }
01139
01140
01141 }
01142
01143 {
01144
01145
01146
01147
01148 LCleanedupHandle<RTimer, TCancelClose> t;
01149 t->CreateLocal();
01150
01151
01152 }
01153
01154
01155 {
01156
01157
01158
01159
01160
01161
01162
01163 RPointerArray<HBufC> rar;
01164
01165 rar.Append(HBufC::NewL(5));
01166 rar.Append(HBufC::NewL(5));
01167
01168
01169 LCleanedupRef<RPointerArray<HBufC>, TResetAndDestroy> array(rar);
01170
01171 for (TInt i = 0; i < 10; ++i)
01172 {
01173 array->AppendL(HBufC::NewL(5));
01174 }
01175
01176
01177 }
01178
01179 {
01180
01181
01182
01183
01184
01185
01186
01187
01188
01189
01190 HBufC* raw = HBufC::NewLC(5);
01191
01192 CleanupStack::Pop();
01193 LCleanedupPtr<HBufC> wrapped(raw);
01194
01195
01196
01197
01198
01199
01200
01201
01202
01203
01204
01205
01206
01207
01208 }
01209
01210 {
01211
01212 LCleanedupArray<CTicker> array(new CTicker[5]);
01213
01214
01215 }
01216
01217 {
01218
01219
01220
01221
01222
01223
01224 TAny* data = NULL;
01225 LCleanedupGuard guard1(BespokeCleanupFunction, data);
01226
01227
01228 LCleanedupGuard guard2(BespokeCleanupFunction, data);
01229
01230 guard2.Dismiss();
01231 }
01232
01233 {
01234 LCleanedupHandle<RFs> managedFs;
01235 managedFs->Connect();
01236
01237 }
01238
01239 {
01240 LCleanedupHandle<RSimple, TFree> simple;
01241 simple->OpenL(23);
01242
01243 }
01244
01245
01246
01247
01248
01249
01250 {
01251 LCleanedupHandle<RSimple> simple;
01252 simple->OpenL(23);
01253
01254 }
01255
01256 {
01257 RSimple simple;
01258
01259
01260
01261 LCleanedupGuard guard(RSimple::Cleanup, &simple);
01262
01263 simple.OpenL(10);
01264
01265
01266 }
01267 }
01268
01269 void WalkthroughUsageL()
01270 {
01271 _LIT(KTxtOption3,"Option3: Memory used by EUser high level classes\n");
01272 gConsole->Printf(KTxtOption3);
01273 RFile file;
01274
01275 _LIT(KTxtSizeofRFile,"Size of RFile = %d\n");
01276 gConsole->Printf(KTxtSizeofRFile, sizeof(file));
01277
01278 LCleanedupHandle<RFile> cFile;
01279
01280 _LIT(KTxtSizeofLCleanedupHandleRFile,"Size of LCleanedupHandle<RFile> = %d\n");
01281 gConsole->Printf(KTxtSizeofLCleanedupHandleRFile, sizeof(cFile));
01282 gConsole->Printf(KTxtPressAnyKeyToContinue);
01283 gConsole->Getch();
01284
01285 LCleanedupRef<RFile> crFile(file);
01286 _LIT(KTxtSizeofLCleanedupRefRFile,"Size of LCleanedupRef<RFile> = %d\n");
01287 gConsole->Printf(KTxtSizeofLCleanedupRefRFile, sizeof(crFile));
01288 gConsole->Printf(KTxtPressAnyKeyToContinue);
01289 gConsole->Getch();
01290
01291 CTicker* tracker = new(ELeave) CTicker;
01292 _LIT(KTxtSizeofCTracker,"Size of CTracker* = %d\n");
01293 gConsole->Printf(KTxtSizeofCTracker, sizeof(tracker));
01294 gConsole->Printf(KTxtPressAnyKeyToContinue);
01295 gConsole->Getch();
01296
01297 LCleanedupPtr<CTicker> cTracker(tracker);
01298 _LIT(KTxtSizeofLCleanedupHandleCTicker,"Size of LCleanedupPtr<CTicker> = %d\n");
01299 gConsole->Printf(KTxtSizeofLCleanedupHandleCTicker, sizeof(LCleanedupPtr<CTicker>));
01300 gConsole->Printf(KTxtPressAnyKeyToContinue);
01301 gConsole->Getch();
01302 }
01303
01304 TInt TestL()
01305 {
01306 gConsole=Console::NewL(KTxtExample,TSize(KConsFullScreen,KConsFullScreen));
01307 CleanupStack::PushL(gConsole);
01308 gConsole->Printf(KTxtExample);
01309 gConsole->Printf(KTxtPressAnyKeyToContinue);
01310 gConsole->Getch();
01311 WalkthroughStringsL();
01312 gConsole->Printf(KTxtPressAnyKeyToContinue);
01313 gConsole->Getch();
01314 WalkthroughManagedL();
01315 gConsole->Printf(KTxtPressAnyKeyToContinue);
01316 gConsole->Getch();
01317 WalkthroughUsageL();
01318 _LIT(KTxtPressAnyKeyToExit,"\nPress any key to exit");
01319 gConsole->Printf(KTxtPressAnyKeyToExit);
01320 gConsole->Getch();
01321 CleanupStack::PopAndDestroy(gConsole);
01322 return KErrNone;
01323 }
01324
01325 TInt E32Main()
01326 {
01327 __UHEAP_MARK;
01328 CTrapCleanup* cleanup=CTrapCleanup::New();
01329 TInt status;
01330 if(cleanup!=NULL)
01331 {
01332 TRAP(status, TestL());
01333 __ASSERT_ALWAYS(!status,User::Panic(KTxtExample,status));
01334 }
01335 delete cleanup;
01336 __UHEAP_MARKEND;
01337
01338 return status;
01339 }
01340
01341
01342