Rules and Standards |
CAA V5 C++ Interface and Class Documentation RulesHints and tips to tag and write comments in your header files |
Technical Article |
AbstractThis article gives you information on how you can document your interface and class header files using specific comments that are processed to build html files.
|
Each of the following entity declared as L1 must be documented.
This applies to L1 entities that are located in the PublicInterfaces directories of the exposed frameworks. This includes members declared as public, and for classes that can be derived, members declared as protected.
[Top]
Interfaces, classes, and all the stuff they include, are documented thanks to information enclosed into specific comments inserted in the header files. The C++ statements and the comments are then processed to produce an organized set of html files in which you and the users of your interfaces and classes can navigate. These comments are as follows:
/** * This is a comment. */ |
They must begin by /**
and end by */
. Each
intermediate line must begin by a leading *
.
Never use such a comment for any other purpose than documentation, otherwise
your internal comments will be processed and clearly readable, and moreover may
pollute automatically generated lists and index.
A comment must be placed just before the line containing the declaration of the class, interface, method, etc., it is intended to describe.
/** * Base class for creating and for implementing interfaces. * CATBaseUnknown supplies the infrastructure and the basic mechanisms * to create interface abstract classes and to manage interface pointers. */ class ExportedByJS0CORBA CATBaseUnknown : public IDispatch { ... |
[Top]
[Top]
You will find below some tips to write comments for classes, interfaces, constructors, methods, global functions, enums, operators, struct, data members, and typedef.
[Top]
Do:
Don't:
Refer to the following examples:
Header File | html File |
---|---|
CATCommand.h | CATCommand.htm |
CATUnicodeString.h | CATUnicodeString.htm |
[Top]
Do:
Don't:
Header File | html File | |
---|---|---|
IClassFactory.h | IClassFactory.htm | A COM interface |
CATIPrintable.h | CATIPrintable.htm | A CNext interface |
[Top]
Do:
Reminder of CNext rules and naming conventions
Don't:
Refer to the following examples:
Header File | html File |
---|---|
CATUnicodeString.h | CATUnicodeString.htm |
[Top]
Do:
Reminder of CNext rules and naming conventions
Begin an argument definition using the definite article The. For example, write The point coordinates, or The dialog agent. You can use A instead of The if there is a part of indetermination, such as A pointer to the IUnknown interface, if the pointer is not explicitly defined or used in the description beforehand.
Refer to interfaces or global functions for HRESULT examples.
Don't:
Header File | html File | |
---|---|---|
CATDialogTransition.h | CATDialogTransition.htm | |
CyclicReference.cpp | CyclicReference.htm | Cyclic reference examples |
[Top]
Do:
Reminder of CNext rules and naming conventions
Don't:
Refer to the following example:
Header File | html File |
---|---|
CATInstantiateComponent.h | CATInstantiateComponent.htm |
[Top]
Do:
Don't:
Refer to the following examples:
[Top]
Do:
Don't:
Refer to the following examples:
Header File | html File | |
---|---|---|
CATListOfCATFrmWindow.h | CATListOfCATFrmWindow.htm | Collection with all methods |
CATListOfCATDlgControl.h | CATListOfCATDlgControl.htm | Collection with almost all methods |
CATListOfCATDlgNotify.h | CATListOfCATDlgNotify.htm | Collection with few methods |
[Top]
Do:
Don't:
Refer to the following examples:
Header File | html File |
---|---|
CATCommandMode.h | CATCommandMode.htm |
CATCommandMsg.h | CATCommandMsg.htm |
[Top]
Do:
Operator | Short Role |
---|---|
Equality operators | |
== |
Equality operator. |
!= |
Inequality operator. |
Relational operators | |
< |
Less-than operator. |
<= |
Less-than or equal operator. |
> |
Greater-than operator. |
>= |
Greater-than or equal operator. |
Prefix operators | |
++ |
Prefix increment operator. |
-- |
Prefix decrement operator. |
Postfix operators | |
[] |
Subscripting operator. |
. |
Member-selection operator. |
-> |
Member-selection operator. |
++ |
Postfix increment operator. |
-- |
Postfix decrement operator. |
Unary operators | |
+ |
Unary plus operator. |
- |
Arithmetic-negation operator. |
~ |
Bitwise-complement (or bitwise-NOT) operator. |
! |
Logical-negation (or logical-NOT) operator. |
* |
Indirection (or dereference) operator. |
& |
Address-of operator. |
() |
Cast (or type cast, or conversion) operator. |
Additive operators | |
+ |
Addition operator. |
- |
Subtraction operator. |
Multiplicative operators | |
* |
Multiplication operator. |
/ |
Division operator. |
% |
Remainder (or modulus) operator. |
Bitwise operators | |
& |
Bitwise AND operator. |
^ |
Bitwise-exclusive-OR operator. |
| |
Bitwise-inclusive-OR operator. |
Bitwise shift operators | |
<< |
Bitwise left shift operator. |
>> |
Bitwise right shift operator. |
Logical operators | |
&& |
Logical-AND operator. |
|| |
Logical-OR operator. |
Assignment operators | |
= |
Assignment operator. |
*= |
Multiplication assignment operator. |
/= |
Division assignment operator. |
%= |
Remainder (or modulus) assignment operator. |
+= |
Addition assignment operator. |
-= |
Subtraction assignment operator. |
<<= |
Left-shift assignment operator. |
>>= |
Right-shift assignment operator. |
&= |
Bitwise-AND assignment operator. |
^= |
Bitwise-exclusive-OR assignment operator. |
|= |
Bitwise-inclusive-OR assignment operator. |
&= |
Bitwise-AND assignment operator. |
Other operators | |
:: |
Scope resolution operator. |
?: |
Conditional-expression operator. |
, |
Sequential-evaluation (comma) operator. |
Don't:
Refer to the following examples:
Header File | html File |
---|---|
CAT4x4MatrixOperators.h | CAT4x4MatrixOperators.htm |
[Top]
Do:
Don't:
Refer to the following examples:
Header File | html File |
---|---|
CAT2DGeomTextPixmap.h | CAT2DGeomTextPixmap.htm |
[Top]
Do:
Don't:
Refer to the following examples:
Header File | html File |
---|---|
CATExtIUIActivate.h | CATExtIUIActivate.htm |
[Top]
Do:
Don't:
Refer to the following examples:
Header File | html File |
---|---|
CATCommandMethod.h | CATCommandMethod.htm |
CATCommandClientData.h | CATCommandClientData.htm |
[Top]
These tips can help you in the following areas:
These tags are:
[Top]
If your method returns only S_OK
and E_FAIL
, do
not include a Returns section.
Otherwise, if the method can return more than S_OK
and
E_FAIL
, write your list of HRESULT legal values as follows:
... * @return * An HRESULT value. * <br><b>Legal values</b>: * <dl> * <dt>S_OK</dt> * <dd>The component is successfully created * and the interface pointer is successfully returned</dd> * <dt>E_FAIL </dt> * <dd>The component was successfully created, * but the interface query failed</dd> * <dt>E_NOINTERFACE </dt> * <dd>The component was successfully created, * but the it doesn't implement the requested interface</dd> * <dt>E_OUTOFMEMORY </dt> * <dd><dd>The component allocation failed</dd> * </dl> */
[Top]
You usually provide methods to scan your lists and collections, and to retrieve a given object from the collection. It can be thanks to:
InitTransitionList
below, the other to retrieve the
pointed object and move the pointer to the next object, such as
GetNextTransition
.
/** * Points to the first command transition. * @see #GetNextTransition */ virtual void InitTransitionList(); /** * Returns the pointed command transition and points to the next one. * <br><b>Precondition</b>: Set the pointer to the first command transition * using @href #InitTransitionList before traversing out the command transition * list using calls to GetNextTransition enclosed in a loop. */ virtual CATDialogTransition * GetNextTransition();
GetElementTypeSize
, the other to retrieve the ith item, such as
GetElementType
.
/** * Returns the count of element types expected by the dialog agent. * <br><b>Legal values</b>: * The count of element types ranges from 1 to n. */ int GetElementTypeSize(); /** * Returns an element type from those expected by the dialog agent using the element type index. * <br><b>Role</b>: This method returns the <tt>iIndex</tt>th element type * from those expected by the dialog agent and set using the @href #SetElementType method. * @param iIndex * The index of the element type . * <br><b>Legal values</b>: <tt>iIndex</tt> range starts with 1, which is the default. * Use @href #GetElementTypeSize to get the element type count. */ CATClassId GetElementType(int iIndex = 1);
[Top]
Your methods have often weak typed parameters that you didn't want to specialize to ensure future evolutions. For example, a method takes a pointer to CATBaseUnknown as a parameter, but you expect in fact a pointer to a more specific interface. This can also be the case of a return value. The type into which the pointer must be cast to become usable, or the interface to query from the returned one must be described. Nowhere else will the client application programmer get this information.
/** * Retrieves the object that does what you want. * @param oObject * The retrieved object. * <br><b>Legal values</b>: The object retrieved is an instance of a * a CATSpecObject. Cast the pointer to CATSpecObject to use it. */ public HRESULT GetObject(CATBaseUnknown ** oObject);
[Top]
Some specific tags are used to denote specific entities and generate html tags to present this information consistently. These tags begin with the "at" sign, or @. These tags are:
Tag | Definition |
---|---|
@collection | To identify and provide the name of a collection class |
@deprecated | To denote that an entity is deprecated |
@description | To create a description section |
@exception | To create a Throws section to describe the exceptions thrown by the method |
@example | To create an example section |
@href | To create a hyperlink to other documented entities anywhere in the text |
@nodoc | To denote each entity that you don't want to see in the extracted html file |
@param | To denote each method or global function parameter, enum value, struct member, and possibly typedef value |
@return | To create a Returns section to describe the returned value of a method |
@see | To create a See also section that contains hyperlinks to other documented entities, usually located at the end of the role of a class or method |
@SOM and @EOM | To delimite a Macro Usage in a C++ header. |
[Top]
To identify and provide the name of a collection class. The comment should be inserted at the top of the file, just below the Level and Usage comment, and must be the only comment in the file.
... // COPYRIGHT DASSAULT SYSTEMES 1999 /** * @CAA2Level L1 * @CAA2Usage U1 */ /** * @collection CATLISTP(CATUnicodeString) * Collection class for Unicode strings. * ... */
[Top]
To denote each entity that should not be used.
/** * @deprecated V5R8 * Removes a file descriptor subscription from a command. * This method will be replaced by @href myClass#myMethod * The signature of the method has been changed to manage a new functionnality * @param iFileDescriptor * The file descriptor. * @param iToClient * The command for which the subscription is to be removed. * @return 0 if the file descriptor subscription is successfully removed and 0 otherwise. * @see #AddFileDescriptor */ int RemoveFileDescriptor(int iFileDescriptor, CATCommand * iToClient);
The replacing entity, if any, can be specified using the @see
or @href
syntax, as follows:
/** * @deprecated V5R8 IUnknown#QueryInterface * ...
[Top]
To create a description section to describe an object.
/** * Retrieves a reference to an element of self. * @param coordIndex * [in] The index of the desired coordinate (e.g., DNBMath3D::X). * @return * A reference to componentof self. * @description * This function returns a reference to component of self. */ reference operator[]( CoordinateIndex coordIndex )
[Top]
To create a Throws section to describe the exceptions thrown by the method
/** * Checks that the class to document belongs to JJA's list. * ... * @exception @href CATSystemError if JJA's laptop is not connected to the network */ HRESULT Check(CATBaseUnknown * pClass);
[Top]
To create an example section.
/** * Retrieves a reference to an element of self. * @param coordIndex * [in] The index of the desired coordinate (e.g., DNBMath3D::X). * @return * A reference to componentof self. * @example * DNBVector3D vector; * vector[ DNBMath3D::X ] = 1.0; * vector[ DNBMath3D::Y ] = 2.0; * vector[ DNBMath3D::Z ] = 3.0; * DNBReal x = vector[ DNBMath3D::X ]; */ reference operator[]( CoordinateIndex coordIndex )
[Top]
To create a hyperlink to other documented entities anywhere in the text.
/** * A collection of all the CATCamera instances attached to a document. * A camera can be created using the @href CATViewer#NewCamera method. * The first seventh cameras of the collection are @href CATCamera3D * objects and cannot be modified or removed. */ interface CATIACameras : CATIACollection
Do not use tags for monospace fonts (<tt>
or <code>
)
in hyperlinks. See Using Hyperlinks to know which
hyperlinks you can use.
[Top]
To denote each entity that you don't want to see in the extracted html file.
/** * @nodoc */ CATNotification * GetRadBModifyNotification() const; /** @nodoc */ virtual l_CATDialog* GetLetterObject(); /** * @nodoc * Sets the radio button state. * @param iState * The radio button state. * <b>Legal values</b>: It can be set to either * <tt>CATDlgCheck</tt> to check the radio button or to * <tt>CATDlgUncheck&lgt;/tt> to uncheck it. * @param iNotify * Requests that a notification be sent when the state is set. * This notification is an instance of the CATDlgRadBModifyNotification * class. * <b>Legal values</b>: 0 to send the notification, and 1, or a non null * value, to prevent from sending it. 1 is the default. */ void SetState(CATULong iState, int iNotify=1);
[Top]
To denote each method or global function parameter.
/** * Constructs a radio button. * @param iParent * The radio button command and containment parent. * @param iObjectName * The radio button identifier. * This identifier is used to assign resources to the radio button, * namely its title displayed beside it. * @param iStyle * The radio button style. * <br><b>Legal values</b>: The default style expressed by the * NULL default value sets the radio button title to the right * of the radio button. * This is the only available style */ CATDlgRadioButton(CATDialog * iParent, const CATString & iObjectName, CATDlgStyle iStyle=NULL);
[Top]
To create a Returns section to describe the returned value of a method.
/** * Analyzes a notification received. * ... * @return * The notification propagation mode. * <br><b>Legal values</b>: <tt>CATNotifTransmitToFather</tt> (=0) * if the notification should go on along the command tree structure, or * <tt>CATNotifDontTransmitToFather</tt> (=1) if it should stop. */ virtual CATNotifPropagationMode AnalyseNotification(CATCommand * iFromClient, CATNotification * iNotification);
If the returned value can take all the values of the enum, the hyperlink set by mkman to the enum documentation can be enough. Nevertheless, if a only subset of these values can be returned, or if the meaning of is context-dependent, you must use the Legal values named field.
If the method returns a HRESULT, you can find examples in global functions.
[Top]
To create a See also section that contains hyperlinks to other documented entities, usually located at the end of the role of a class or method. Use the comma to separate two successive entity.
/** * Base class for all collaborating objects. * <tt>CATCommand</tt> is the base class for all objects that need to collaborate by * means of * <ul> * <li>The send/receive communication protocol</li> * <li>The callback mechanism.</li> * </ul> * <p><tt>CATCommand</tt> supplies the methods to convey notifications and their * associated data to the object either able to process user's requests in response * to user interactions, or that has set callbacks on to user activable objects. * @see CATCallbackManager, CATNotification */ class ExportedByJS0FM CATCommand : public CATEventSubscriber
Another example about an enumeration to refer to methods that are members of the same class that the enum.
/** * Subscribing type, used as parameter of the methods <tt>Subscribe</tt> and * <tt>RemoveSubscribe</tt>. * @param CATSubscribeEndTransaction * The subscribing command must be called when the transaction is completed * @param CATSubscribeIdle * The call must be performed when the process enters the main event loop * @see #Subscribe, #RemoveSubscribe */ enum { CATSubscribeEndTransaction=1, CATSubscribeIdle =2 };
See Using Hyperlinks to know which hyperlinks you can use.
[Top]
@SOM
(Start Of Macro) and @EOM
(End Of Macro)
delimit a macro usage in a C++ header. mkman does not replace the macro by its
contents like the preprocessor. It simply identifies the enclosed statement as
a macro and thus does not attempt to parse it, and copies the macro in the
output html file as it is in the header file.
Header file:
void normalize() /**@SOM*/ DNB_THROW_SPEC((DNBEZeroVector)) /**@EOM*/ ;
HTML File:
public void normalize | ( | ) | DNB_THROW_SPEC((DNBEZeroVector)) |
[Top]
Some comments may appear repeatitively, such as the parameter legal values, or the deviation to the lifecycle management. Use name fields to describe them. Available name fields are:
Named Field html Tags | Definition |
---|---|
<b>Role</b>: | To describe the role of a class, an interface, a global function, an enum, a macro, a typedef |
<br><b>Role</b>: | To describe the role of a method or data member |
<br><b>Precondition</b>: | To describe the valid system context or state required before calling the method. Applies to methods |
<br><b>Postcondition</b>: | To describe the system context or state that the method leaves or should leave when returning. Applies to methods |
<br><b>Cyclic reference</b>: | To describe potential cycles between objects due to mutual interface pointers or smart pointers stored as data members, and that could never be released. Applies to method parameters. Refer to CyclicReference.cpp and to CyclicReference.htm for examples. |
<br><b>Legal values</b>: | To describes parameter range of valid values, including the default value. Applies to method parameters |
<br><b>Lifecycle rules deviation</b>: | To describe deviations with respect to lifecycle rules. Applies to method parameters |
[Top]
When calling member functions, parameters with non scalar types (structures, character strings, classes) memory must be allocated and deallocated according to strict rules in order to avoid memory leaks or untimely memory release.
There are two memory allocation mechanisms in C++:
[Top]
Parameters of type interface must use the rules defined by COM for memory management. COM defines two functions IUnknown::AddRef() and IUnknown::Release() to perform reference counting (see <10> for examples).
AddRef must be called on interface pointers in the following situations:
Release must be called on interface pointers in the following situations:
Note that in the case of in parameters, it is not necessary to call AddRef before calling the member function and Release upon return of the member function.
[Top]
You can use html tags in your comments, except tags, such as <H1>, <H2>, as any other structuring tags. Main html tags you can use are:
Tag | Definition |
---|---|
<br> | To insert a line break |
<p> | To create a new paragraph |
<b>bold</b> | To enclose a text that should be rendered in boldface: bold |
<i>italic</i> | To enclose a text that should be rendered in italic font: italic |
<tt>monospace</tt> | To enclose a text that should be rendered in monospace font.
You can also use <code> and </code> . Use these
tags to enclose class names, method names, enum values, etc. that you don't
use as hyperlinks, that is that do not follow a @see or
a @href tag |
<pre> and </pre> | To enclose lines that should be rendered with existing line breaks and using monospace font. It forces a line break |
<ul> and </ul> | To specify that the following block of text is a bulleted (or unordered) list. Each item begins with a <li> |
<ol> and </ol> | To specify that the following block of text is an ordered list. Each item begins with a <li> |
<dl> and </dl> | To specify that the following block of text is a definition list. Each defined term is denoted with <dt>, and each associated definition is denoted using <dd> |
[Top]
Hyperlink anchors are automatically generated on the following entities:
... @href CATBaseUnknown ... ... @see CATBaseUnknown
Note that the htm suffix must not be used.
Use @href CATCommand#CATCommand to instantiate commands.
that sets the same hyperlinks as:
<a href="../System/CATCommand.htm#CATCommand">CATCommand::CATCommand</a>
which reads in the html file as follows:
Use CATCommand::CATCommand to instantiate commands.
This hyperlink leads to the beginning of the section where the first overloaded method is found.
Preferably, use this hyperlink in place of the following if you don't need to refer to a specific method among the set of overloaded methods.
CATCommand(CATCommand*,CATString*const)
for the CATCommand constructor:
CATCommand(CATCommand * iEventManager, CATString * const iName);
Leading and trailing blanks are removed, as well as blanks and dummy arguments in signatures. You can refer to such a method as follows:
... @href CATCommand#CATCommand(CATCommand*,CATString*const) ...
that sets the hyperlink as:
<a href="../System/CATCommand.htm#CATCommand(CATCommand * iEventManager, CATString * const iName)">CATCommand.CATCommand</a>
This hyperlink directly leads to the appropriate method.
Preferably, don't use this hyperlink. Use the preceding hyperlink instead if you don't need to refer to a specific method among the set of overloaded methods.
Hyperlink syntax:
@see CATBaseUnknown
or @href CATBaseUnknown
sets an hyperlink to the class CATBaseUnknown. It can only be used from any
entity that IS NOT a CATBaseUnknown member@see CATBaseUnknown#AddRef
or @href
CATBaseUnknown#AddRef
sets an hyperlink to the CATBaseUnknown::AddRef
method. It can only be used from any entity that IS NOT a
CATBaseUnknown member@see #AddRef
or @href #AddRef
sets an hyperlink
to the AddRef method. It can only be used from any entity that
IS a CATBaseUnknown member.[Top]
[Top]
Version: 1 [Dec 2000] | Document created |
[Top] |
Copyright © 2000, Dassault Systèmes. All rights reserved.