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
00032
00033 #include <e32cons.h>
00034
00035
00036 LOCAL_D CConsoleBase* console;
00037
00038
00039 LOCAL_C void doExampleL();
00040 LOCAL_C void callExampleL();
00041
00042
00044
00045
00046
00048 class CSimple : public CBase
00049 {
00050 public :
00051 static CSimple* NewL(TInt aVal);
00052 static CSimple* NewLC(TInt aVal);
00053 void Display();
00054 protected:
00055 CSimple(TInt aVal);
00056 public:
00057 TInt iVal;
00058 };
00059
00060
00062
00063
00064
00066 class CCompound : public CBase
00067 {
00068 public :
00069 virtual ~CCompound();
00070 void Display();
00071 static CCompound* NewL(TInt aRoot,TInt aChild);
00072 static CCompound* NewLC(TInt aRoot,TInt aChild);
00073 private:
00074 void ConstructL(TInt aRoot,TInt aChild);
00075 private:
00076 TInt iRoot;
00077 CSimple* iChild;
00078 };
00079
00081
00082
00083
00085
00086
00087
00088
00089
00090
00091
00092 CCompound* CCompound::NewLC(TInt aRoot,TInt aChild)
00093 {
00094 CCompound* self=new (ELeave) CCompound;
00095 CleanupStack::PushL(self);
00096
00097
00098
00099 self->ConstructL(aRoot,aChild);
00100 return self;
00101 }
00102
00103
00104 CCompound* CCompound::NewL(TInt aRoot,TInt aChild)
00105 {
00106 CCompound* self=NewLC(aRoot,aChild);
00107 CleanupStack::Pop();
00108 return self;
00109 }
00110
00111
00112 void CCompound::ConstructL(TInt aRoot,TInt aChild)
00113 {
00114 iRoot = aRoot;
00115 iChild = CSimple::NewL(aChild);
00116 iChild->iVal = aChild;
00117 }
00118
00119 void CCompound::Display()
00120 {
00121
00122 _LIT(KFormat4,"Root=%d. Child=%d.\n");
00123 console->Printf(KFormat4,iRoot,iChild->iVal);
00124 }
00125
00126 CCompound::~CCompound()
00127 {
00128 _LIT(KMsgDestCCompound,"Destructing CCompound\n");
00129 console->Printf(KMsgDestCCompound);
00130 delete iChild;
00131 }
00132
00133
00135
00136
00137
00139 CSimple* CSimple::NewL(TInt aVal)
00140 {
00141
00142 CSimple* self=new (ELeave) CSimple(aVal);
00143 return self;
00144 }
00145
00146
00147 CSimple* CSimple::NewLC(TInt aVal)
00148 {
00149
00150 CSimple* self=NewL(aVal);
00151 CleanupStack::PushL(self);
00152 return self;
00153 }
00154
00155
00156 void CSimple::Display()
00157 {
00158
00159 _LIT(KFormat1,"Value=%d.\n");
00160 console->Printf(KFormat1,iVal);
00161 }
00162
00163 CSimple::CSimple(TInt aVal)
00164 : iVal(aVal)
00165 {}
00166
00167
00169
00170
00171
00173 GLDEF_C TInt E32Main()
00174 {
00175
00176 CTrapCleanup* cleanup=CTrapCleanup::New();
00177
00178
00179 TRAPD(error,callExampleL());
00180
00181
00182 _LIT(KMsgPanicEpoc32ex,"EPOC32EX");
00183 __ASSERT_ALWAYS(!error,User::Panic(KMsgPanicEpoc32ex,error));
00184
00185
00186 delete cleanup;
00187
00188
00189 return 0;
00190 }
00191
00192
00194
00195
00196
00198 LOCAL_C void callExampleL()
00199 {
00200
00201 _LIT(KMsgExampleCode,"Symbian platform Example Code");
00202 console = Console::NewL(KMsgExampleCode,TSize(KConsFullScreen,KConsFullScreen));
00203
00204 CleanupStack::PushL(console);
00205
00206
00207 __UHEAP_MARK;
00208
00209
00210
00211 TRAPD(error,doExampleL());
00212
00213
00214 __UHEAP_MARKEND;
00215
00216
00217 _LIT(KMsgOK,"ok");
00218 _LIT(KFormat2,"Overall example Trap Harness failed: leave code=%d");
00219 if (error)
00220 console->Printf(KFormat2, error);
00221 else
00222 console->Printf(KMsgOK);
00223
00224
00225 _LIT(KMsgPressAnyKey," [press any key]");
00226 console->Printf(KMsgPressAnyKey);
00227 console->Getch();
00228
00229
00230
00231 CleanupStack::PopAndDestroy();
00232 }
00233
00234
00236
00237
00238
00239
00240
00242 void doExampleL()
00243 {
00244 #if defined(_DEBUG) //only ever used in debug mode
00245 TInt failValue = 5;
00246 #endif
00247
00248
00249
00250
00251
00252
00253 __UHEAP_SETFAIL(RHeap::EDeterministic,failValue);
00254
00255 for(TInt ii=1;ii<4;ii++)
00256 {
00257
00258 _LIT(KFormat3,"Cycle %d.\n");
00259 console->Printf(KFormat3,ii);
00260
00261 CCompound* myCompoundExample = CCompound::NewL(1,2);
00262
00263 myCompoundExample->Display();
00264
00265 delete myCompoundExample;
00266 }
00267 }
00268
00269