Browse Source

Clarify header inclusion order

adaptive-webui-19844
Chocobo1 7 years ago
parent
commit
5f1ac96f66
No known key found for this signature in database
GPG Key ID: 210D9C873253A68C
  1. 65
      CODING_GUIDELINES.md

65
CODING_GUIDELINES.md

@ -232,36 +232,69 @@ class MyClass
``` ```
### 7. Header inclusion order. ### ### 7. Header inclusion order. ###
The headers should be placed in the following order: The headers should be placed in the following group order:
1. Module header (in .cpp) 1. Module header (in .cpp)
2. System/Qt/Boost etc. headers (split in subcategories if you have many). 2. C++ Standard Library headers
3. Application headers, starting from *Base* 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).<br/>
<br/>
Example: Example:
```c++ ```c++
// examplewidget.cpp // file: examplewidget.cpp
// Module header
#include "examplewidget.h" #include "examplewidget.h"
#include <cmath> // exceptions, headers containing version number
#include <boost/version.hpp>
#include <libtorrent/version.hpp>
#include <QtGlobal>
// C++ Standard Library headers
#include <cstdio> #include <cstdio>
#include <QDateTime> #ifdef Q_OS_WIN // conditional
#include <QList> #include <cmath>
#endif
// System headers
#ifdef Q_OS_WIN
#include <Windows.h>
#endif
// Boost library headers
#include <boost/circular_buffer.hpp>
// Libtorrent headers
#include <libtorrent/session.hpp>
// Qt headers
#include <QString> #include <QString>
#include <QUrl> #include <QUrl>
#include <libtorrent/version.hpp> #ifdef Q_OS_MAC // conditional
#include <QFont>
#endif
// conditional for the different header groups
#if LIBTORRENT_VERSION_NUM >= 10100
#include <memory>
#include <QElapsedTimer>
#endif
// qBittorrent own headers
#include "base/bittorrent/infohash.h" #include "base/bittorrent/infohash.h"
#include "base/bittorrent/session.h" #include "anothermodule.h"
#include "base/utils/fs.h"
#include "base/utils/misc.h"
#include "base/utils/string.h"
#include "ui_examplewidget.h" #include "ui_examplewidget.h"
``` ```
### 8. Include guard. ### ### 8. Include guard. ###

Loading…
Cancel
Save