From 217eb0564a06d02a4a8f379403ddb954f49b5fb9 Mon Sep 17 00:00:00 2001 From: DaLaw2 Date: Sun, 11 Jan 2026 13:27:05 +0800 Subject: [PATCH] feat: Adjust project structure --- CMakeLists.txt | 33 +++++++++++++++---- .../shmcpp/containers/mpsc_ring_buffer.hpp | 8 +++++ .../shmcpp/containers/spsc_ring_buffer.hpp | 8 +++++ .../containers/posix/mpsc_ring_buffer.hpp | 8 +++++ .../containers/posix/spsc_ring_buffer.hpp | 8 +++++ .../containers/win32/mpsc_ring_buffer.hpp | 8 +++++ .../containers/win32/spsc_ring_buffer.hpp | 8 +++++ .../detail/{ => handle}/handle_concept.hpp | 0 .../detail/{ => handle}/posix/handle.hpp | 2 +- .../detail/{ => handle}/win32/handle.hpp | 2 +- .../detail/{ => handle}/win32/native_api.hpp | 0 .../detail/{ => handle}/win32/utils.hpp | 0 include/shmcpp/shared_memory.hpp | 4 +-- src/containers/mpsc_ring_buffer.cpp | 3 ++ src/containers/posix/mpsc_ring_buffer.cpp | 3 ++ src/containers/posix/spsc_ring_buffer.cpp | 3 ++ src/containers/spsc_ring_buffer.cpp | 3 ++ src/containers/win32/mpsc_ring_buffer.cpp | 3 ++ src/containers/win32/spsc_ring_buffer.cpp | 3 ++ src/{ => handle}/posix/handle.cpp | 2 +- src/{ => handle}/win32/handle.cpp | 6 ++-- 21 files changed, 100 insertions(+), 15 deletions(-) create mode 100644 include/shmcpp/containers/mpsc_ring_buffer.hpp create mode 100644 include/shmcpp/containers/spsc_ring_buffer.hpp create mode 100644 include/shmcpp/detail/containers/posix/mpsc_ring_buffer.hpp create mode 100644 include/shmcpp/detail/containers/posix/spsc_ring_buffer.hpp create mode 100644 include/shmcpp/detail/containers/win32/mpsc_ring_buffer.hpp create mode 100644 include/shmcpp/detail/containers/win32/spsc_ring_buffer.hpp rename include/shmcpp/detail/{ => handle}/handle_concept.hpp (100%) rename include/shmcpp/detail/{ => handle}/posix/handle.hpp (95%) rename include/shmcpp/detail/{ => handle}/win32/handle.hpp (95%) rename include/shmcpp/detail/{ => handle}/win32/native_api.hpp (100%) rename include/shmcpp/detail/{ => handle}/win32/utils.hpp (100%) create mode 100644 src/containers/mpsc_ring_buffer.cpp create mode 100644 src/containers/posix/mpsc_ring_buffer.cpp create mode 100644 src/containers/posix/spsc_ring_buffer.cpp create mode 100644 src/containers/spsc_ring_buffer.cpp create mode 100644 src/containers/win32/mpsc_ring_buffer.cpp create mode 100644 src/containers/win32/spsc_ring_buffer.cpp rename src/{ => handle}/posix/handle.cpp (98%) rename src/{ => handle}/win32/handle.cpp (96%) diff --git a/CMakeLists.txt b/CMakeLists.txt index 5a5db15..a16e1e2 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -5,23 +5,42 @@ set(CMAKE_CXX_STANDARD 20) set(CMAKE_CXX_STANDARD_REQUIRED ON) if (WIN32) - set(PLATFORM_SOURCES src/win32/handle.cpp) - set(PLATFORM_HEADERS include/shmcpp/detail/win32/handle.hpp - include/shmcpp/detail/win32/native_api.hpp - include/shmcpp/detail/win32/utils.hpp + set(PLATFORM_SOURCES + src/handle/win32/handle.cpp + src/containers/win32/spsc_ring_buffer.cpp + src/containers/win32/mpsc_ring_buffer.cpp + ) + set(PLATFORM_HEADERS + include/shmcpp/detail/handle/win32/handle.hpp + include/shmcpp/detail/handle/win32/native_api.hpp + include/shmcpp/detail/handle/win32/utils.hpp + include/shmcpp/detail/containers/win32/spsc_ring_buffer.hpp + include/shmcpp/detail/containers/win32/mpsc_ring_buffer.hpp ) else () - set(PLATFORM_SOURCES src/posix/handle.cpp) - set(PLATFORM_HEADERS include/shmcpp/detail/posix/handle.hpp) + set(PLATFORM_SOURCES + src/handle/posix/handle.cpp + src/containers/posix/spsc_ring_buffer.cpp + src/containers/posix/mpsc_ring_buffer.cpp + ) + set(PLATFORM_HEADERS + include/shmcpp/detail/handle/posix/handle.hpp + include/shmcpp/detail/containers/posix/spsc_ring_buffer.hpp + include/shmcpp/detail/containers/posix/mpsc_ring_buffer.hpp + ) endif () add_library(shmcpp STATIC src/shared_memory.cpp src/mapped_view.cpp + src/containers/spsc_ring_buffer.cpp + src/containers/mpsc_ring_buffer.cpp ${PLATFORM_SOURCES} include/shmcpp/shared_memory.hpp include/shmcpp/mapped_view.hpp - include/shmcpp/detail/handle_concept.hpp + include/shmcpp/containers/spsc_ring_buffer.hpp + include/shmcpp/containers/mpsc_ring_buffer.hpp + include/shmcpp/detail/handle/handle_concept.hpp ${PLATFORM_HEADERS} ) diff --git a/include/shmcpp/containers/mpsc_ring_buffer.hpp b/include/shmcpp/containers/mpsc_ring_buffer.hpp new file mode 100644 index 0000000..b3f6807 --- /dev/null +++ b/include/shmcpp/containers/mpsc_ring_buffer.hpp @@ -0,0 +1,8 @@ +// +// Created by DaLaw2 on 2026/1/11. +// + +#ifndef SHMCPP_MPSC_RING_BUFFER_HPP +#define SHMCPP_MPSC_RING_BUFFER_HPP + +#endif //SHMCPP_MPSC_RING_BUFFER_HPP \ No newline at end of file diff --git a/include/shmcpp/containers/spsc_ring_buffer.hpp b/include/shmcpp/containers/spsc_ring_buffer.hpp new file mode 100644 index 0000000..f52da02 --- /dev/null +++ b/include/shmcpp/containers/spsc_ring_buffer.hpp @@ -0,0 +1,8 @@ +// +// Created by DaLaw2 on 2026/1/11. +// + +#ifndef SHMCPP_SPSC_RING_BUFFER_HPP +#define SHMCPP_SPSC_RING_BUFFER_HPP + +#endif //SHMCPP_SPSC_RING_BUFFER_HPP \ No newline at end of file diff --git a/include/shmcpp/detail/containers/posix/mpsc_ring_buffer.hpp b/include/shmcpp/detail/containers/posix/mpsc_ring_buffer.hpp new file mode 100644 index 0000000..b3f6807 --- /dev/null +++ b/include/shmcpp/detail/containers/posix/mpsc_ring_buffer.hpp @@ -0,0 +1,8 @@ +// +// Created by DaLaw2 on 2026/1/11. +// + +#ifndef SHMCPP_MPSC_RING_BUFFER_HPP +#define SHMCPP_MPSC_RING_BUFFER_HPP + +#endif //SHMCPP_MPSC_RING_BUFFER_HPP \ No newline at end of file diff --git a/include/shmcpp/detail/containers/posix/spsc_ring_buffer.hpp b/include/shmcpp/detail/containers/posix/spsc_ring_buffer.hpp new file mode 100644 index 0000000..f52da02 --- /dev/null +++ b/include/shmcpp/detail/containers/posix/spsc_ring_buffer.hpp @@ -0,0 +1,8 @@ +// +// Created by DaLaw2 on 2026/1/11. +// + +#ifndef SHMCPP_SPSC_RING_BUFFER_HPP +#define SHMCPP_SPSC_RING_BUFFER_HPP + +#endif //SHMCPP_SPSC_RING_BUFFER_HPP \ No newline at end of file diff --git a/include/shmcpp/detail/containers/win32/mpsc_ring_buffer.hpp b/include/shmcpp/detail/containers/win32/mpsc_ring_buffer.hpp new file mode 100644 index 0000000..b3f6807 --- /dev/null +++ b/include/shmcpp/detail/containers/win32/mpsc_ring_buffer.hpp @@ -0,0 +1,8 @@ +// +// Created by DaLaw2 on 2026/1/11. +// + +#ifndef SHMCPP_MPSC_RING_BUFFER_HPP +#define SHMCPP_MPSC_RING_BUFFER_HPP + +#endif //SHMCPP_MPSC_RING_BUFFER_HPP \ No newline at end of file diff --git a/include/shmcpp/detail/containers/win32/spsc_ring_buffer.hpp b/include/shmcpp/detail/containers/win32/spsc_ring_buffer.hpp new file mode 100644 index 0000000..f52da02 --- /dev/null +++ b/include/shmcpp/detail/containers/win32/spsc_ring_buffer.hpp @@ -0,0 +1,8 @@ +// +// Created by DaLaw2 on 2026/1/11. +// + +#ifndef SHMCPP_SPSC_RING_BUFFER_HPP +#define SHMCPP_SPSC_RING_BUFFER_HPP + +#endif //SHMCPP_SPSC_RING_BUFFER_HPP \ No newline at end of file diff --git a/include/shmcpp/detail/handle_concept.hpp b/include/shmcpp/detail/handle/handle_concept.hpp similarity index 100% rename from include/shmcpp/detail/handle_concept.hpp rename to include/shmcpp/detail/handle/handle_concept.hpp diff --git a/include/shmcpp/detail/posix/handle.hpp b/include/shmcpp/detail/handle/posix/handle.hpp similarity index 95% rename from include/shmcpp/detail/posix/handle.hpp rename to include/shmcpp/detail/handle/posix/handle.hpp index 679c2bc..00aff6d 100644 --- a/include/shmcpp/detail/posix/handle.hpp +++ b/include/shmcpp/detail/handle/posix/handle.hpp @@ -5,7 +5,7 @@ #ifndef SHMCPP_POSIX_HANDLE_HPP #define SHMCPP_POSIX_HANDLE_HPP -#include +#include namespace shmcpp::detail { class PosixHandle { diff --git a/include/shmcpp/detail/win32/handle.hpp b/include/shmcpp/detail/handle/win32/handle.hpp similarity index 95% rename from include/shmcpp/detail/win32/handle.hpp rename to include/shmcpp/detail/handle/win32/handle.hpp index 450c8e5..ca2f437 100644 --- a/include/shmcpp/detail/win32/handle.hpp +++ b/include/shmcpp/detail/handle/win32/handle.hpp @@ -8,7 +8,7 @@ #include #include #include -#include +#include namespace shmcpp::detail { class Win32Handle { diff --git a/include/shmcpp/detail/win32/native_api.hpp b/include/shmcpp/detail/handle/win32/native_api.hpp similarity index 100% rename from include/shmcpp/detail/win32/native_api.hpp rename to include/shmcpp/detail/handle/win32/native_api.hpp diff --git a/include/shmcpp/detail/win32/utils.hpp b/include/shmcpp/detail/handle/win32/utils.hpp similarity index 100% rename from include/shmcpp/detail/win32/utils.hpp rename to include/shmcpp/detail/handle/win32/utils.hpp diff --git a/include/shmcpp/shared_memory.hpp b/include/shmcpp/shared_memory.hpp index 9122a94..7ca1f13 100644 --- a/include/shmcpp/shared_memory.hpp +++ b/include/shmcpp/shared_memory.hpp @@ -8,9 +8,9 @@ #include #ifdef _WIN32 -#include +#include #else -#include +#include #endif #include diff --git a/src/containers/mpsc_ring_buffer.cpp b/src/containers/mpsc_ring_buffer.cpp new file mode 100644 index 0000000..83446d3 --- /dev/null +++ b/src/containers/mpsc_ring_buffer.cpp @@ -0,0 +1,3 @@ +// +// Created by DaLaw2 on 2026/1/11. +// \ No newline at end of file diff --git a/src/containers/posix/mpsc_ring_buffer.cpp b/src/containers/posix/mpsc_ring_buffer.cpp new file mode 100644 index 0000000..83446d3 --- /dev/null +++ b/src/containers/posix/mpsc_ring_buffer.cpp @@ -0,0 +1,3 @@ +// +// Created by DaLaw2 on 2026/1/11. +// \ No newline at end of file diff --git a/src/containers/posix/spsc_ring_buffer.cpp b/src/containers/posix/spsc_ring_buffer.cpp new file mode 100644 index 0000000..83446d3 --- /dev/null +++ b/src/containers/posix/spsc_ring_buffer.cpp @@ -0,0 +1,3 @@ +// +// Created by DaLaw2 on 2026/1/11. +// \ No newline at end of file diff --git a/src/containers/spsc_ring_buffer.cpp b/src/containers/spsc_ring_buffer.cpp new file mode 100644 index 0000000..83446d3 --- /dev/null +++ b/src/containers/spsc_ring_buffer.cpp @@ -0,0 +1,3 @@ +// +// Created by DaLaw2 on 2026/1/11. +// \ No newline at end of file diff --git a/src/containers/win32/mpsc_ring_buffer.cpp b/src/containers/win32/mpsc_ring_buffer.cpp new file mode 100644 index 0000000..83446d3 --- /dev/null +++ b/src/containers/win32/mpsc_ring_buffer.cpp @@ -0,0 +1,3 @@ +// +// Created by DaLaw2 on 2026/1/11. +// \ No newline at end of file diff --git a/src/containers/win32/spsc_ring_buffer.cpp b/src/containers/win32/spsc_ring_buffer.cpp new file mode 100644 index 0000000..83446d3 --- /dev/null +++ b/src/containers/win32/spsc_ring_buffer.cpp @@ -0,0 +1,3 @@ +// +// Created by DaLaw2 on 2026/1/11. +// \ No newline at end of file diff --git a/src/posix/handle.cpp b/src/handle/posix/handle.cpp similarity index 98% rename from src/posix/handle.cpp rename to src/handle/posix/handle.cpp index b9f196b..3a9d076 100644 --- a/src/posix/handle.cpp +++ b/src/handle/posix/handle.cpp @@ -10,7 +10,7 @@ #include #include #include -#include "shmcpp/detail/posix/handle.hpp" +#include "shmcpp/detail/handle/posix/handle.hpp" namespace shmcpp::detail { PosixHandle::PosixHandle(int fd, std::size_t size, const std::string& name) diff --git a/src/win32/handle.cpp b/src/handle/win32/handle.cpp similarity index 96% rename from src/win32/handle.cpp rename to src/handle/win32/handle.cpp index 00ad692..4d499f5 100644 --- a/src/win32/handle.cpp +++ b/src/handle/win32/handle.cpp @@ -5,9 +5,9 @@ #include #include -#include "shmcpp/detail/win32/handle.hpp" -#include "shmcpp/detail/win32/native_api.hpp" -#include "shmcpp/detail/win32/utils.hpp" +#include "shmcpp/detail/handle/win32/handle.hpp" +#include "shmcpp/detail/handle/win32/native_api.hpp" +#include "shmcpp/detail/handle/win32/utils.hpp" namespace shmcpp::detail { Win32Handle::Win32Handle(const HANDLE handle, const std::size_t size, const std::string& name) noexcept