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