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 TInt iRoot;
00075 CSimple* iChild;
00076 protected:
00077 CCompound(TInt aRoot,TInt aChild);
00078 };
00079
00081
00082
00083
00085
00086
00087
00088 CCompound* CCompound::NewL(TInt aRoot,TInt aChild)
00089 {
00090
00091 CCompound* self=new (ELeave) CCompound(aRoot,aChild);
00092 return self;
00093 }
00094
00095 CCompound* CCompound::NewLC(TInt aRoot,TInt aChild)
00096 {
00097 CCompound* self=NewL(aRoot,aChild);
00098 CleanupStack::PushL(self);
00099 return self;
00100 }
00101
00102 CCompound::CCompound(TInt aRoot,TInt aChild)
00103 {
00104 iRoot = aRoot;
00105 iChild = CSimple::NewL(aChild);
00106
00107
00108 iChild->iVal = aChild;
00109 }
00110
00111 void CCompound::Display()
00112 {
00113
00114 _LIT(KFormat4,"Root=%d. Child=%d.\n");
00115 console->Printf(KFormat4,iRoot,iChild->iVal);
00116 }
00117
00118 CCompound::~CCompound()
00119 {
00120 _LIT(KMsgDestCCompound,"Destructing CCompound\n");
00121 console->Printf(KMsgDestCCompound);
00122 delete iChild;
00123 }
00124
00125
00127
00128
00129
00131 CSimple* CSimple::NewL(TInt aVal)
00132 {
00133
00134 CSimple* self=new (ELeave) CSimple(aVal);
00135 return self;
00136 }
00137
00138
00139 CSimple* CSimple::NewLC(TInt aVal)
00140 {
00141
00142 CSimple* self=NewL(aVal);
00143 CleanupStack::PushL(self);
00144 return self;
00145 }
00146
00147
00148 void CSimple::Display()
00149 {
00150
00151 _LIT(KFormat1,"Value=%d.\n");
00152 console->Printf(KFormat1,iVal);
00153 }
00154
00155 CSimple::CSimple(TInt aVal)
00156 : iVal(aVal)
00157 {}
00158
00159
00161
00162
00163
00165 GLDEF_C TInt E32Main()
00166 {
00167
00168 CTrapCleanup* cleanup=CTrapCleanup::New();
00169
00170
00171 TRAPD(error,callExampleL());
00172
00173
00174 _LIT(KMsgPanicEpoc32ex,"EPOC32EX");
00175 __ASSERT_ALWAYS(!error,User::Panic(KMsgPanicEpoc32ex,error));
00176
00177
00178 delete cleanup;
00179
00180
00181 return 0;
00182 }
00183
00184
00186
00187
00188
00190 LOCAL_C void callExampleL()
00191 {
00192
00193 _LIT(KMsgExampleCode,"Symbian platform Example Code");
00194 console = Console::NewL(KMsgExampleCode,TSize(KConsFullScreen,KConsFullScreen));
00195
00196 CleanupStack::PushL(console);
00197
00198
00199 __UHEAP_MARK;
00200
00201
00202
00203 TRAPD(error,doExampleL());
00204
00205
00206 __UHEAP_MARKEND;
00207
00208
00209 _LIT(KMsgOK,"ok");
00210 _LIT(KFormat2,"Overall example Trap Harness failed: leave code=%d");
00211 if (error)
00212 console->Printf(KFormat2, error);
00213 else
00214 console->Printf(KMsgOK);
00215
00216
00217 _LIT(KMsgPressAnyKey," [press any key]");
00218 console->Printf(KMsgPressAnyKey);
00219 console->Getch();
00220
00221
00222
00223 CleanupStack::PopAndDestroy();
00224 }
00225
00226
00228
00229
00230
00231
00232
00234 void doExampleL()
00235 {
00236 #if defined(_DEBUG) //only ever used in debug mode
00237 TInt failValue = 5;
00238 #endif
00239
00240
00241
00242
00243
00244
00245 __UHEAP_SETFAIL(RHeap::EDeterministic,failValue);
00246
00247 for(TInt ii=1;ii<4;ii++)
00248 {
00249
00250 _LIT(KFormat3,"Cycle %d.\n");
00251 console->Printf(KFormat3,ii);
00252
00253 CCompound* myCompoundExample = CCompound::NewL(1,2);
00254
00255 myCompoundExample->Display();
00256
00257 delete myCompoundExample;
00258 }
00259 }
00260
00261