comparison Sphinx/source/developers/coding-style.rst @ 25:669ea65ba7fb

fix links
author Sebastien Jodogne <s.jodogne@gmail.com>
date Wed, 20 Jul 2016 09:26:08 +0200
parents 25fa874803ab
children d217af5e6cb3
comparison
equal deleted inserted replaced
24:25fa874803ab 25:669ea65ba7fb
50 * One-liners are always ok in a ``.h``, 50 * One-liners are always ok in a ``.h``,
51 * High-performance code is also allowed but only with the inline 51 * High-performance code is also allowed but only with the inline
52 keyword (the code being moved at the end of the header) 52 keyword (the code being moved at the end of the header)
53 53
54 * Rule 40: Use ``#pragma once`` in each header file (cf. `Wikipedia 54 * Rule 40: Use ``#pragma once`` in each header file (cf. `Wikipedia
55 <http://en.wikipedia.org/wiki/Pragma_once>`__) 55 <https://en.wikipedia.org/wiki/Pragma_once>`__)
56 * Rules 73 and 80: Use Visual Studio's default style that does not add 56 * Rules 73 and 80: Use Visual Studio's default style that does not add
57 two whitespaces in front of public, protected, private and case:: 57 two whitespaces in front of public, protected, private and case::
58 58
59 class SomeClass : public BaseClass 59 class SomeClass : public BaseClass
60 { 60 {
69 69
70 Additional Rules 70 Additional Rules
71 ---------------- 71 ----------------
72 72
73 * Use C++ exceptions, avoid error codes. 73 * Use C++ exceptions, avoid error codes.
74 * Use the `RAII design pattern <http://en.wikipedia.org/wiki/RAII>`__ (Resource Allocation Is Initialization) wherever possible. 74 * Use the `RAII design pattern <https://en.wikipedia.org/wiki/RAII>`__ (Resource Allocation Is Initialization) wherever possible.
75 * No C-style casting, use ``static_cast``, ``reinterpret_cast``, 75 * No C-style casting, use ``static_cast``, ``reinterpret_cast``,
76 ``dynamic_cast`` and ``const_cast``. 76 ``dynamic_cast`` and ``const_cast``.
77 * Never use ``using namespace`` in header files (except inside inline 77 * Never use ``using namespace`` in header files (except inside inline
78 implementations). 78 implementations).
79 * Complement to rule 20: ``Finalize`` is the complementary word to 79 * Complement to rule 20: ``Finalize`` is the complementary word to
80 ``Initialize``. 80 ``Initialize``.
81 * Minimize the number of #include in header files. 81 * Minimize the number of #include in header files.
82 * Never use ``catch (...)``, except when protecting non-Orthanc code. 82 * Never use ``catch (...)``, except when protecting non-Orthanc code.
83 * To ease unit testing, favor the `JavaBeans 83 * To ease unit testing, favor the `JavaBeans
84 <http://en.wikipedia.org/wiki/Java_beans>`__ conventions: 84 <https://en.wikipedia.org/wiki/Java_beans>`__ conventions:
85 85
86 * Single constructor without argument, 86 * Single constructor without argument,
87 * Use getters/setters. 87 * Use getters/setters.
88
89
90 Conventions for pointers and references
91 ---------------------------------------
92
93 Except when clearly stated in the documentation:
94
95 * A function that receives a **reference** to an object as an argument
96 is not responsible for the lifecycle of the object, and must not
97 ``delete`` it. The object is allowed to keep this reference in a
98 member variable. The caller must ensure that the referenced object
99 will not be freed between the object that references it.
100 * A function that receives a **pointer** to an object as an argument
101 takes the ownership of the object.
102 * A function that returns a **reference** to an object indicates that
103 the object should not be freed by the caller.
104 * A function that returns a **pointer** to an object transfers its
105 ownership to the caller. Occasionally, a pointer is also returned to
106 indicate the presence or the absence (represented by ``NULL``) of
107 some resource: In such a case, the pointer must not be freed.