Rules and Standards

CAA V5 C++ Interface and Class Documentation Rules

Hints and tips to tag and write comments in your header files

Technical Article

Abstract

This 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.


What Do You Need to Document?

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]

How Do You Document?

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]

A Simple Sample

 

SampleClass1.jpg (92683 bytes)

SampleClass2.jpg (72469 bytes)

SampleClass3.jpg (54334 bytes)

[Top]

Writing Comments

You will find below some tips to write comments for classes, interfaces, constructors, methods, global functions, enums, operators, struct, data members, and typedef.

[Top]

Writing Class Comments

Do:

Don't:

Refer to the following examples:

Header File html File
CATCommand.h CATCommand.htm
CATUnicodeString.h CATUnicodeString.htm

[Top]

Writing C++ Interface Comments

Do:

Don't:

Header File html File
IClassFactory.h IClassFactory.htm A COM interface
CATIPrintable.h CATIPrintable.htm A CNext interface

[Top]

Writing Constructor Comments

Do:

Don't:

Refer to the following examples:

Header File html File
CATUnicodeString.h CATUnicodeString.htm

[Top]

Writing Method Comments

Do:

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]

Writing Global Function Comments

Do:

Don't:

Refer to the following example:

Header File html File
CATInstantiateComponent.h CATInstantiateComponent.htm

[Top]

Writing Macro and #define Comments

Do:

Don't:

Refer to the following examples:

Header File html File
CATMacForIUnknown.h CATDeclareClass.htm
CATBeginImplementClass.htm
CATEndImplementClass.htm
CATAddClassExtension.htm
CATImplementClass.htm
CATDlgEngUtility.h CATDlgEngBehavior.htm
CATGeometryType.h CATGeometryType.htm

[Top]

Writing Collection Comments

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]

Writing Enumeration Comments

Do:

Don't:

Refer to the following examples:

Header File html File
CATCommandMode.h CATCommandMode.htm
CATCommandMsg.h CATCommandMsg.htm

[Top]

Writing Operator Comments

Do:

Don't:

Refer to the following examples:

Header File html File
CAT4x4MatrixOperators.h CAT4x4MatrixOperators.htm

[Top]

Writing Structure Comments

Do:

Don't:

Refer to the following examples:

Header File html File
CAT2DGeomTextPixmap.h CAT2DGeomTextPixmap.htm

[Top]

Writing Data Member Comments

Do:

Don't:

Refer to the following examples:

Header File html File
CATExtIUIActivate.h CATExtIUIActivate.htm

[Top]

Writing typedef and constant Comments

Do:

Don't:

Refer to the following examples:

Header File html File
CATCommandMethod.h CATCommandMethod.htm
CATCommandClientData.h CATCommandClientData.htm

[Top]

Tips

These tips can help you in the following areas:

These tags are:

[Top]

Tips for HRESULT

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]

Tips for Lists

You usually provide methods to scan your lists and collections, and to retrieve a given object from the collection. It can be thanks to:

[Top]

Tips for Weak Typing

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]

CNext Tag Reference

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]

@collection

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]

@deprecated

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]

@description

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 component  of self.
 * @description 
 *   This function returns a reference to component  of self.
 */ 
reference operator[]( CoordinateIndex coordIndex )

[Top]

@exception

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]

@example

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 component  of 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]

@href

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]

@nodoc

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]

@param

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]

@return

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]

@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. 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 and @EOM

@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:

o normalize
public void normalize ( ) DNB_THROW_SPEC((DNBEZeroVector))

[Top]

Named Field Reference

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]

Lifecycle Rules

Memory Management for Non-scalar types (Except Interfaces)

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++:

  1. Heap allocation. It is done using the C++ new and delete operators. This mechanism can be used for all three kinds of parameters (in, out, inout). If you use other means, such as malloc and free, you must describe them
  2. Stack allocation (auto variables). This mechanism can be only be used if the variable is allocated and deallocated in the same scope. Thus, it can only be used for in parameters.

[Top]

Reference Counting for Interfaces

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]

html Tag Reference

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]

Setting Hyperlinks

Hyperlink anchors are automatically generated on the following entities:

Hyperlink syntax:

[Top]

[Top]


History

Version: 1 [Dec 2000] Document created
[Top]

Copyright © 2000, Dassault Systèmes. All rights reserved.