Symbian3/Examples/guid-6013a680-57f9-415b-8851-c4fa63356636/mystringreverse_8cpp_source.html
Initial contribution of the Adaptation Documentation.
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<title>TB9.2 Example Applications: examples/Base/ArraysAndLists/linkedlist/dbllist/src/mystringreverse.cpp Source File</title>
<link href="tabs.css" rel="stylesheet" type="text/css"/>
<link href="doxygen.css" rel="stylesheet" type="text/css"/>
</head>
<body>
<!-- Generated by Doxygen 1.6.2 -->
<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>
<a name="l00002"></a>00002 <span class="comment">// All rights reserved.</span>
<a name="l00003"></a>00003 <span class="comment">// This component and the accompanying materials are made available</span>
<a name="l00004"></a>00004 <span class="comment">// under the terms of "Eclipse Public License v1.0"</span>
<a name="l00005"></a>00005 <span class="comment">// which accompanies this distribution, and is available</span>
<a name="l00006"></a>00006 <span class="comment">// at the URL "http://www.eclipse.org/legal/epl-v10.html".</span>
<a name="l00007"></a>00007 <span class="comment">//</span>
<a name="l00008"></a>00008 <span class="comment">// Initial Contributors:</span>
<a name="l00009"></a>00009 <span class="comment">// Nokia Corporation - initial contribution.</span>
<a name="l00010"></a>00010 <span class="comment">//</span>
<a name="l00011"></a>00011 <span class="comment">// Contributors:</span>
<a name="l00012"></a>00012 <span class="comment">//</span>
<a name="l00013"></a>00013 <span class="comment">// Description:</span>
<a name="l00014"></a>00014 <span class="comment">// Contains definition of functions defined in the CMyStringReverse class.</span>
<a name="l00015"></a>00015 <span class="comment">// </span>
<a name="l00016"></a>00016 <span class="comment">//</span>
<a name="l00017"></a>00017
<a name="l00022"></a>00022 <span class="preprocessor">#include "<a class="code" href="mystringreverse_8h.html">mystringreverse.h</a>"</span>
<a name="l00023"></a>00023
<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)
<a name="l00029"></a>00029 {
<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);
<a name="l00031"></a>00031 <span class="keyword">self</span>-><a class="code" href="class_c_my_string_reverse.html#a2c4d6ff67407fcd776305acb55820750">AddToScheduler</a>();
<a name="l00032"></a>00032 <span class="keywordflow">return</span> <span class="keyword">self</span>;
<a name="l00033"></a>00033 }
<a name="l00034"></a>00034
<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>()
<a name="l00039"></a>00039 {
<a name="l00040"></a>00040 CActiveScheduler::Add(<span class="keyword">this</span>);
<a name="l00041"></a>00041 }
<a name="l00042"></a>00042
<a name="l00047"></a>00047 CMyStringReverse::CMyStringReverse(CConsoleBase* aConsole):
<a name="l00048"></a>00048 <span class="comment">// Constructor of the base class.</span>
<a name="l00049"></a>00049 CActive(CActive::EPriorityUserInput),
<a name="l00050"></a>00050 <span class="comment">// Create the linked list.</span>
<a name="l00051"></a>00051 iString(_FOFF(<a class="code" href="class_t_letter.html">TLetter</a>,iDLink)),
<a name="l00052"></a>00052 <span class="comment">// Initialize iterators.</span>
<a name="l00053"></a>00053 iIteratorString(iString),
<a name="l00054"></a>00054 iConsole(aConsole)
<a name="l00055"></a>00055 {
<a name="l00056"></a>00056 }
<a name="l00057"></a>00057
<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>()
<a name="l00068"></a>00068 {
<a name="l00069"></a>00069 <span class="comment">// Get the key code.</span>
<a name="l00070"></a>00070 TUint8 option = iConsole->KeyCode();
<a name="l00071"></a>00071 <span class="comment">// Print the selected option.</span>
<a name="l00072"></a>00072 <a class="code" href="secureclientandserver_8h.html#a5eadd4429627d82193b37536d4faa03a">_LIT</a>(KTextFormat,<span class="stringliteral">"%c\n"</span>);
<a name="l00073"></a>00073 iConsole->Printf(KTextFormat,option);
<a name="l00074"></a>00074
<a name="l00075"></a>00075 <span class="comment">// Check if a numeric key is pressed.</span>
<a name="l00076"></a>00076 TInt number = option - (TUint)<span class="charliteral">'0'</span>;
<a name="l00077"></a>00077 <span class="keywordflow">if</span>(number <10 && number > -1)
<a name="l00078"></a>00078 {
<a name="l00079"></a>00079 <span class="comment">// Handle the numeric key press.</span>
<a name="l00080"></a>00080 <span class="keywordflow">switch</span>(number)
<a name="l00081"></a>00081 {
<a name="l00082"></a>00082 <span class="keywordflow">case</span> 1:
<a name="l00083"></a>00083 {
<a name="l00084"></a>00084 <span class="comment">// The iString.AddFirst() function needs to be called.</span>
<a name="l00085"></a>00085 <span class="comment">// Read the character to be added to the list.</span>
<a name="l00086"></a>00086 iTask = ETaskStringAddFirst;
<a name="l00087"></a>00087 <a class="code" href="class_c_my_string_reverse.html#a3df27149dbe0c55a7a6a7afdd0af43d6">ReadChar</a>();
<a name="l00088"></a>00088 }
<a name="l00089"></a>00089 <span class="keywordflow">break</span>;
<a name="l00090"></a>00090 <span class="keywordflow">case</span> 2:
<a name="l00091"></a>00091 {
<a name="l00092"></a>00092 <span class="comment">// The iString.AddLast() function needs to be called.</span>
<a name="l00093"></a>00093 <span class="comment">// Read the character to be added to the list.</span>
<a name="l00094"></a>00094 iTask = ETaskStringAddLast;
<a name="l00095"></a>00095 <a class="code" href="class_c_my_string_reverse.html#a3df27149dbe0c55a7a6a7afdd0af43d6">ReadChar</a>();
<a name="l00096"></a>00096 }
<a name="l00097"></a>00097 <span class="keywordflow">break</span>;
<a name="l00098"></a>00098 <span class="keywordflow">default</span>:
<a name="l00099"></a>00099 <span class="comment">// Stop the active scheduler.</span>
<a name="l00100"></a>00100 CActiveScheduler::Stop();
<a name="l00101"></a>00101 }
<a name="l00102"></a>00102 }
<a name="l00103"></a>00103 <span class="keywordflow">else</span>
<a name="l00104"></a>00104 {
<a name="l00105"></a>00105 <span class="comment">// An alphabetic key is pressed.</span>
<a name="l00106"></a>00106 <span class="comment">// Check the action to be performed.</span>
<a name="l00107"></a>00107 <span class="keywordflow">switch</span>(iTask)
<a name="l00108"></a>00108 {
<a name="l00109"></a>00109 <span class="keywordflow">case</span> ETaskNone:
<a name="l00110"></a>00110 <a class="code" href="secureclientandserver_8h.html#a5eadd4429627d82193b37536d4faa03a">_LIT</a>(KInvalidOption,<span class="stringliteral">"Invalid Option!\n"</span>);
<a name="l00111"></a>00111 iConsole->Printf(KInvalidOption);
<a name="l00112"></a>00112 <span class="keywordflow">break</span>;
<a name="l00113"></a>00113 <span class="comment">// The iString.AddFirst() function needs to be called.</span>
<a name="l00114"></a>00114 <span class="keywordflow">case</span> ETaskStringAddFirst:
<a name="l00115"></a>00115 {
<a name="l00116"></a>00116 <span class="comment">// Create an object of the TLetter class.</span>
<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);
<a name="l00118"></a>00118 <span class="comment">// Add the TLetter object into the list.</span>
<a name="l00119"></a>00119 iString.AddFirst(*letter);
<a name="l00120"></a>00120 iTask = ETaskNone;
<a name="l00121"></a>00121 <span class="comment">// Print the data in iString and iReverseString.</span>
<a name="l00122"></a>00122 <a class="code" href="class_c_my_string_reverse.html#ac042ac03ee05e8410f080f2ee3b51f39">PrintStrings</a>();
<a name="l00123"></a>00123 }
<a name="l00124"></a>00124 <span class="keywordflow">break</span>;
<a name="l00125"></a>00125 <span class="keywordflow">case</span> ETaskStringAddLast:
<a name="l00126"></a>00126 {
<a name="l00127"></a>00127 <span class="comment">// Create an object of the TLetter class.</span>
<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);
<a name="l00129"></a>00129 <span class="comment">// Add the TLetter object into the list.</span>
<a name="l00130"></a>00130 iString.AddLast(*letter);
<a name="l00131"></a>00131 iTask = ETaskNone;
<a name="l00132"></a>00132 <span class="comment">// Print the data in iString and iReverseString.</span>
<a name="l00133"></a>00133 <a class="code" href="class_c_my_string_reverse.html#ac042ac03ee05e8410f080f2ee3b51f39">PrintStrings</a>();
<a name="l00134"></a>00134 }
<a name="l00135"></a>00135 <span class="keywordflow">break</span>;
<a name="l00136"></a>00136 <span class="keywordflow">default</span>:
<a name="l00137"></a>00137 iTask = ETaskNone;
<a name="l00138"></a>00138 <span class="keywordflow">break</span>;
<a name="l00139"></a>00139 }
<a name="l00140"></a>00140 <span class="comment">// Generate an asynchronous read request.</span>
<a name="l00141"></a>00141 <a class="code" href="class_c_my_string_reverse.html#a28aa61d2589697113937251c10747826">ReadOption</a>();
<a name="l00142"></a>00142 }
<a name="l00143"></a>00143 }
<a name="l00144"></a>00144
<a name="l00148"></a>00148 <span class="keywordtype">void</span> CMyStringReverse::ReadFunc()
<a name="l00149"></a>00149 {
<a name="l00150"></a>00150 <span class="comment">// Wait for a key press event.</span>
<a name="l00151"></a>00151 iConsole->Read(iStatus);
<a name="l00152"></a>00152 SetActive();
<a name="l00153"></a>00153 }
<a name="l00154"></a>00154
<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>()
<a name="l00159"></a>00159 {
<a name="l00160"></a>00160 <span class="comment">// Print the menu.</span>
<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>);
<a name="l00162"></a>00162 iConsole->Printf(KTextMenu);
<a name="l00163"></a>00163 <span class="comment">// Generate an asynchronous read request.</span>
<a name="l00164"></a>00164 ReadFunc();
<a name="l00165"></a>00165 }
<a name="l00166"></a>00166
<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>()
<a name="l00171"></a>00171 {
<a name="l00172"></a>00172 <a class="code" href="secureclientandserver_8h.html#a5eadd4429627d82193b37536d4faa03a">_LIT</a>(KTextReadChar,<span class="stringliteral">"\nEnter a character\n"</span>);
<a name="l00173"></a>00173 iConsole->Printf(KTextReadChar);
<a name="l00174"></a>00174 <span class="comment">// Generate an asynchronous read request.</span>
<a name="l00175"></a>00175 ReadFunc();
<a name="l00176"></a>00176 }
<a name="l00177"></a>00177
<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>()
<a name="l00182"></a>00182 {
<a name="l00183"></a>00183 <a class="code" href="secureclientandserver_8h.html#a5eadd4429627d82193b37536d4faa03a">_LIT</a>(KTextSrcString,<span class="stringliteral">"Source String: "</span>);
<a name="l00184"></a>00184 iConsole->Printf(KTextSrcString);
<a name="l00185"></a>00185 <span class="comment">// Initialize the iterator.</span>
<a name="l00186"></a>00186 iIteratorString.SetToFirst();
<a name="l00187"></a>00187
<a name="l00188"></a>00188 <span class="comment">// Iterate iString.</span>
<a name="l00189"></a>00189 <span class="keywordflow">while</span>(iIteratorString != NULL)
<a name="l00190"></a>00190 {
<a name="l00191"></a>00191 <span class="comment">// Get the TLetter object pointed to by the iterator.</span>
<a name="l00192"></a>00192 <a class="code" href="class_t_letter.html">TLetter</a> letter = *iIteratorString;
<a name="l00193"></a>00193 <span class="comment">// Print the character value of the TLetter object.</span>
<a name="l00194"></a>00194 <a class="code" href="secureclientandserver_8h.html#a5eadd4429627d82193b37536d4faa03a">_LIT</a>(KTextChar,<span class="stringliteral">"%c"</span>);
<a name="l00195"></a>00195 iConsole->Printf(KTextChar,TUint(letter.<a class="code" href="class_t_letter.html#a1ce2b6bc97d7c647ee1adbf72aac5628">iChar</a>));
<a name="l00196"></a>00196 <span class="comment">// Set the iterator to point to the next element.</span>
<a name="l00197"></a>00197 iIteratorString++;
<a name="l00198"></a>00198 }
<a name="l00199"></a>00199
<a name="l00200"></a>00200 <a class="code" href="secureclientandserver_8h.html#a5eadd4429627d82193b37536d4faa03a">_LIT</a>(KTextRevString,<span class="stringliteral">"\nReverse of the String: "</span>);
<a name="l00201"></a>00201 iConsole->Printf(KTextRevString);
<a name="l00202"></a>00202 <span class="comment">// Initialize the iterator.</span>
<a name="l00203"></a>00203 iIteratorString.SetToLast();
<a name="l00204"></a>00204
<a name="l00205"></a>00205 <span class="comment">// Iterate iReverseString.</span>
<a name="l00206"></a>00206 <span class="keywordflow">while</span>(iIteratorString != NULL)
<a name="l00207"></a>00207 {
<a name="l00208"></a>00208 <span class="comment">// Get the TLetter object pointed to by the iterator.</span>
<a name="l00209"></a>00209 <a class="code" href="class_t_letter.html">TLetter</a> letter = *iIteratorString;
<a name="l00210"></a>00210 <span class="comment">// Print the character value of the TLetter object.</span>
<a name="l00211"></a>00211 <a class="code" href="secureclientandserver_8h.html#a5eadd4429627d82193b37536d4faa03a">_LIT</a>(KTextChar,<span class="stringliteral">"%c"</span>);
<a name="l00212"></a>00212 iConsole->Printf(KTextChar,TUint(letter.<a class="code" href="class_t_letter.html#a1ce2b6bc97d7c647ee1adbf72aac5628">iChar</a>));
<a name="l00213"></a>00213 <span class="comment">// Set the iterator to point to the next element.</span>
<a name="l00214"></a>00214 iIteratorString--;
<a name="l00215"></a>00215 }
<a name="l00216"></a>00216 iConsole->Printf(KTextNewLine);
<a name="l00217"></a>00217 }
<a name="l00218"></a>00218
<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>()
<a name="l00223"></a>00223 {
<a name="l00224"></a>00224 <span class="keywordflow">if</span>(IsActive())
<a name="l00225"></a>00225 {
<a name="l00226"></a>00226 <span class="comment">// Cancel any outstanding read requests.</span>
<a name="l00227"></a>00227 iConsole->ReadCancel();
<a name="l00228"></a>00228 }
<a name="l00229"></a>00229 }
<a name="l00230"></a>00230
<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>()
<a name="l00237"></a>00237 {
<a name="l00238"></a>00238 <span class="comment">// Delete the elements from the list. </span>
<a name="l00239"></a>00239 iIteratorString.SetToFirst();
<a name="l00240"></a>00240 <span class="comment">// Iterate the list and delete all TLetter objects.</span>
<a name="l00241"></a>00241 <a class="code" href="class_t_letter.html">TLetter</a>* ptr = iIteratorString++;
<a name="l00242"></a>00242 <span class="keywordflow">while</span> (ptr != NULL)
<a name="l00243"></a>00243 {
<a name="l00244"></a>00244 <span class="keyword">delete</span> ptr;
<a name="l00245"></a>00245 ptr = iIteratorString++;
<a name="l00246"></a>00246 }
<a name="l00247"></a>00247 }
<a name="l00248"></a>00248
</pre></div></div>
<hr size="1"/><address style="text-align: right;"><small>Generated by
<a href="http://www.doxygen.org/index.html">
<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.6.2 </small></address>
</body>
</html>