From 5f1ac96f66d991922e0cb2bb93da47cf4568a52e Mon Sep 17 00:00:00 2001 From: Chocobo1 Date: Tue, 10 Apr 2018 16:14:06 +0800 Subject: [PATCH] Clarify header inclusion order --- CODING_GUIDELINES.md | 65 +++++++++++++++++++++++++++++++++----------- 1 file changed, 49 insertions(+), 16 deletions(-) diff --git a/CODING_GUIDELINES.md b/CODING_GUIDELINES.md index 4e3137434..5e0f47a1e 100644 --- a/CODING_GUIDELINES.md +++ b/CODING_GUIDELINES.md @@ -232,36 +232,69 @@ class MyClass ``` ### 7. Header inclusion order. ### -The headers should be placed in the following order: - 1. Module header (in .cpp) - 2. System/Qt/Boost etc. headers (split in subcategories if you have many). - 3. Application headers, starting from *Base* headers. +The headers should be placed in the following group order: + 1. Module header (in .cpp) + 2. C++ Standard Library headers + 3. System headers + 4. Boost library headers + 5. Libtorrent headers + 6. Qt headers + 7. qBittorrent own headers, starting from *base* headers. + +The headers should be ordered alphabetically within each group. +If there are conditionals for the same header group, then put them at the bottom of the respective group. +If there are conditionals for the different header groups, then put them above of the "qBittorrent own headers" group. + +One exception is the header containing the library version (for example, QtGlobal), this particular header isn't constrained by the aforementioned order. -The headers should be ordered alphabetically within each group (subgroup).
-
Example: ```c++ -// examplewidget.cpp +// file: examplewidget.cpp +// Module header #include "examplewidget.h" -#include +// exceptions, headers containing version number +#include +#include +#include + +// C++ Standard Library headers #include -#include -#include +#ifdef Q_OS_WIN // conditional +#include +#endif + +// System headers +#ifdef Q_OS_WIN +#include +#endif + +// Boost library headers +#include + +// Libtorrent headers +#include + +// Qt headers #include #include -#include +#ifdef Q_OS_MAC // conditional +#include +#endif + +// conditional for the different header groups +#if LIBTORRENT_VERSION_NUM >= 10100 +#include +#include +#endif +// qBittorrent own headers #include "base/bittorrent/infohash.h" -#include "base/bittorrent/session.h" -#include "base/utils/fs.h" -#include "base/utils/misc.h" -#include "base/utils/string.h" +#include "anothermodule.h" #include "ui_examplewidget.h" - ``` ### 8. Include guard. ###