Contents
The developers of Orthanc should follow these C++ Programming Style Guidelines, that are similar to the so-called “BSD/Allman style”, with some adaptations that are described below. A compliant Eclipse formatter is available in the Orthanc distribution (not maintained anymore).
Do not forget to include licensing information (GPLv3 with OpenSSL
exception) in each .cpp
and .h
.
No tab characters. Replace 1 tab by 2 spaces.
Rule 31: Use COLOR_RED
instead of Color::RED
Rule 34: Use the suffix .cpp
Rule 35: A single header file must contain a single public class
Rule 72: Use the Example 2 style (aka. Allman style, used by MSDN and Visual Studio):
while (!done)
{
doSomething();
done = moreToDo();
}
Rule 6: The names of the methods are camel-case to move the coding style closer to that of the .NET framework.
Rule 36:
.h
,Rule 40: Use #pragma once
in each header file (cf. Wikipedia)
Rules 73 and 80: Use Visual Studio’s default style that does not add two whitespaces in front of public, protected, private and case:
class SomeClass : public BaseClass
{
public:
...
protected:
...
private:
...
};
static_cast
, reinterpret_cast
,
dynamic_cast
and const_cast
.using namespace
in header files (except inside inline
implementations).Finalize
is the complementary word to
Initialize
.catch (...)
, except when protecting non-Orthanc code.Except when clearly stated in the documentation:
delete
it. The object is allowed to keep this reference in a
member variable. The caller must ensure that the referenced object
will not be freed between the object that references it.NULL
) of
some resource: In such a case, the pointer must not be freed.