00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00022 #include "mystringreverse.h"
00023
00028 CMyStringReverse* CMyStringReverse::NewL(CConsoleBase* aConsole)
00029 {
00030 CMyStringReverse* self = new (ELeave)CMyStringReverse(aConsole);
00031 self->AddToScheduler();
00032 return self;
00033 }
00034
00038 void CMyStringReverse::AddToScheduler()
00039 {
00040 CActiveScheduler::Add(this);
00041 }
00042
00047 CMyStringReverse::CMyStringReverse(CConsoleBase* aConsole):
00048
00049 CActive(CActive::EPriorityUserInput),
00050
00051 iString(_FOFF(TLetter,iDLink)),
00052
00053 iIteratorString(iString),
00054 iConsole(aConsole)
00055 {
00056 }
00057
00067 void CMyStringReverse::RunL()
00068 {
00069
00070 TUint8 option = iConsole->KeyCode();
00071
00072 _LIT(KTextFormat,"%c\n");
00073 iConsole->Printf(KTextFormat,option);
00074
00075
00076 TInt number = option - (TUint)'0';
00077 if(number <10 && number > -1)
00078 {
00079
00080 switch(number)
00081 {
00082 case 1:
00083 {
00084
00085
00086 iTask = ETaskStringAddFirst;
00087 ReadChar();
00088 }
00089 break;
00090 case 2:
00091 {
00092
00093
00094 iTask = ETaskStringAddLast;
00095 ReadChar();
00096 }
00097 break;
00098 default:
00099
00100 CActiveScheduler::Stop();
00101 }
00102 }
00103 else
00104 {
00105
00106
00107 switch(iTask)
00108 {
00109 case ETaskNone:
00110 _LIT(KInvalidOption,"Invalid Option!\n");
00111 iConsole->Printf(KInvalidOption);
00112 break;
00113
00114 case ETaskStringAddFirst:
00115 {
00116
00117 TLetter* letter = new (ELeave) TLetter(option);
00118
00119 iString.AddFirst(*letter);
00120 iTask = ETaskNone;
00121
00122 PrintStrings();
00123 }
00124 break;
00125 case ETaskStringAddLast:
00126 {
00127
00128 TLetter* letter = new (ELeave) TLetter(option);
00129
00130 iString.AddLast(*letter);
00131 iTask = ETaskNone;
00132
00133 PrintStrings();
00134 }
00135 break;
00136 default:
00137 iTask = ETaskNone;
00138 break;
00139 }
00140
00141 ReadOption();
00142 }
00143 }
00144
00148 void CMyStringReverse::ReadFunc()
00149 {
00150
00151 iConsole->Read(iStatus);
00152 SetActive();
00153 }
00154
00158 void CMyStringReverse::ReadOption()
00159 {
00160
00161 _LIT(KTextMenu,"\nEnter\n1-> Add a character to the beginning of the string\n2-> Add a character to the end of the string\nAny other NUMBER to stop\n");
00162 iConsole->Printf(KTextMenu);
00163
00164 ReadFunc();
00165 }
00166
00170 void CMyStringReverse::ReadChar()
00171 {
00172 _LIT(KTextReadChar,"\nEnter a character\n");
00173 iConsole->Printf(KTextReadChar);
00174
00175 ReadFunc();
00176 }
00177
00181 void CMyStringReverse::PrintStrings()
00182 {
00183 _LIT(KTextSrcString,"Source String: ");
00184 iConsole->Printf(KTextSrcString);
00185
00186 iIteratorString.SetToFirst();
00187
00188
00189 while(iIteratorString != NULL)
00190 {
00191
00192 TLetter letter = *iIteratorString;
00193
00194 _LIT(KTextChar,"%c");
00195 iConsole->Printf(KTextChar,TUint(letter.iChar));
00196
00197 iIteratorString++;
00198 }
00199
00200 _LIT(KTextRevString,"\nReverse of the String: ");
00201 iConsole->Printf(KTextRevString);
00202
00203 iIteratorString.SetToLast();
00204
00205
00206 while(iIteratorString != NULL)
00207 {
00208
00209 TLetter letter = *iIteratorString;
00210
00211 _LIT(KTextChar,"%c");
00212 iConsole->Printf(KTextChar,TUint(letter.iChar));
00213
00214 iIteratorString--;
00215 }
00216 iConsole->Printf(KTextNewLine);
00217 }
00218
00222 void CMyStringReverse::DoCancel()
00223 {
00224 if(IsActive())
00225 {
00226
00227 iConsole->ReadCancel();
00228 }
00229 }
00230
00236 CMyStringReverse::~CMyStringReverse()
00237 {
00238
00239 iIteratorString.SetToFirst();
00240
00241 TLetter* ptr = iIteratorString++;
00242 while (ptr != NULL)
00243 {
00244 delete ptr;
00245 ptr = iIteratorString++;
00246 }
00247 }
00248