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
00034 #include "mystringreverse.h"
00035
00040 CMyStringReverse* CMyStringReverse::NewL(CConsoleBase* aConsole)
00041 {
00042 CMyStringReverse* self = new (ELeave)CMyStringReverse(aConsole);
00043 self->AddToScheduler();
00044 return self;
00045 }
00046
00050 void CMyStringReverse::AddToScheduler()
00051 {
00052 CActiveScheduler::Add(this);
00053 }
00054
00059 CMyStringReverse::CMyStringReverse(CConsoleBase* aConsole):
00060
00061 CActive(CActive::EPriorityUserInput),
00062
00063 iString(_FOFF(TLetter,iDLink)),
00064
00065 iIteratorString(iString),
00066 iConsole(aConsole)
00067 {
00068 }
00069
00079 void CMyStringReverse::RunL()
00080 {
00081
00082 TUint8 option = iConsole->KeyCode();
00083
00084 _LIT(KTextFormat,"%c\n");
00085 iConsole->Printf(KTextFormat,option);
00086
00087
00088 TInt number = option - (TUint)'0';
00089 if(number <10 && number > -1)
00090 {
00091
00092 switch(number)
00093 {
00094 case 1:
00095 {
00096
00097
00098 iTask = ETaskStringAddFirst;
00099 ReadChar();
00100 }
00101 break;
00102 case 2:
00103 {
00104
00105
00106 iTask = ETaskStringAddLast;
00107 ReadChar();
00108 }
00109 break;
00110 default:
00111
00112 CActiveScheduler::Stop();
00113 }
00114 }
00115 else
00116 {
00117
00118
00119 switch(iTask)
00120 {
00121 case ETaskNone:
00122 _LIT(KInvalidOption,"Invalid Option!\n");
00123 iConsole->Printf(KInvalidOption);
00124 break;
00125
00126 case ETaskStringAddFirst:
00127 {
00128
00129 TLetter* letter = new (ELeave) TLetter(option);
00130
00131 iString.AddFirst(*letter);
00132 iTask = ETaskNone;
00133
00134 PrintStrings();
00135 }
00136 break;
00137 case ETaskStringAddLast:
00138 {
00139
00140 TLetter* letter = new (ELeave) TLetter(option);
00141
00142 iString.AddLast(*letter);
00143 iTask = ETaskNone;
00144
00145 PrintStrings();
00146 }
00147 break;
00148 default:
00149 iTask = ETaskNone;
00150 break;
00151 }
00152
00153 ReadOption();
00154 }
00155 }
00156
00160 void CMyStringReverse::ReadFunc()
00161 {
00162
00163 iConsole->Read(iStatus);
00164 SetActive();
00165 }
00166
00170 void CMyStringReverse::ReadOption()
00171 {
00172
00173 _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");
00174 iConsole->Printf(KTextMenu);
00175
00176 ReadFunc();
00177 }
00178
00182 void CMyStringReverse::ReadChar()
00183 {
00184 _LIT(KTextReadChar,"\nEnter a character\n");
00185 iConsole->Printf(KTextReadChar);
00186
00187 ReadFunc();
00188 }
00189
00193 void CMyStringReverse::PrintStrings()
00194 {
00195 _LIT(KTextSrcString,"Source String: ");
00196 iConsole->Printf(KTextSrcString);
00197
00198 iIteratorString.SetToFirst();
00199
00200
00201 while(iIteratorString != NULL)
00202 {
00203
00204 TLetter letter = *iIteratorString;
00205
00206 _LIT(KTextChar,"%c");
00207 iConsole->Printf(KTextChar,TUint(letter.iChar));
00208
00209 iIteratorString++;
00210 }
00211
00212 _LIT(KTextRevString,"\nReverse of the String: ");
00213 iConsole->Printf(KTextRevString);
00214
00215 iIteratorString.SetToLast();
00216
00217
00218 while(iIteratorString != NULL)
00219 {
00220
00221 TLetter letter = *iIteratorString;
00222
00223 _LIT(KTextChar,"%c");
00224 iConsole->Printf(KTextChar,TUint(letter.iChar));
00225
00226 iIteratorString--;
00227 }
00228 iConsole->Printf(KTextNewLine);
00229 }
00230
00234 void CMyStringReverse::DoCancel()
00235 {
00236 if(IsActive())
00237 {
00238
00239 iConsole->ReadCancel();
00240 }
00241 }
00242
00248 CMyStringReverse::~CMyStringReverse()
00249 {
00250
00251 iIteratorString.SetToFirst();
00252
00253 TLetter* ptr = iIteratorString++;
00254 while (ptr != NULL)
00255 {
00256 delete ptr;
00257 ptr = iIteratorString++;
00258 }
00259 }
00260