From f7143d170fe7249238eb9e2cded5a2c7f97b131a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Teodor=20Sp=C3=A6ren?= Date: Sun, 14 Apr 2024 22:43:22 +0200 Subject: [PATCH] Rework directory structure --- include/hage/core/concepts.hpp | 15 +++++++ include/hage/core/lifetime_tester.hpp | 26 ++++++++++++ include/hage/core/misc.hpp | 26 ++++++++++++ include/hage/logging/ring_buffer.hpp | 3 +- include/hage/logging/sink.hpp | 4 +- include/hage/misc.hpp | 58 --------------------------- src/CMakeLists.txt | 20 +++++++-- src/logging/file_sink.cpp | 3 +- 8 files changed, 89 insertions(+), 66 deletions(-) create mode 100644 include/hage/core/concepts.hpp create mode 100644 include/hage/core/lifetime_tester.hpp create mode 100644 include/hage/core/misc.hpp delete mode 100644 include/hage/misc.hpp diff --git a/include/hage/core/concepts.hpp b/include/hage/core/concepts.hpp new file mode 100644 index 0000000..24f59b3 --- /dev/null +++ b/include/hage/core/concepts.hpp @@ -0,0 +1,15 @@ +#pragma once + +#include +#include + +namespace hage { +template +concept RangeOf = std::ranges::range && std::convertible_to, V>; + +template +concept InputRangeOf = std::ranges::input_range && std::convertible_to, V>; + +template +concept CommonRangeOf = std::ranges::common_range && std::convertible_to, V>; +} \ No newline at end of file diff --git a/include/hage/core/lifetime_tester.hpp b/include/hage/core/lifetime_tester.hpp new file mode 100644 index 0000000..fd98bab --- /dev/null +++ b/include/hage/core/lifetime_tester.hpp @@ -0,0 +1,26 @@ +#pragma once + +#include +#include + +namespace hage { +// stolen from jason turner +struct LifetimeTester +{ + explicit LifetimeTester(int) noexcept { std::printf("LifetimeTester::LifetimeTester(int)\n"); } + LifetimeTester() noexcept { std::printf("LifetimeTester::LifetimeTester()\n"); } + LifetimeTester(LifetimeTester&&) noexcept { std::printf("LifetimeTester::LifetimeTester(LifetimeTester&&)\n");} + LifetimeTester(const LifetimeTester&) noexcept { std::printf("LifetimeTester::LifetimeTester(const LifetimeTester&)\n"); } + ~LifetimeTester() noexcept { std::printf("LifetimeTester::~LifetimeTester()\n"); } + LifetimeTester& operator=(const LifetimeTester&) noexcept + { + std::printf("LifetimeTester::operator=(const LifetimeTester&)\n"); + return *this; + } + LifetimeTester& operator=(LifetimeTester&&) noexcept + { + std::printf("LifetimeTester::operator=(LifetimeTester&&)\n"); + return *this; + } +}; +} \ No newline at end of file diff --git a/include/hage/core/misc.hpp b/include/hage/core/misc.hpp new file mode 100644 index 0000000..ee423d1 --- /dev/null +++ b/include/hage/core/misc.hpp @@ -0,0 +1,26 @@ +#pragma once + +#include + +namespace hage { +namespace details { +#ifdef __cpp_lib_hardware_interference_size +#include +static constexpr auto constructive_interference_size = std::hardware_constructive_interference_size; +static constexpr auto destructive_interference_size = std::hardware_destructive_interference_size; +#else +// 64 bytes on x86-64 │ L1_CACHE_BYTES │ L1_CACHE_SHIFT │ __cacheline_aligned │ ... +static constexpr std::size_t constructive_interference_size = 64; +static constexpr std::size_t destructive_interference_size = 64; +#endif + +} + +template +[[nodiscard]] constexpr std::array +byte_array(T... a) +{ + return { static_cast(a)... }; +} + +}; diff --git a/include/hage/logging/ring_buffer.hpp b/include/hage/logging/ring_buffer.hpp index 2ea9196..5a873b6 100644 --- a/include/hage/logging/ring_buffer.hpp +++ b/include/hage/logging/ring_buffer.hpp @@ -1,6 +1,7 @@ #pragma once -#include "../misc.hpp" +#include + #include "byte_buffer.hpp" #include diff --git a/include/hage/logging/sink.hpp b/include/hage/logging/sink.hpp index d132b29..6ead922 100644 --- a/include/hage/logging/sink.hpp +++ b/include/hage/logging/sink.hpp @@ -1,5 +1,7 @@ #pragma once -#include "../misc.hpp" + +#include + #include #include diff --git a/include/hage/misc.hpp b/include/hage/misc.hpp deleted file mode 100644 index 1ba152f..0000000 --- a/include/hage/misc.hpp +++ /dev/null @@ -1,58 +0,0 @@ -#pragma once - -#include -#include - -#include - -namespace hage { -namespace details { -#ifdef __cpp_lib_hardware_interference_size -#include -static constexpr auto constructive_interference_size = std::hardware_constructive_interference_size; -static constexpr auto destructive_interference_size = std::hardware_destructive_interference_size; -#else -// 64 bytes on x86-64 │ L1_CACHE_BYTES │ L1_CACHE_SHIFT │ __cacheline_aligned │ ... -static constexpr std::size_t constructive_interference_size = 64; -static constexpr std::size_t destructive_interference_size = 64; -#endif - -} - -template -constexpr std::array -byte_array(T... a) -{ - return { static_cast(a)... }; -} - -template -concept RangeOf = std::ranges::range && std::convertible_to, V>; - -template -concept InputRangeOf = std::ranges::input_range && std::convertible_to, V>; - -template -concept CommonRangeOf = std::ranges::common_range && std::convertible_to, V>; - -// stolen from jason turner -struct Lifetime -{ - explicit Lifetime(int) noexcept { std::printf("Lifetime::Lifetime(int)\n"); } - Lifetime() noexcept { std::printf("Lifetime::Lifetime()\n"); } - Lifetime(Lifetime&&) noexcept { std::printf("Lifetime::Lifetime(Lifetime&&)\n");} - Lifetime(const Lifetime&) noexcept { std::printf("Lifetime::Lifetime(const Lifetime&)\n"); } - ~Lifetime() noexcept { std::printf("Lifetime::~Lifetime()\n"); } - Lifetime& operator=(const Lifetime&) noexcept - { - std::printf("Lifetime::operator=(const Lifetime&)\n"); - return *this; - } - Lifetime& operator=(Lifetime&&) noexcept - { - std::printf("Lifetime::operator=(Lifetime&&)\n"); - return *this; - } -}; - -}; diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 2b49417..9c7f19a 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -7,6 +7,14 @@ FetchContent_Declare( FetchContent_MakeAvailable(fmt) + +set(CORE_HEADER_LIST + "${hage_SOURCE_DIR}/include/hage/core/misc.hpp" + "${hage_SOURCE_DIR}/include/hage/core/lifetime_tester.hpp" + "${hage_SOURCE_DIR}/include/hage/core/concepts.hpp" +) + + set(ATOMIC_HEADER_LIST "${hage_SOURCE_DIR}/include/hage/atomic/atomic.hpp" "${hage_SOURCE_DIR}/include/hage/atomic/atomic_base.hpp" @@ -19,7 +27,7 @@ set(ATOMIC_HEADER_LIST set(LOGGING_HEADER_LIST - "${hage_SOURCE_DIR}/include/hage/misc.hpp" + "${hage_SOURCE_DIR}/include/hage/logging.hpp" "${hage_SOURCE_DIR}/include/hage/logging/ring_buffer.hpp" "${hage_SOURCE_DIR}/include/hage/logging/vector_buffer.hpp" @@ -31,6 +39,11 @@ set(LOGGING_HEADER_LIST "${hage_SOURCE_DIR}/include/hage/logging/console_sink.hpp" ) +add_library(hage_core INTERFACE) + +target_sources(hage_core INTERFACE ${CORE_HEADER_LIST}) +target_include_directories(hage_core INTERFACE ../include) + add_library(hage_atomic INTERFACE) target_sources(hage_atomic INTERFACE @@ -43,12 +56,11 @@ add_library(hage_logging ${LOGGING_HEADER_LIST} logging/console_sink.cpp logging/file_sink.cpp) - # We need this directory, and users of our library will need it to. target_include_directories(hage_logging PUBLIC ../include) -target_link_libraries(hage_logging PUBLIC fmt::fmt hage_atomic) +target_link_libraries(hage_logging PUBLIC fmt::fmt hage_atomic hage_core) -foreach (target_var IN ITEMS hage_atomic hage_logging) +foreach (target_var IN ITEMS hage_atomic hage_logging hage_core) get_target_property(target_type ${target_var} TYPE) if (target_type STREQUAL "INTERFACE_LIBRARY") diff --git a/src/logging/file_sink.cpp b/src/logging/file_sink.cpp index 79ce29f..842ae2b 100644 --- a/src/logging/file_sink.cpp +++ b/src/logging/file_sink.cpp @@ -1,7 +1,6 @@ +#include #include #include -#include - #include void