From 7b37e4207766ab4dbdc288f788f7ca75c4eb7b2e Mon Sep 17 00:00:00 2001 From: mariankay Date: Thu, 10 Aug 2023 19:43:53 +0200 Subject: [PATCH] single header include and compile flag for http the example http_client.cpp shows to include the headers in following order: ``` "../src/netlib.hpp" "../src/http/client.hpp" "../src/http/http.hpp" ``` However, a common setting in auto-formatters like clang-format will sort the headers in alphabetical order (which is also a requirement in some code-styles), like this: ``` "../src/http/client.hpp" "../src/http/http.hpp" "../src/netlib.hpp" ``` But this will lead to compilation errors as `netlib.hpp` includes headers that are needed by `client.hpp`, for example `` but also library-defined symbols like `DEFAULT_TIMEOUT` or `TICK_TIME`, which are then included or defined after `client.hpp` needs them. The ordering of includes of all needed library-headers should not matter, but a single header file to include everything would be preferable anyway. To exclude features like HTTP by default anyway, a compile switch is added. --- examples/http_client.cpp | 4 ++-- src/netlib.hpp | 6 +++++- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/examples/http_client.cpp b/examples/http_client.cpp index d2359fe..29eec75 100644 --- a/examples/http_client.cpp +++ b/examples/http_client.cpp @@ -1,6 +1,6 @@ +#define NETLIB_USE_HTTP + #include "../src/netlib.hpp" -#include "../src/http/client.hpp" -#include "../src/http/http.hpp" #include #include #include diff --git a/src/netlib.hpp b/src/netlib.hpp index 24b48ee..91cc8fd 100644 --- a/src/netlib.hpp +++ b/src/netlib.hpp @@ -2,4 +2,8 @@ #include "client.hpp" #include "server.hpp" -#include "thread_pool.hpp" \ No newline at end of file +#include "thread_pool.hpp" + +#ifdef NETLIB_USE_HTTP +#include "http/client.hpp" +#endif