﻿<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/"><channel><title>C++博客-我的博客-文章分类-S60 platform programming</title><link>http://www.cppblog.com/cheney-chen/category/6878.html</link><description> learning symbian C++</description><language>zh-cn</language><lastBuildDate>Mon, 19 May 2008 13:12:46 GMT</lastBuildDate><pubDate>Mon, 19 May 2008 13:12:46 GMT</pubDate><ttl>60</ttl><item><title>Name Conventions for Applications on Symbian OS</title><link>http://www.cppblog.com/cheney-chen/articles/Name_Conventions_for_Applications_on_Symbian_OS.html</link><dc:creator>cheney</dc:creator><author>cheney</author><pubDate>Sun, 27 Apr 2008 06:57:00 GMT</pubDate><guid>http://www.cppblog.com/cheney-chen/articles/Name_Conventions_for_Applications_on_Symbian_OS.html</guid><wfw:comment>http://www.cppblog.com/cheney-chen/comments/48259.html</wfw:comment><comments>http://www.cppblog.com/cheney-chen/articles/Name_Conventions_for_Applications_on_Symbian_OS.html#Feedback</comments><slash:comments>1</slash:comments><wfw:commentRss>http://www.cppblog.com/cheney-chen/comments/commentRss/48259.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/cheney-chen/services/trackbacks/48259.html</trackback:ping><description><![CDATA[<p><span style="FONT-SIZE: 18pt; FONT-FAMILY: Verdana">Overview</span></p>
<p>Applications on Symbian OS use a standard set of conventions to name their classes, structs, variables, functions, macros, enumerations, and constants. This topic explains the meaning of these conventions.<br><br></p>
<h2>&nbsp;</h2>
<p><span style="FONT-SIZE: 18pt; FONT-FAMILY: Verdana">Class names</span>&nbsp;</p>
<p>Most class names are formed with a prefix letter <code>C</code>, <code>T</code>, <code>R</code>, or <code>M</code>. Briefly, the meaning of these is as follows:&nbsp; <br></p>
<li>
<p><code>C</code>: heap-allocated classes, that are derived from a base class <code>CBase</code></p>
<li>
<p><code>T</code>: value classes, that do not own any external object</p>
<li>
<p><code>R</code>: resource classes, that contain handles to a real resource which is maintained elsewhere</p>
<li>
<p><code>M</code>: interface classes, that define abstract protocol definitions that are implemented by derived classes </p>
<p>Classes that consist solely of static member functions have no prefix letter. Beyond the prefix, the class name is usually a noun that indicates the purpose of the class.</p>
<p><br><span style="FONT-SIZE: 18pt; FONT-FAMILY: Verdana">Struct names</span><br></p>
<p>Structure types are considered as similar to <code>T</code> classes, as they should not own external objects, and are normally given names beginning with <code>T</code> (although some begin with <code>S</code>).<br><br><br><span style="FONT-SIZE: 18pt; FONT-FAMILY: Verdana">Variable names</span><br><br></p>
<p>Member variables names begin with <code>i</code>, e.g. <code>iMember</code>. This makes it easy to check that certain cleanup-related rules are being obeyed. Arguments names begin with <code>a</code>, e.g. <code>aControl</code> or <code>aIndex</code>. Local variables names have no initial letter. Global variables are usually avoided, but when used, their names begin with a capital letter.</p>
<p>Symbian OS does not use Hungarian or any notation which attempts to include the variable type in its name: such notations are ugly, and become impossible to manage when there are several hundred classes in the system. They are irrelevant anyway: functions are usually so short that it is easy to see the types of variables defined in them, and class browsers provide a quick way to find the types of class members.<br><br><br><span style="FONT-SIZE: 18pt; FONT-FAMILY: Verdana">Function names</span><br><br>Functions names indicate what they do. They are usually verbs. One exception is getter functions: for a function which returns the value of a member variable, the function name is usually the name of the variable, without the leading <code>i</code>:<br><br><font face="Courier New">inline RWindow&amp; Window() const { return iWindow; };</p>
<p style="FONT-FAMILY: Times New Roman">A corresponding setter function would include the word <code>Set</code>, e.g. <code>SetWindow()</code>.<br></p>
<p style="FONT-FAMILY: Times New Roman">To terminate functions because of error conditions, Symbian OS does not use standard C++ exception handling, but its own system called leaving (see <a href="file:///C:/Documents%20and%20Settings/Administrator/桌面/Base-subsystem-guide/e32/MemoryManagement/CleanupSupportOverview.guide.html#MemoryManagementOverview%2eCleanupSupportOverview%2emain">Cleanup Support Overview</a>). Any function that might leave has a name ending in <code>...L()</code>. This makes the fundamental process of checking for errors easier. The <code>new (ELeave)</code> function might also leave. The fundamental leaving function is <code>User::Leave()</code>. Any function that contains any of these, and does not trap them, might itself leave, and should be coded with a trailing <code>L</code> in its name. If a function calls another which might leave, then its name should have the <code>L</code> suffix also.</p>
<p style="FONT-FAMILY: Times New Roman">Associated with the leaving mechanism, is the cleanup stack, which allows memory allocated on the heap to be recovered when a leave occurs. An allocation or construction function which places data on the cleanup stack ends with <code>...LC()</code>. For instance, many <code>new</code>, <code>PushL()</code>, <code>ConstructL()</code> sequences are encapsulated in a <code>NewLC()</code> function:</p>
<p class=CodeBlock style="FONT-FAMILY: Times New Roman"><code>CS* s=CS::NewLC(p1, p2);</code></p>
<p style="FONT-FAMILY: Times New Roman">This allocates the object, initialises it, and leaves it on the cleanup stack. This process may leave (if only through the <code>PushL()</code>!), so such functions always include an <code>L</code>, and are therefore <code>...LC()</code>.</p>
<p style="FONT-FAMILY: Times New Roman">A function which takes ownership of its object and destroys it has a name ending in <code>...D()</code>. An example is the UI framework dialog protocol:</p>
<p class=CodeBlock style="FONT-FAMILY: Times New Roman"><code>CEikDialog* dialog=new (ELeave) CBossSettingsDialog;<br>if (dialog-&gt;ExecuteLD(R_BOSS_SETTINGS_DIALOG))<br>&nbsp;&nbsp;&nbsp;&nbsp;{<br>&nbsp;&nbsp;&nbsp;&nbsp;// handle successful settings<br>&nbsp;&nbsp;&nbsp;&nbsp;}</code></p>
<p style="FONT-FAMILY: Times New Roman">The <code>ExecuteLD()</code> function includes second-phase construction, execution of the dialog and then destruction.<br><br><br><span style="FONT-SIZE: 18pt; FONT-FAMILY: Verdana">Macro names<br></span><br>Macro names are all capitalised, with underscores to separates words.<br><br><br><span style="FONT-SIZE: 18pt; FONT-FAMILY: Verdana">Enumeration names<br></span><br></p>
<p style="FONT-FAMILY: Times New Roman">Enumerations are named as follows:<br></p>
<ul>
    <li>as enumerations are types, they have the <code>T</code> prefix
    <li>enumeration members have the prefix <code>E</code>
    <li>type and members should have a meaningful, unambiguous name </li>
</ul>
<p style="FONT-FAMILY: Times New Roman">Enumerations should be scoped within the relevant class, so as not to pollute the global name space.</p>
<p style="FONT-FAMILY: Times New Roman">An example of the declaration and use of an enumeration is as follows:</p>
<p class=CodeBlock style="FONT-FAMILY: Times New Roman"><code>class TDemo<br>&nbsp;&nbsp;&nbsp;&nbsp;{<br>public:<br>&nbsp;&nbsp;&nbsp;&nbsp;enum TShape {EShapeRound, EShapeSquare};<br>&nbsp;&nbsp;&nbsp;&nbsp;};<br><br>TDemo::TShape shape=TDemo::EShapeSquare;</code></p>
</font>
<p><br><span style="FONT-FAMILY: Verdana"><br></span><span style="FONT-SIZE: 18pt">Constant names<br></span><br>Names of constants have a prefix K. For example,<br><br><span style="FONT-FAMILY: courier new">const TInt KMaxNameLength=0x20;</span></p>
</li>
<img src ="http://www.cppblog.com/cheney-chen/aggbug/48259.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/cheney-chen/" target="_blank">cheney</a> 2008-04-27 14:57 <a href="http://www.cppblog.com/cheney-chen/articles/Name_Conventions_for_Applications_on_Symbian_OS.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item></channel></rss>