|
1 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> |
|
2 <html xmlns="http://www.w3.org/1999/xhtml"> |
|
3 <head> |
|
4 <meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/> |
|
5 <title>TB9.2 Example Applications: examples/Base/ArraysAndLists/linkedlist/dbllist/src/mystringreverse.cpp Source File</title> |
|
6 <link href="tabs.css" rel="stylesheet" type="text/css"/> |
|
7 <link href="doxygen.css" rel="stylesheet" type="text/css"/> |
|
8 </head> |
|
9 <body> |
|
10 <!-- Generated by Doxygen 1.6.2 --> |
|
11 <h1>examples/Base/ArraysAndLists/linkedlist/dbllist/src/mystringreverse.cpp</h1><a href="mystringreverse_8cpp.html">Go to the documentation of this file.</a><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">// Copyright (c) 2008-2009 Nokia Corporation and/or its subsidiary(-ies).</span> |
|
12 <a name="l00002"></a>00002 <span class="comment">// All rights reserved.</span> |
|
13 <a name="l00003"></a>00003 <span class="comment">// This component and the accompanying materials are made available</span> |
|
14 <a name="l00004"></a>00004 <span class="comment">// under the terms of "Eclipse Public License v1.0"</span> |
|
15 <a name="l00005"></a>00005 <span class="comment">// which accompanies this distribution, and is available</span> |
|
16 <a name="l00006"></a>00006 <span class="comment">// at the URL "http://www.eclipse.org/legal/epl-v10.html".</span> |
|
17 <a name="l00007"></a>00007 <span class="comment">//</span> |
|
18 <a name="l00008"></a>00008 <span class="comment">// Initial Contributors:</span> |
|
19 <a name="l00009"></a>00009 <span class="comment">// Nokia Corporation - initial contribution.</span> |
|
20 <a name="l00010"></a>00010 <span class="comment">//</span> |
|
21 <a name="l00011"></a>00011 <span class="comment">// Contributors:</span> |
|
22 <a name="l00012"></a>00012 <span class="comment">//</span> |
|
23 <a name="l00013"></a>00013 <span class="comment">// Description:</span> |
|
24 <a name="l00014"></a>00014 <span class="comment">// Contains definition of functions defined in the CMyStringReverse class.</span> |
|
25 <a name="l00015"></a>00015 <span class="comment">// </span> |
|
26 <a name="l00016"></a>00016 <span class="comment">//</span> |
|
27 <a name="l00017"></a>00017 |
|
28 <a name="l00022"></a>00022 <span class="preprocessor">#include "<a class="code" href="mystringreverse_8h.html">mystringreverse.h</a>"</span> |
|
29 <a name="l00023"></a>00023 |
|
30 <a name="l00028"></a><a class="code" href="class_c_my_string_reverse.html#a2ab3e8b199ce96ba6239d6af086c62a4">00028</a> <a class="code" href="class_c_my_string_reverse.html">CMyStringReverse</a>* <a class="code" href="class_c_my_string_reverse.html#a2ab3e8b199ce96ba6239d6af086c62a4">CMyStringReverse::NewL</a>(CConsoleBase* aConsole) |
|
31 <a name="l00029"></a>00029 { |
|
32 <a name="l00030"></a>00030 <a class="code" href="class_c_my_string_reverse.html">CMyStringReverse</a>* <span class="keyword">self</span> = <span class="keyword">new</span> (ELeave)<a class="code" href="class_c_my_string_reverse.html">CMyStringReverse</a>(aConsole); |
|
33 <a name="l00031"></a>00031 <span class="keyword">self</span>-><a class="code" href="class_c_my_string_reverse.html#a2c4d6ff67407fcd776305acb55820750">AddToScheduler</a>(); |
|
34 <a name="l00032"></a>00032 <span class="keywordflow">return</span> <span class="keyword">self</span>; |
|
35 <a name="l00033"></a>00033 } |
|
36 <a name="l00034"></a>00034 |
|
37 <a name="l00038"></a><a class="code" href="class_c_my_string_reverse.html#a2c4d6ff67407fcd776305acb55820750">00038</a> <span class="keywordtype">void</span> <a class="code" href="class_c_my_string_reverse.html#a2c4d6ff67407fcd776305acb55820750">CMyStringReverse::AddToScheduler</a>() |
|
38 <a name="l00039"></a>00039 { |
|
39 <a name="l00040"></a>00040 CActiveScheduler::Add(<span class="keyword">this</span>); |
|
40 <a name="l00041"></a>00041 } |
|
41 <a name="l00042"></a>00042 |
|
42 <a name="l00047"></a>00047 CMyStringReverse::CMyStringReverse(CConsoleBase* aConsole): |
|
43 <a name="l00048"></a>00048 <span class="comment">// Constructor of the base class.</span> |
|
44 <a name="l00049"></a>00049 CActive(CActive::EPriorityUserInput), |
|
45 <a name="l00050"></a>00050 <span class="comment">// Create the linked list.</span> |
|
46 <a name="l00051"></a>00051 iString(_FOFF(<a class="code" href="class_t_letter.html">TLetter</a>,iDLink)), |
|
47 <a name="l00052"></a>00052 <span class="comment">// Initialize iterators.</span> |
|
48 <a name="l00053"></a>00053 iIteratorString(iString), |
|
49 <a name="l00054"></a>00054 iConsole(aConsole) |
|
50 <a name="l00055"></a>00055 { |
|
51 <a name="l00056"></a>00056 } |
|
52 <a name="l00057"></a>00057 |
|
53 <a name="l00067"></a><a class="code" href="class_c_my_string_reverse.html#a2d3f11cae95c95116bcd3ff89962f212">00067</a> <span class="keywordtype">void</span> <a class="code" href="class_c_my_string_reverse.html#a2d3f11cae95c95116bcd3ff89962f212">CMyStringReverse::RunL</a>() |
|
54 <a name="l00068"></a>00068 { |
|
55 <a name="l00069"></a>00069 <span class="comment">// Get the key code.</span> |
|
56 <a name="l00070"></a>00070 TUint8 option = iConsole->KeyCode(); |
|
57 <a name="l00071"></a>00071 <span class="comment">// Print the selected option.</span> |
|
58 <a name="l00072"></a>00072 <a class="code" href="secureclientandserver_8h.html#a5eadd4429627d82193b37536d4faa03a">_LIT</a>(KTextFormat,<span class="stringliteral">"%c\n"</span>); |
|
59 <a name="l00073"></a>00073 iConsole->Printf(KTextFormat,option); |
|
60 <a name="l00074"></a>00074 |
|
61 <a name="l00075"></a>00075 <span class="comment">// Check if a numeric key is pressed.</span> |
|
62 <a name="l00076"></a>00076 TInt number = option - (TUint)<span class="charliteral">'0'</span>; |
|
63 <a name="l00077"></a>00077 <span class="keywordflow">if</span>(number <10 && number > -1) |
|
64 <a name="l00078"></a>00078 { |
|
65 <a name="l00079"></a>00079 <span class="comment">// Handle the numeric key press.</span> |
|
66 <a name="l00080"></a>00080 <span class="keywordflow">switch</span>(number) |
|
67 <a name="l00081"></a>00081 { |
|
68 <a name="l00082"></a>00082 <span class="keywordflow">case</span> 1: |
|
69 <a name="l00083"></a>00083 { |
|
70 <a name="l00084"></a>00084 <span class="comment">// The iString.AddFirst() function needs to be called.</span> |
|
71 <a name="l00085"></a>00085 <span class="comment">// Read the character to be added to the list.</span> |
|
72 <a name="l00086"></a>00086 iTask = ETaskStringAddFirst; |
|
73 <a name="l00087"></a>00087 <a class="code" href="class_c_my_string_reverse.html#a3df27149dbe0c55a7a6a7afdd0af43d6">ReadChar</a>(); |
|
74 <a name="l00088"></a>00088 } |
|
75 <a name="l00089"></a>00089 <span class="keywordflow">break</span>; |
|
76 <a name="l00090"></a>00090 <span class="keywordflow">case</span> 2: |
|
77 <a name="l00091"></a>00091 { |
|
78 <a name="l00092"></a>00092 <span class="comment">// The iString.AddLast() function needs to be called.</span> |
|
79 <a name="l00093"></a>00093 <span class="comment">// Read the character to be added to the list.</span> |
|
80 <a name="l00094"></a>00094 iTask = ETaskStringAddLast; |
|
81 <a name="l00095"></a>00095 <a class="code" href="class_c_my_string_reverse.html#a3df27149dbe0c55a7a6a7afdd0af43d6">ReadChar</a>(); |
|
82 <a name="l00096"></a>00096 } |
|
83 <a name="l00097"></a>00097 <span class="keywordflow">break</span>; |
|
84 <a name="l00098"></a>00098 <span class="keywordflow">default</span>: |
|
85 <a name="l00099"></a>00099 <span class="comment">// Stop the active scheduler.</span> |
|
86 <a name="l00100"></a>00100 CActiveScheduler::Stop(); |
|
87 <a name="l00101"></a>00101 } |
|
88 <a name="l00102"></a>00102 } |
|
89 <a name="l00103"></a>00103 <span class="keywordflow">else</span> |
|
90 <a name="l00104"></a>00104 { |
|
91 <a name="l00105"></a>00105 <span class="comment">// An alphabetic key is pressed.</span> |
|
92 <a name="l00106"></a>00106 <span class="comment">// Check the action to be performed.</span> |
|
93 <a name="l00107"></a>00107 <span class="keywordflow">switch</span>(iTask) |
|
94 <a name="l00108"></a>00108 { |
|
95 <a name="l00109"></a>00109 <span class="keywordflow">case</span> ETaskNone: |
|
96 <a name="l00110"></a>00110 <a class="code" href="secureclientandserver_8h.html#a5eadd4429627d82193b37536d4faa03a">_LIT</a>(KInvalidOption,<span class="stringliteral">"Invalid Option!\n"</span>); |
|
97 <a name="l00111"></a>00111 iConsole->Printf(KInvalidOption); |
|
98 <a name="l00112"></a>00112 <span class="keywordflow">break</span>; |
|
99 <a name="l00113"></a>00113 <span class="comment">// The iString.AddFirst() function needs to be called.</span> |
|
100 <a name="l00114"></a>00114 <span class="keywordflow">case</span> ETaskStringAddFirst: |
|
101 <a name="l00115"></a>00115 { |
|
102 <a name="l00116"></a>00116 <span class="comment">// Create an object of the TLetter class.</span> |
|
103 <a name="l00117"></a>00117 <a class="code" href="class_t_letter.html">TLetter</a>* letter = <span class="keyword">new</span> (ELeave) <a class="code" href="class_t_letter.html">TLetter</a>(option); |
|
104 <a name="l00118"></a>00118 <span class="comment">// Add the TLetter object into the list.</span> |
|
105 <a name="l00119"></a>00119 iString.AddFirst(*letter); |
|
106 <a name="l00120"></a>00120 iTask = ETaskNone; |
|
107 <a name="l00121"></a>00121 <span class="comment">// Print the data in iString and iReverseString.</span> |
|
108 <a name="l00122"></a>00122 <a class="code" href="class_c_my_string_reverse.html#ac042ac03ee05e8410f080f2ee3b51f39">PrintStrings</a>(); |
|
109 <a name="l00123"></a>00123 } |
|
110 <a name="l00124"></a>00124 <span class="keywordflow">break</span>; |
|
111 <a name="l00125"></a>00125 <span class="keywordflow">case</span> ETaskStringAddLast: |
|
112 <a name="l00126"></a>00126 { |
|
113 <a name="l00127"></a>00127 <span class="comment">// Create an object of the TLetter class.</span> |
|
114 <a name="l00128"></a>00128 <a class="code" href="class_t_letter.html">TLetter</a>* letter = <span class="keyword">new</span> (ELeave) <a class="code" href="class_t_letter.html">TLetter</a>(option); |
|
115 <a name="l00129"></a>00129 <span class="comment">// Add the TLetter object into the list.</span> |
|
116 <a name="l00130"></a>00130 iString.AddLast(*letter); |
|
117 <a name="l00131"></a>00131 iTask = ETaskNone; |
|
118 <a name="l00132"></a>00132 <span class="comment">// Print the data in iString and iReverseString.</span> |
|
119 <a name="l00133"></a>00133 <a class="code" href="class_c_my_string_reverse.html#ac042ac03ee05e8410f080f2ee3b51f39">PrintStrings</a>(); |
|
120 <a name="l00134"></a>00134 } |
|
121 <a name="l00135"></a>00135 <span class="keywordflow">break</span>; |
|
122 <a name="l00136"></a>00136 <span class="keywordflow">default</span>: |
|
123 <a name="l00137"></a>00137 iTask = ETaskNone; |
|
124 <a name="l00138"></a>00138 <span class="keywordflow">break</span>; |
|
125 <a name="l00139"></a>00139 } |
|
126 <a name="l00140"></a>00140 <span class="comment">// Generate an asynchronous read request.</span> |
|
127 <a name="l00141"></a>00141 <a class="code" href="class_c_my_string_reverse.html#a28aa61d2589697113937251c10747826">ReadOption</a>(); |
|
128 <a name="l00142"></a>00142 } |
|
129 <a name="l00143"></a>00143 } |
|
130 <a name="l00144"></a>00144 |
|
131 <a name="l00148"></a>00148 <span class="keywordtype">void</span> CMyStringReverse::ReadFunc() |
|
132 <a name="l00149"></a>00149 { |
|
133 <a name="l00150"></a>00150 <span class="comment">// Wait for a key press event.</span> |
|
134 <a name="l00151"></a>00151 iConsole->Read(iStatus); |
|
135 <a name="l00152"></a>00152 SetActive(); |
|
136 <a name="l00153"></a>00153 } |
|
137 <a name="l00154"></a>00154 |
|
138 <a name="l00158"></a><a class="code" href="class_c_my_string_reverse.html#a28aa61d2589697113937251c10747826">00158</a> <span class="keywordtype">void</span> <a class="code" href="class_c_my_string_reverse.html#a28aa61d2589697113937251c10747826">CMyStringReverse::ReadOption</a>() |
|
139 <a name="l00159"></a>00159 { |
|
140 <a name="l00160"></a>00160 <span class="comment">// Print the menu.</span> |
|
141 <a name="l00161"></a>00161 <a class="code" href="secureclientandserver_8h.html#a5eadd4429627d82193b37536d4faa03a">_LIT</a>(KTextMenu,<span class="stringliteral">"\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"</span>); |
|
142 <a name="l00162"></a>00162 iConsole->Printf(KTextMenu); |
|
143 <a name="l00163"></a>00163 <span class="comment">// Generate an asynchronous read request.</span> |
|
144 <a name="l00164"></a>00164 ReadFunc(); |
|
145 <a name="l00165"></a>00165 } |
|
146 <a name="l00166"></a>00166 |
|
147 <a name="l00170"></a><a class="code" href="class_c_my_string_reverse.html#a3df27149dbe0c55a7a6a7afdd0af43d6">00170</a> <span class="keywordtype">void</span> <a class="code" href="class_c_my_string_reverse.html#a3df27149dbe0c55a7a6a7afdd0af43d6">CMyStringReverse::ReadChar</a>() |
|
148 <a name="l00171"></a>00171 { |
|
149 <a name="l00172"></a>00172 <a class="code" href="secureclientandserver_8h.html#a5eadd4429627d82193b37536d4faa03a">_LIT</a>(KTextReadChar,<span class="stringliteral">"\nEnter a character\n"</span>); |
|
150 <a name="l00173"></a>00173 iConsole->Printf(KTextReadChar); |
|
151 <a name="l00174"></a>00174 <span class="comment">// Generate an asynchronous read request.</span> |
|
152 <a name="l00175"></a>00175 ReadFunc(); |
|
153 <a name="l00176"></a>00176 } |
|
154 <a name="l00177"></a>00177 |
|
155 <a name="l00181"></a><a class="code" href="class_c_my_string_reverse.html#ac042ac03ee05e8410f080f2ee3b51f39">00181</a> <span class="keywordtype">void</span> <a class="code" href="class_c_my_string_reverse.html#ac042ac03ee05e8410f080f2ee3b51f39">CMyStringReverse::PrintStrings</a>() |
|
156 <a name="l00182"></a>00182 { |
|
157 <a name="l00183"></a>00183 <a class="code" href="secureclientandserver_8h.html#a5eadd4429627d82193b37536d4faa03a">_LIT</a>(KTextSrcString,<span class="stringliteral">"Source String: "</span>); |
|
158 <a name="l00184"></a>00184 iConsole->Printf(KTextSrcString); |
|
159 <a name="l00185"></a>00185 <span class="comment">// Initialize the iterator.</span> |
|
160 <a name="l00186"></a>00186 iIteratorString.SetToFirst(); |
|
161 <a name="l00187"></a>00187 |
|
162 <a name="l00188"></a>00188 <span class="comment">// Iterate iString.</span> |
|
163 <a name="l00189"></a>00189 <span class="keywordflow">while</span>(iIteratorString != NULL) |
|
164 <a name="l00190"></a>00190 { |
|
165 <a name="l00191"></a>00191 <span class="comment">// Get the TLetter object pointed to by the iterator.</span> |
|
166 <a name="l00192"></a>00192 <a class="code" href="class_t_letter.html">TLetter</a> letter = *iIteratorString; |
|
167 <a name="l00193"></a>00193 <span class="comment">// Print the character value of the TLetter object.</span> |
|
168 <a name="l00194"></a>00194 <a class="code" href="secureclientandserver_8h.html#a5eadd4429627d82193b37536d4faa03a">_LIT</a>(KTextChar,<span class="stringliteral">"%c"</span>); |
|
169 <a name="l00195"></a>00195 iConsole->Printf(KTextChar,TUint(letter.<a class="code" href="class_t_letter.html#a1ce2b6bc97d7c647ee1adbf72aac5628">iChar</a>)); |
|
170 <a name="l00196"></a>00196 <span class="comment">// Set the iterator to point to the next element.</span> |
|
171 <a name="l00197"></a>00197 iIteratorString++; |
|
172 <a name="l00198"></a>00198 } |
|
173 <a name="l00199"></a>00199 |
|
174 <a name="l00200"></a>00200 <a class="code" href="secureclientandserver_8h.html#a5eadd4429627d82193b37536d4faa03a">_LIT</a>(KTextRevString,<span class="stringliteral">"\nReverse of the String: "</span>); |
|
175 <a name="l00201"></a>00201 iConsole->Printf(KTextRevString); |
|
176 <a name="l00202"></a>00202 <span class="comment">// Initialize the iterator.</span> |
|
177 <a name="l00203"></a>00203 iIteratorString.SetToLast(); |
|
178 <a name="l00204"></a>00204 |
|
179 <a name="l00205"></a>00205 <span class="comment">// Iterate iReverseString.</span> |
|
180 <a name="l00206"></a>00206 <span class="keywordflow">while</span>(iIteratorString != NULL) |
|
181 <a name="l00207"></a>00207 { |
|
182 <a name="l00208"></a>00208 <span class="comment">// Get the TLetter object pointed to by the iterator.</span> |
|
183 <a name="l00209"></a>00209 <a class="code" href="class_t_letter.html">TLetter</a> letter = *iIteratorString; |
|
184 <a name="l00210"></a>00210 <span class="comment">// Print the character value of the TLetter object.</span> |
|
185 <a name="l00211"></a>00211 <a class="code" href="secureclientandserver_8h.html#a5eadd4429627d82193b37536d4faa03a">_LIT</a>(KTextChar,<span class="stringliteral">"%c"</span>); |
|
186 <a name="l00212"></a>00212 iConsole->Printf(KTextChar,TUint(letter.<a class="code" href="class_t_letter.html#a1ce2b6bc97d7c647ee1adbf72aac5628">iChar</a>)); |
|
187 <a name="l00213"></a>00213 <span class="comment">// Set the iterator to point to the next element.</span> |
|
188 <a name="l00214"></a>00214 iIteratorString--; |
|
189 <a name="l00215"></a>00215 } |
|
190 <a name="l00216"></a>00216 iConsole->Printf(KTextNewLine); |
|
191 <a name="l00217"></a>00217 } |
|
192 <a name="l00218"></a>00218 |
|
193 <a name="l00222"></a><a class="code" href="class_c_my_string_reverse.html#a845aed5a330f05b110198d4ee45ab32d">00222</a> <span class="keywordtype">void</span> <a class="code" href="class_c_my_string_reverse.html#a845aed5a330f05b110198d4ee45ab32d">CMyStringReverse::DoCancel</a>() |
|
194 <a name="l00223"></a>00223 { |
|
195 <a name="l00224"></a>00224 <span class="keywordflow">if</span>(IsActive()) |
|
196 <a name="l00225"></a>00225 { |
|
197 <a name="l00226"></a>00226 <span class="comment">// Cancel any outstanding read requests.</span> |
|
198 <a name="l00227"></a>00227 iConsole->ReadCancel(); |
|
199 <a name="l00228"></a>00228 } |
|
200 <a name="l00229"></a>00229 } |
|
201 <a name="l00230"></a>00230 |
|
202 <a name="l00236"></a><a class="code" href="class_c_my_string_reverse.html#a1b0e1bef7e163fa3fc8f7e06047782ed">00236</a> <a class="code" href="class_c_my_string_reverse.html#a1b0e1bef7e163fa3fc8f7e06047782ed">CMyStringReverse::~CMyStringReverse</a>() |
|
203 <a name="l00237"></a>00237 { |
|
204 <a name="l00238"></a>00238 <span class="comment">// Delete the elements from the list. </span> |
|
205 <a name="l00239"></a>00239 iIteratorString.SetToFirst(); |
|
206 <a name="l00240"></a>00240 <span class="comment">// Iterate the list and delete all TLetter objects.</span> |
|
207 <a name="l00241"></a>00241 <a class="code" href="class_t_letter.html">TLetter</a>* ptr = iIteratorString++; |
|
208 <a name="l00242"></a>00242 <span class="keywordflow">while</span> (ptr != NULL) |
|
209 <a name="l00243"></a>00243 { |
|
210 <a name="l00244"></a>00244 <span class="keyword">delete</span> ptr; |
|
211 <a name="l00245"></a>00245 ptr = iIteratorString++; |
|
212 <a name="l00246"></a>00246 } |
|
213 <a name="l00247"></a>00247 } |
|
214 <a name="l00248"></a>00248 |
|
215 </pre></div></div> |
|
216 <hr size="1"/><address style="text-align: right;"><small>Generated by |
|
217 <a href="http://www.doxygen.org/index.html"> |
|
218 <img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.6.2 </small></address> |
|
219 </body> |
|
220 </html> |