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