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