00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016 #include "CommonFramework.h"
00017
00018
00019
00020
00021
00022
00023
00024 class COnePhaser : public CBase {
00025 public:
00026 TInt iInt1;
00027 TInt iInt2;
00028 public:
00029
00030 static COnePhaser* NewL()
00031 {
00032 return new (ELeave) COnePhaser;
00033 };
00034 static COnePhaser* NewLC()
00035 {
00036 COnePhaser* self=COnePhaser::NewL();
00037 CleanupStack::PushL(self);
00038 return self;
00039 };
00040
00041 void Print()
00042 {
00043 _LIT(KFormat1,"COnePhaser {TInt %d, TInt %d}");
00044 console->Printf(KFormat1, iInt1, iInt2);
00045 }
00046 protected:
00047
00048 COnePhaser()
00049 {
00050 iInt1=3;
00051
00052 }
00053 };
00054
00055
00056
00057 class CTwoPhaser : public CBase {
00058 public:
00059 TInt iInt1;
00060 TInt iInt2;
00061 RTimer iTimer;
00062 COnePhaser* iOnePhaser;
00063 public:
00064
00065 static CTwoPhaser* NewLC(TInt aInt1)
00066 {
00067 CTwoPhaser* self=new (ELeave) CTwoPhaser;
00068 CleanupStack::PushL(self);
00069 self->ConstructL(aInt1);
00070 return self;
00071 };
00072 static CTwoPhaser* NewL(TInt aInt1)
00073 {
00074 CTwoPhaser* self=CTwoPhaser::NewLC(aInt1);
00075 CleanupStack::Pop();
00076 return self;
00077 };
00078 virtual ~CTwoPhaser()
00079 {
00080 delete iOnePhaser;
00081 iTimer.Close();
00082 }
00083
00084 void Print()
00085 {
00086 _LIT(KFormat2,"CTwoPhaser {TInt %d, TInt %d, RTimer, ");
00087 console->Printf(KFormat2, iInt1, iInt2);
00088 iOnePhaser->Print();
00089 _LIT(KtxtCloseCurly,"}");
00090 console->Printf(KtxtCloseCurly);
00091 }
00092 protected:
00093
00094 void ConstructL(TInt aInt1)
00095 {
00096 iInt1=aInt1;
00097 User::LeaveIfError(iTimer.CreateLocal());
00098 iOnePhaser=COnePhaser::NewL();
00099 }
00100 };
00101
00102
00103
00104 class CAbstract : public CBase
00105 {
00106 public:
00107 CTwoPhaser* iTwoPhaser;
00108 public:
00109 void SomeFunction(TInt aInt)
00110 {
00111 _LIT(KTxtbeginSomeFunction,"beginning to do SomeFunction()\n");
00112 console->Printf(KTxtbeginSomeFunction);
00113 DoSomeFunction(aInt);
00114 _LIT(KTxtfinishSomeFunction,"finished doing SomeFunction()\n");
00115 console->Printf(KTxtfinishSomeFunction);
00116 }
00117 virtual ~CAbstract()
00118 {
00119 delete iTwoPhaser;
00120 }
00121 protected:
00122 virtual void DoSomeFunction(TInt aInt) const =0;
00123
00124 void ConstructL(TInt aInt)
00125 {
00126 iTwoPhaser=CTwoPhaser::NewL(aInt);
00127
00128 }
00129 };
00130
00131
00132
00133 class CConcrete : public CAbstract
00134 {
00135 public:
00136 COnePhaser* iOnePhaser;
00137 public:
00138
00139 static CConcrete* NewLC(TInt aInt)
00140 {
00141 CConcrete* self=new (ELeave) CConcrete;
00142 CleanupStack::PushL(self);
00143 self->ConstructL(aInt);
00144 return self;
00145 };
00146 static CConcrete* NewL(TInt aInt)
00147 {
00148 CConcrete* self=CConcrete::NewLC(aInt);
00149 CleanupStack::Pop();
00150 return self;
00151 };
00152 virtual ~CConcrete()
00153 {
00154 delete iOnePhaser;
00155 }
00156
00157 virtual void DoSomeFunction(TInt aInt) const
00158 {
00159 _LIT(KFormat3,"CConcrete::DoSomething(%d)\n");
00160 console->Printf(KFormat3, aInt);
00161 }
00162 protected:
00163
00164 void ConstructL(TInt aInt)
00165 {
00166 CAbstract::ConstructL(aInt);
00167 iOnePhaser=COnePhaser::NewL();
00168 }
00169 };
00170
00171
00172 LOCAL_C void doExampleL()
00173 {
00174
00175 CTwoPhaser* twoPhaser=CTwoPhaser::NewLC(5);
00176
00177 twoPhaser->Print();
00178 _LIT(KTxtNewLine,"\n");
00179 console->Printf(KTxtNewLine);
00180 CleanupStack::PopAndDestroy();
00181
00182 CAbstract* abstract=CConcrete::NewLC(9);
00183
00184 abstract->SomeFunction(11);
00185 CleanupStack::PopAndDestroy();
00186 }