Code Formatting Conventions

From OpenMW Wiki
Revision as of 02:26, 8 August 2011 by Rhys (talk | contribs) (Created page with "==Layout & Indention== This is an example of the layout & indention style we encourage. <div dir="ltr" style="text-align: left"><div class="source-cpp"><font face="mono...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

Layout & Indention

This is an example of the layout & indention style we encourage.

namespace SomeSpace
{
    class SomeClass
    {
        private:
 
            int mSomeVar;
 
        public:
 
            float someFunction (float p1, float p2) const;
    };
}
namespace SomeSpace
{
    float SomeClass::someFunction (float p1, float p2) const
    {
        return p1 p2;
    }
}

Note that the indention width is 4 spaces. We are not too strict about these rules, but if you use tabs instead of spaces, you have a decent chance to piss us off. Mixing spaces and tabs is not good.

Includes

An implementation file (cpp) should always start by including its own header.

Further includes should be grouped. Groups must be separated by an empty line.

Standard C and C headers

Example:

#include <string>

C headers (if any) should be listed before the C headers.

External libraries headers

#include <OgreVector3.h>

If more than one external library is used, each library's headers should be put into a separate group.

OpenMW-related library headers

OpenEngine and mangle.

#include <openengine/ogre/renderer.hpp>

If both OpenEngine and mangle are present, mangle includes should be put into a separate group listed before the OpenEngine includes.

Note: If you are including from OpenEngine you would instead write:

#include "renderer.hpp"

or

#include "ogre/renderer.hpp"

or even

#include "../renderer.hpp"

depending on the directory, where the including file is located. This rule applies to the following groups too.

Components headers

#include <ocomponents/compiler/context.hpp>

Apps headers

#include <mwworld/world.hpp>

Local headers

#include "world.hpp"

Doxygen Comments

Class definitions and function declarations should have doxygen comments. We aren't very strict about this though (especially for trivial functions).

A class should be documented like this:

/// \brief short description
///
/// Longer description.
class SomeClass

The longer description can be skipped, if there is nothing more to say.

A function should be documented like this:

/// Description.
void someFunction();

or this:

void someFunction();
///< Description.


Here is a link to the Doxygen Documentation. Please make plenty of use of the listed commands, especially the following:

  • \a
  • \arg
  • \attention
  • \brief
  • \note
  • \p
  • \return
  • \todo