Skip to content

Commit

Permalink
Rework directory structure
Browse files Browse the repository at this point in the history
  • Loading branch information
rHermes committed Apr 14, 2024
1 parent b90dfb5 commit f7143d1
Show file tree
Hide file tree
Showing 8 changed files with 89 additions and 66 deletions.
15 changes: 15 additions & 0 deletions include/hage/core/concepts.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#pragma once

#include <ranges>
#include <concepts>

namespace hage {
template<typename R, typename V>
concept RangeOf = std::ranges::range<R> && std::convertible_to<std::ranges::range_reference_t<R>, V>;

template<typename R, typename V>
concept InputRangeOf = std::ranges::input_range<R> && std::convertible_to<std::ranges::range_reference_t<R>, V>;

template<typename R, typename V>
concept CommonRangeOf = std::ranges::common_range<R> && std::convertible_to<std::ranges::range_reference_t<R>, V>;
}
26 changes: 26 additions & 0 deletions include/hage/core/lifetime_tester.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#pragma once

#include <cstdio>
#include <string_view>

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;
}
};
}
26 changes: 26 additions & 0 deletions include/hage/core/misc.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#pragma once

#include <array>

namespace hage {
namespace details {
#ifdef __cpp_lib_hardware_interference_size
#include <new>
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<typename... T>
[[nodiscard]] constexpr std::array<std::byte, sizeof...(T)>
byte_array(T... a)
{
return { static_cast<std::byte>(a)... };
}

};
3 changes: 2 additions & 1 deletion include/hage/logging/ring_buffer.hpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#pragma once

#include "../misc.hpp"
#include <hage/core/misc.hpp>

#include "byte_buffer.hpp"

#include <span>
Expand Down
4 changes: 3 additions & 1 deletion include/hage/logging/sink.hpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#pragma once
#include "../misc.hpp"

#include <hage/core/concepts.hpp>

#include <chrono>
#include <vector>

Expand Down
58 changes: 0 additions & 58 deletions include/hage/misc.hpp

This file was deleted.

20 changes: 16 additions & 4 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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"
Expand All @@ -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
Expand All @@ -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")
Expand Down
3 changes: 1 addition & 2 deletions src/logging/file_sink.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#include <fmt/core.h>
#include <fmt/chrono.h>
#include <fmt/color.h>
#include <fmt/compile.h>

#include <hage/logging/file_sink.hpp>

void
Expand Down

0 comments on commit f7143d1

Please sign in to comment.