Skip to content

CodingRules

Matthias Fuchs edited this page Apr 17, 2012 · 1 revision

Header Files

Include Guards

Avoid multiple inclusion of header files by the mandatory code snippet:

#ifndef <NAMESPACE>_<HEADER_FILE>
#define <NAMESPACE>_<HEADER_FILE>
.
.
.
#endif  // <NAMESPACE>_<HEADER_FILE>

Here <NAMESPACE> is a wild card for the corresponding namespace where the class is valid and <HEADER_FILE> for the actual file name. Notice that all variables of this construction have to be written in capital letters.

Example: The class Stream in the namespace stromx_core is declared in /stromx/core/Stream.h as follows:

#ifndef STROMX_CORE_STREAM_H
#define STROMX_CORE_STREAM_H
.
.
.
#endif  // STROMX_CORE_STREAM_H

Includes

Include directives should be inserted by the following scheme

  1. Headers of nonnative libraries (e.g. boost, xercesc) (in alphabetical order)
  2. Standard C/C++ headers (in alphabetical order)
  3. Headers of stromx library (in alphabetical order)

Use "header.h" style inclusion to include headers of compilation units which are compiled and linked together with the current compilation unit. These header paths are always expected to be relative to the current files. Headers of libraries which are linked dynamically to the current target should be included using <header.h>. The paths to these headers are expected to be passed to the compiler.

Example:

#include <boost/thread.hpp>
#include <boost/thread/mutex.hpp>
#include <xercesc/dom/DOM.hpp>
#include <string>
#include <vector>
#include "Stream.h"

Key Words

The typical key words for a C++ class should be used in the order public, protected, private. Since any kind of elements of Standard-C should be avoided always use class instead of struct!

Example:

class Stream
{
public:
...
protected:
...
private:
...
};

Variables

All variables should have a reasonable name to provide better readability of the code. In case of a member variable of a class, it is mandatory to denote the variable by appending the prefix <m_var>.

Example: class Stream { ... private: std::string& m_name; ... };

Clone this wiki locally