Caret7:Development/Classes

From Van Essen Lab

Jump to: navigation, search

Contents

Classes

Naming

  • All names in the code are formatted using CamelCase. That is, all names consist of a sequence of words without spaces, underscores, or dashes.
  • Class names begin with a upper-case letter
  • Method names begin with a lower-case letter.
  • Member names begin with a lower-case letter.
  • Use descriptive names of a reasonable length.
  • The header and implementation files for a class are named exactly the same as the class (including any capitalization) with the appended .h or .cxx extension.

Base Class

Each class should be derived from CaretObject or QObject. CaretObject provides a method (that can be overridden) for printing information about an object and, when compiled debug, can track allocation of objects and report those that are not deleted. QObject is a parent of all Qt classes used in the Qt graphical user-interface.

Copy Constructor and Assignment Operator

If a class instance can be copied, both the copy constructor and the assignment operator should either be fully implemented and publicly accessible. Otherwise, both should be declared, without any implementation, in a private section of the header file.

Documenting

All classes should be commented using Doxygen style comments (very similar or the same as JavaDoc) so that Doxygen can generate documentation in HTML or other formats.

The documentation for a class should describe the purpose of the class.

Since classes have both header (.h) and implementation files (.cxx), add documentation comments on methods only to the implementation of the method. In most cases, this will be inside the implementation file with the exception of inline or other short methods defined in the header file. For a method, describe the purpose of the method, each of its parameters, the values returned, and why an exception is thrown.

Member variables should be documented unless the member's name clearly describes its contents.

Use JavaDoc style commenting which begins with /** and ends with */. If the comment spans more than one line, begin each line with an asterisk.

Example Header File


/**
 * A 4x4 homogeneous transformation matrix.
 */
class Matrix4x4 : public CaretObject {

public:
    Matrix4x4();

    ~Matrix4x4();

    double getMatrixElement(
                    const int32_t i,
                    const int32_t j) const;

    void writeAsXML(XmlWriter& xmlWriter) throw (XmlException);


protected:
    /**the 4x4 matrix */
    double matrix[4][4];
};

Example Implementation File

/**
 *
 * constructor that creates an identity matrix.
 *
 */
Matrix4x4::Matrix4x4()
    : CaretObject()
{
    this->initializeMembersMatrix4x4();
}

/**
 * Destructor
 */
Matrix4x4::~Matrix4x4()
{
}


/**
 * Get a matrix element.
 * @param i   Row
 * @param j   Column
 * @return   value at [i][j]
 *
 */
double
Matrix4x4::getMatrixElement(
                   const int32_t i,
                   const int32_t j) const
{
    return this->matrix[i][j];
}


/**
 * Write the metadata in GIFTI XML format.
 *
 * @param xmlWriter The XML Writer.
 * @throws XmlException if an error occurs while writing.
 */
void
Matrix4x4::writeAsXML(XmlWriter& xmlWriter) throw (XmlException)
{
}

Personal tools
Sums Database