diff --git a/include/libconcur/concurrent.h b/include/libconcur/concurrent.h index f759533..87a9d12 100644 --- a/include/libconcur/concurrent.h +++ b/include/libconcur/concurrent.h @@ -88,7 +88,7 @@ struct producer { template , typename = is_convertible> - static bool enqueue(::LIBIMP_::span> elems, C &ctx, U &&src) noexcept { + static bool enqueue(::LIBIMP::span> elems, C &ctx, U &&src) noexcept { auto w_idx = ctx.w_idx; auto w_cur = trunc_index(ctx, w_idx); auto &elem = elems[w_cur]; @@ -119,7 +119,7 @@ struct producer { template , typename = is_convertible> - static bool enqueue(::LIBIMP_::span> elems, C &ctx, U &&src) noexcept { + static bool enqueue(::LIBIMP::span> elems, C &ctx, U &&src) noexcept { auto w_idx = ctx.w_idx.load(std::memory_order_acquire); for (;;) { auto w_cur = trunc_index(ctx, w_idx); @@ -154,7 +154,7 @@ struct consumer { template , typename = is_convertible> - static bool dequeue(::LIBIMP_::span> elems, C &ctx, U &des) noexcept { + static bool dequeue(::LIBIMP::span> elems, C &ctx, U &des) noexcept { auto r_idx = ctx.r_idx; auto r_cur = trunc_index(ctx, r_idx); auto &elem = elems[r_cur]; @@ -184,7 +184,7 @@ struct consumer { template , typename = is_convertible> - static bool dequeue(::LIBIMP_::span> elems, C &ctx, U &des) noexcept { + static bool dequeue(::LIBIMP::span> elems, C &ctx, U &des) noexcept { auto r_idx = ctx.r_idx.load(std::memory_order_acquire); for (;;) { auto r_cur = trunc_index(ctx, r_idx); @@ -250,7 +250,7 @@ struct prod_cons : producer : circ_size(cs) {} template - constexpr context(::LIBIMP_::span> elems) noexcept + constexpr context(::LIBIMP::span> elems) noexcept : circ_size(static_cast(elems.size())) {} constexpr bool valid() const noexcept { diff --git a/include/libconcur/def.h b/include/libconcur/def.h index 83dd1bc..d520012 100644 --- a/include/libconcur/def.h +++ b/include/libconcur/def.h @@ -11,8 +11,8 @@ #include "libimp/detect_plat.h" -#define LIBCONCUR_ concur -#define LIBCONCUR_NAMESPACE_BEG_ namespace LIBCONCUR_ { +#define LIBCONCUR concur +#define LIBCONCUR_NAMESPACE_BEG_ namespace LIBCONCUR { #define LIBCONCUR_NAMESPACE_END_ } LIBCONCUR_NAMESPACE_BEG_ diff --git a/include/libimp/byte.h b/include/libimp/byte.h index dbf1f7c..aa0c405 100644 --- a/include/libimp/byte.h +++ b/include/libimp/byte.h @@ -158,12 +158,12 @@ U *byte_cast(byte const *p) noexcept { LIBIMP_NAMESPACE_END_ template <> -struct fmt::formatter<::LIBIMP_::byte> { +struct fmt::formatter<::LIBIMP::byte> { constexpr auto parse(format_parse_context& ctx) const { return ctx.end(); } template - auto format(::LIBIMP_::byte b, FormatContext &ctx) { + auto format(::LIBIMP::byte b, FormatContext &ctx) { return format_to(ctx.out(), "{:#04x}", static_cast(b)); } }; diff --git a/include/libimp/def.h b/include/libimp/def.h index 4348050..8fb2505 100644 --- a/include/libimp/def.h +++ b/include/libimp/def.h @@ -9,8 +9,8 @@ #include #include -#define LIBIMP_ imp -#define LIBIMP_NAMESPACE_BEG_ namespace LIBIMP_ { +#define LIBIMP imp +#define LIBIMP_NAMESPACE_BEG_ namespace LIBIMP { #define LIBIMP_NAMESPACE_END_ } LIBIMP_NAMESPACE_BEG_ diff --git a/include/libimp/generic.h b/include/libimp/generic.h index 2f11b6c..643069a 100644 --- a/include/libimp/generic.h +++ b/include/libimp/generic.h @@ -1,7 +1,7 @@ /** * @file libimp/generic.h * @author mutouyun (orz@orzz.org) - * @brief Tools for generic programming + * @brief Tools for generic programming. * @date 2022-03-01 */ #pragma once diff --git a/include/libimp/log.h b/include/libimp/log.h index df6bc1b..dbb8555 100644 --- a/include/libimp/log.h +++ b/include/libimp/log.h @@ -1,7 +1,7 @@ /** * @file libimp/log.h * @author mutouyun (orz@orzz.org) - * @brief Simple log output component + * @brief Simple log output component. * @date 2022-05-22 */ #pragma once @@ -198,4 +198,4 @@ public: } // namespace log LIBIMP_NAMESPACE_END_ -#define LIBIMP_LOG_(...) ::LIBIMP_::log::grip log {__func__, __VA_ARGS__} \ No newline at end of file +#define LIBIMP_LOG_(...) ::LIBIMP::log::grip log {__func__, __VA_ARGS__} \ No newline at end of file diff --git a/include/libimp/result.h b/include/libimp/result.h index d4c3bb2..6037b30 100644 --- a/include/libimp/result.h +++ b/include/libimp/result.h @@ -160,22 +160,22 @@ public: LIBIMP_NAMESPACE_END_ template -struct fmt::formatter<::LIBIMP_::result> { +struct fmt::formatter<::LIBIMP::result> { constexpr auto parse(format_parse_context& ctx) const { return ctx.end(); } template - auto format(::LIBIMP_::result r, FormatContext &ctx) { - return format_to(::LIBIMP_::result::default_traits_t::format(r, + auto format(::LIBIMP::result r, FormatContext &ctx) { + return format_to(::LIBIMP::result::default_traits_t::format(r, format_to(ctx.out(), "[{}, value = ", r ? "succ" : "fail")), "]"); } }; template <> -struct fmt::formatter<::LIBIMP_::result_code> - : formatter<::LIBIMP_::result<::LIBIMP_::result_type>> { +struct fmt::formatter<::LIBIMP::result_code> + : formatter<::LIBIMP::result<::LIBIMP::result_type>> { template - auto format(::LIBIMP_::result_code r, FormatContext &ctx) { + auto format(::LIBIMP::result_code r, FormatContext &ctx) { return format_to(ctx.out(), "[{}, value = {}]", (r ? "succ" : "fail"), *r); } }; diff --git a/include/libimp/span.h b/include/libimp/span.h index 2511d29..1e61326 100644 --- a/include/libimp/span.h +++ b/include/libimp/span.h @@ -281,12 +281,12 @@ inline auto make_span(std::string const &str) noexcept -> span { LIBIMP_NAMESPACE_END_ template -struct fmt::formatter<::LIBIMP_::span> { +struct fmt::formatter<::LIBIMP::span> { constexpr auto parse(format_parse_context& ctx) const { return ctx.end(); } template - auto format(::LIBIMP_::span s, FormatContext &ctx) { + auto format(::LIBIMP::span s, FormatContext &ctx) { if (s.empty()) { return format_to(ctx.out(), ""); } diff --git a/include/libimp/system.h b/include/libimp/system.h index dbff599..435d257 100644 --- a/include/libimp/system.h +++ b/include/libimp/system.h @@ -67,10 +67,10 @@ LIBIMP_EXPORT result conf(info) noexcept; LIBIMP_NAMESPACE_END_ template <> -struct fmt::formatter<::LIBIMP_::sys::error> +struct fmt::formatter<::LIBIMP::sys::error> : formatter { template - auto format(::LIBIMP_::sys::error r, FormatContext &ctx) { - return format_to(ctx.out(), ::LIBIMP_::sys::error_msg(r.code())); + auto format(::LIBIMP::sys::error r, FormatContext &ctx) { + return format_to(ctx.out(), ::LIBIMP::sys::error_msg(r.code())); } }; diff --git a/include/libipc/def.h b/include/libipc/def.h index 0ad7085..3b121d1 100755 --- a/include/libipc/def.h +++ b/include/libipc/def.h @@ -9,8 +9,8 @@ #include #include -#define LIBIPC_ ipc -#define LIBIPC_NAMESPACE_BEG_ namespace LIBIPC_ { +#define LIBIPC ipc +#define LIBIPC_NAMESPACE_BEG_ namespace LIBIPC { #define LIBIPC_NAMESPACE_END_ } LIBIPC_NAMESPACE_BEG_ diff --git a/include/libipc/shm.h b/include/libipc/shm.h index 607cef0..ba87e33 100644 --- a/include/libipc/shm.h +++ b/include/libipc/shm.h @@ -20,12 +20,12 @@ struct shm_handle; using shm_t = shm_handle *; /// @brief Create a new shared memory handle with a name of the shared memory file. -LIBIMP_EXPORT ::LIBIMP_::result shm_open(std::string name, +LIBIMP_EXPORT ::LIBIMP::result shm_open(std::string name, std::size_t size = 0, mode::type = mode::create | mode::open) noexcept; /// @brief Close the shared memory handle. -LIBIMP_EXPORT ::LIBIMP_::result_code shm_close(shm_t) noexcept; +LIBIMP_EXPORT ::LIBIMP::result_code shm_close(shm_t) noexcept; /// @brief Gets a memory pointer based on the shared memory handle. /// @return nullptr on failure. @@ -37,7 +37,7 @@ LIBIMP_EXPORT std::size_t shm_size(shm_t) noexcept; /// @brief Sets the memory size based on the shared memory handle. /// @remark [TBD] -LIBIMP_EXPORT ::LIBIMP_::result_code shm_size(shm_t, std::size_t) noexcept; +LIBIMP_EXPORT ::LIBIMP::result_code shm_size(shm_t, std::size_t) noexcept; /// @brief Gets the name of the shared memory file based on the shared memory handle. /// @return empty string on failure. diff --git a/include/libpmr/allocator.h b/include/libpmr/allocator.h index a7019e2..c6f5875 100644 --- a/include/libpmr/allocator.h +++ b/include/libpmr/allocator.h @@ -85,7 +85,7 @@ class LIBIMP_EXPORT allocator { }; using void_holder_type = holder_memory_resource; - alignas(void_holder_type) std::array<::LIBIMP_::byte, sizeof(void_holder_type)> holder_; + alignas(void_holder_type) std::array<::LIBIMP::byte, sizeof(void_holder_type)> holder_; holder_base & get_holder() noexcept; holder_base const &get_holder() const noexcept; @@ -105,7 +105,7 @@ public: template > allocator(T *p_mr) : allocator() { if (p_mr == nullptr) return; - ::LIBIMP_::construct>(holder_.data(), p_mr); + ::LIBIMP::construct>(holder_.data(), p_mr); } void swap(allocator &other) noexcept; diff --git a/include/libpmr/def.h b/include/libpmr/def.h index adb9544..2b3ef7e 100644 --- a/include/libpmr/def.h +++ b/include/libpmr/def.h @@ -6,8 +6,8 @@ */ #pragma once -#define LIBPMR_ pmr -#define LIBPMR_NAMESPACE_BEG_ namespace LIBPMR_ { +#define LIBPMR pmr +#define LIBPMR_NAMESPACE_BEG_ namespace LIBPMR { #define LIBPMR_NAMESPACE_END_ } LIBPMR_NAMESPACE_BEG_ diff --git a/src/libimp/codecvt.cpp b/src/libimp/codecvt.cpp index 96ee8ca..91a0cfd 100644 --- a/src/libimp/codecvt.cpp +++ b/src/libimp/codecvt.cpp @@ -1,10 +1,10 @@ +#include "libimp/codecvt.h" #include #include #include #include -#include "libimp/codecvt.h" #include "libimp/log.h" #include "libimp/detect_plat.h" diff --git a/src/libimp/log.cpp b/src/libimp/log.cpp index c12043e..4bfc2f0 100644 --- a/src/libimp/log.cpp +++ b/src/libimp/log.cpp @@ -1,11 +1,10 @@ +#include "libimp/log.h" #include #include #include "fmt/chrono.h" -#include "libimp/log.h" - LIBIMP_NAMESPACE_BEG_ namespace log { diff --git a/src/libipc/platform/posix/shm_impl.h b/src/libipc/platform/posix/shm_impl.h index 7673200..366f53b 100644 --- a/src/libipc/platform/posix/shm_impl.h +++ b/src/libipc/platform/posix/shm_impl.h @@ -23,7 +23,7 @@ #include "def.h" LIBIPC_NAMESPACE_BEG_ -using namespace ::LIBIMP_; +using namespace ::LIBIMP; struct shm_handle { std::string file; diff --git a/src/libipc/platform/win/get_sa.h b/src/libipc/platform/win/get_sa.h index 65c2edd..05887ee 100644 --- a/src/libipc/platform/win/get_sa.h +++ b/src/libipc/platform/win/get_sa.h @@ -27,7 +27,7 @@ inline LPSECURITY_ATTRIBUTES get_sa() { bool succ_ = false; initiator() { - using namespace ::LIBIMP_; + using namespace ::LIBIMP; log::grip log {"get_sa"}; if (!::InitializeSecurityDescriptor(&sd_, SECURITY_DESCRIPTOR_REVISION)) { log.error("failed: InitializeSecurityDescriptor(SECURITY_DESCRIPTOR_REVISION). error = {}", sys::error()); diff --git a/src/libipc/platform/win/mmap_impl.h b/src/libipc/platform/win/mmap_impl.h index f2cf929..e7392ce 100644 --- a/src/libipc/platform/win/mmap_impl.h +++ b/src/libipc/platform/win/mmap_impl.h @@ -18,7 +18,7 @@ #include "to_tchar.h" LIBIPC_NAMESPACE_BEG_ -using namespace ::LIBIMP_; +using namespace ::LIBIMP; struct shm_handle { std::string file; diff --git a/src/libipc/platform/win/shm_impl.h b/src/libipc/platform/win/shm_impl.h index 56059f5..d601908 100644 --- a/src/libipc/platform/win/shm_impl.h +++ b/src/libipc/platform/win/shm_impl.h @@ -15,7 +15,7 @@ #include "mmap_impl.h" LIBIPC_NAMESPACE_BEG_ -using namespace ::LIBIMP_; +using namespace ::LIBIMP; result shm_open(std::string name, std::size_t size, mode::type type) noexcept { LIBIMP_LOG_(); diff --git a/src/libipc/platform/win/to_tchar.h b/src/libipc/platform/win/to_tchar.h index 4f1d942..a93c3b5 100644 --- a/src/libipc/platform/win/to_tchar.h +++ b/src/libipc/platform/win/to_tchar.h @@ -19,7 +19,7 @@ using tstring = std::basic_string; inline tstring to_tstring(std::string const &str) { tstring des; - ::LIBIMP_::cvt_sstr(str, des); + ::LIBIMP::cvt_sstr(str, des); return des; } diff --git a/src/libpmr/allocator.cpp b/src/libpmr/allocator.cpp index 5254b0b..c83147e 100644 --- a/src/libpmr/allocator.cpp +++ b/src/libpmr/allocator.cpp @@ -14,22 +14,22 @@ allocator::holder_base const &allocator::get_holder() const noexcept { } allocator::allocator() noexcept { - ::LIBIMP_::construct(holder_.data()); + ::LIBIMP::construct(holder_.data()); } allocator::~allocator() noexcept { - ::LIBIMP_::destroy(&get_holder()); + ::LIBIMP::destroy(&get_holder()); } allocator::allocator(allocator &&other) noexcept : allocator(other) /*copy*/ { - ::LIBIMP_::construct(other.holder_.data()); + ::LIBIMP::construct(other.holder_.data()); } allocator &allocator::operator=(allocator &&other) & noexcept { if (this == &other) return *this; this->holder_ = other.holder_; - ::LIBIMP_::construct(other.holder_.data()); + ::LIBIMP::construct(other.holder_.data()); return *this; } diff --git a/src/libpmr/memory_resource.cpp b/src/libpmr/memory_resource.cpp index 98f8a82..7824e5d 100644 --- a/src/libpmr/memory_resource.cpp +++ b/src/libpmr/memory_resource.cpp @@ -13,7 +13,7 @@ namespace { /** * @brief Check that bytes is not 0 and that the alignment is a power of two. */ -bool verify_args(::LIBIMP_::log::grip &log, std::size_t bytes, std::size_t alignment) noexcept { +bool verify_args(::LIBIMP::log::grip &log, std::size_t bytes, std::size_t alignment) noexcept { if (bytes == 0) { return false; } diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index ee001dd..d7b2779 100755 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -29,11 +29,13 @@ file(GLOB SRC_FILES ${LIBIPC_PROJECT_DIR}/test/imp/*.cpp ${LIBIPC_PROJECT_DIR}/test/pmr/*.cpp ${LIBIPC_PROJECT_DIR}/test/concur/*.cpp - ${LIBIPC_PROJECT_DIR}/test/*.cpp) + ${LIBIPC_PROJECT_DIR}/test/ipc/*.cpp) file(GLOB HEAD_FILES ${LIBIPC_PROJECT_DIR}/test/*.h) add_executable(${PROJECT_NAME} ${SRC_FILES} ${HEAD_FILES}) -target_link_libraries(${PROJECT_NAME} gtest_main imp pmr ipc) +target_link_libraries(${PROJECT_NAME} + gtest_main + imp pmr ipc) diff --git a/test/test_ipc_shm.cpp b/test/ipc/test_ipc_shm.cpp similarity index 100% rename from test/test_ipc_shm.cpp rename to test/ipc/test_ipc_shm.cpp