diff --git a/src/libipc/utility/construct.h b/include/libimp/construct.h similarity index 86% rename from src/libipc/utility/construct.h rename to include/libimp/construct.h index ad21ffd..4b485b1 100644 --- a/src/libipc/utility/construct.h +++ b/include/libimp/construct.h @@ -1,5 +1,5 @@ /** - * @file src/construct.h + * @file libimp/construct.h * @author mutouyun (orz@orzz.org) * @brief Construct an object from a memory buffer * @date 2022-02-27 @@ -12,10 +12,10 @@ #include // std::construct_at, std::destroy_at, std::addressof #include -#include "libipc/def.h" -#include "libipc/detect_plat.h" +#include "libimp/def.h" +#include "libimp/detect_plat.h" -LIBIPC_NAMESPACE_BEG_ +LIBIMP_NAMESPACE_BEG_ /** * @brief Creates an object at a given address, like 'construct_at' in c++20 @@ -25,7 +25,7 @@ LIBIPC_NAMESPACE_BEG_ template auto construct(void *p, A &&... args) -> std::enable_if_t<::std::is_constructible::value, T *> { -#if defined(LIBIPC_CPP_20) +#if defined(LIBIMP_CPP_20) return std::construct_at(static_cast(p), std::forward(args)...); #else return ::new (p) T(std::forward(args)...); @@ -45,7 +45,7 @@ auto construct(void *p, A &&... args) template void *destroy(T *p) noexcept { -#if defined(LIBIPC_CPP_17) +#if defined(LIBIMP_CPP_17) std::destroy_at(p); #else p->~T(); @@ -55,9 +55,9 @@ void *destroy(T *p) noexcept { template void *destroy(T (*p)[N]) noexcept { -#if defined(LIBIPC_CPP_20) +#if defined(LIBIMP_CPP_20) std::destroy_at(p); -#elif defined(LIBIPC_CPP_17) +#elif defined(LIBIMP_CPP_17) std::destroy(std::begin(*p), std::end(*p)); #else for (auto &elem : *p) destroy(std::addressof(elem)); @@ -65,4 +65,4 @@ void *destroy(T (*p)[N]) noexcept { return p; } -LIBIPC_NAMESPACE_END_ +LIBIMP_NAMESPACE_END_ diff --git a/src/libipc/utility/countof.h b/include/libimp/countof.h similarity index 93% rename from src/libipc/utility/countof.h rename to include/libimp/countof.h index 8685e84..59c0d39 100644 --- a/src/libipc/utility/countof.h +++ b/include/libimp/countof.h @@ -1,5 +1,5 @@ /** - * @file src/countof.h + * @file libimp/countof.h * @author mutouyun (orz@orzz.org) * @brief Returns the size of the given range * @date 2022-03-01 @@ -9,10 +9,10 @@ #include // std::declval, std::true_type, std::false_type #include // std::size_t -#include "libipc/def.h" -#include "libipc/utility/generic.h" +#include "libimp/def.h" +#include "libimp/generic.h" -LIBIPC_NAMESPACE_BEG_ +LIBIMP_NAMESPACE_BEG_ /** * @see https://en.cppreference.com/w/cpp/iterator/size @@ -76,4 +76,4 @@ constexpr auto countof(C const &c) noexcept(noexcept(R::countof(c))) { return R::countof(c); } -LIBIPC_NAMESPACE_END_ +LIBIMP_NAMESPACE_END_ diff --git a/include/libimp/def.h b/include/libimp/def.h new file mode 100644 index 0000000..0b5ffb0 --- /dev/null +++ b/include/libimp/def.h @@ -0,0 +1,22 @@ +/** + * @file libimp/def.h + * @author mutouyun (orz@orzz.org) + * @brief Define the trivial configuration information + * @date 2022-04-23 + */ +#pragma once + +#include +#include + +#if !defined(LIBIMP_NAMESPACE) +# define LIBIMP_NAMESPACE imp +#endif +#define LIBIMP_NAMESPACE_BEG_ namespace LIBIMP_NAMESPACE { +#define LIBIMP_NAMESPACE_END_ } + +LIBIMP_NAMESPACE_BEG_ + +// constants + +LIBIMP_NAMESPACE_END_ diff --git a/include/libimp/detect_plat.h b/include/libimp/detect_plat.h new file mode 100644 index 0000000..13d5104 --- /dev/null +++ b/include/libimp/detect_plat.h @@ -0,0 +1,155 @@ +/** + * @file libimp/detect_plat.h + * @author mutouyun (orz@orzz.org) + * @brief Define platform detection related interfaces + * @date 2022-02-27 + */ +#pragma once + +// OS + +#if defined(WINCE) || defined(_WIN32_WCE) +# define LIBIMP_OS_WINCE +#elif defined(WIN64) || defined(_WIN64) || defined(__WIN64__) || \ + (defined(__x86_64) && defined(__MSYS__)) +#define LIBIMP_OS_WIN64 +#elif defined(WIN32) || defined(_WIN32) || defined(__WIN32__) || \ + defined(__NT__) || defined(__MSYS__) +# define LIBIMP_OS_WIN32 +#elif defined(__linux__) || defined(__linux) +# define LIBIMP_OS_LINUX +#elif defined(__QNX__) || defined(__QNXNTO__) +# define LIBIMP_OS_QNX +#elif defined(ANDROID) || defined(__ANDROID__) +# define LIBIMP_OS_ANDROID +#else +# error "This OS is unsupported." +#endif + +#if defined(LIBIMP_OS_WIN32) || defined(LIBIMP_OS_WIN64) || \ + defined(LIBIMP_OS_WINCE) +# define LIBIMP_OS_WIN +#endif + +// Compiler + +#if defined(_MSC_VER) +# define LIBIMP_CC_MSVC +#elif defined(__GNUC__) +# define LIBIMP_CC_GNUC +#else +# error "This compiler is unsupported." +#endif + +// Instruction set +// @see https://sourceforge.net/p/predef/wiki/Architectures/ + +#if defined(_M_X64) || defined(_M_AMD64) || \ + defined(__x86_64__) || defined(__x86_64) || \ + defined(__amd64__) || defined(__amd64) +# define LIBIMP_INSTR_X64 +#elif defined(_M_IA64) || defined(__IA64__) || defined(_IA64) || \ + defined(__ia64__) || defined(__ia64) +# define LIBIMP_INSTR_I64 +#elif defined(_M_IX86) || defined(_X86_) || defined(__i386__) || defined(__i386) +# define LIBIMP_INSTR_X86 +#elif defined(_M_ARM64) || defined(__arm64__) || defined(__aarch64__) +# define LIBIMP_INSTR_ARM64 +#elif defined(_M_ARM) || defined(_ARM) || defined(__arm__) || defined(__arm) +# define LIBIMP_INSTR_ARM32 +#else +# error "This instruction set is unsupported." +#endif + +#if defined(LIBIMP_INSTR_X86) || defined(LIBIMP_INSTR_X64) +# define LIBIMP_INSTR_X86_64 +#elif defined(LIBIMP_INSTR_ARM32) || defined(LIBIMP_INSTR_ARM64) +# define LIBIMP_INSTR_ARM +#endif + +// Byte order + +#if defined(__BYTE_ORDER__) +# define LIBIMP_ENDIAN_BIG (__BYTE_ORDER__ == __ORDER_BIG_ENDIAN__) +# define LIBIMP_ENDIAN_LIT (!LIBIMP_ENDIAN_BIG) +#else +# define LIBIMP_ENDIAN_BIG (0) +# define LIBIMP_ENDIAN_LIT (1) +#endif + +// C++ version + +#if (__cplusplus >= 202002L) && !defined(LIBIMP_CPP_20) +# define LIBIMP_CPP_20 +#endif +#if (__cplusplus >= 201703L) && !defined(LIBIMP_CPP_17) +# define LIBIMP_CPP_17 +#endif +#if /*(__cplusplus >= 201402L) &&*/ !defined(LIBIMP_CPP_14) +# define LIBIMP_CPP_14 +#endif + +#if !defined(LIBIMP_CPP_20) && \ + !defined(LIBIMP_CPP_17) && \ + !defined(LIBIMP_CPP_14) +# error "This C++ version is unsupported." +#endif + +// C++ attributes + +#if defined(__has_cpp_attribute) +# if __has_cpp_attribute(fallthrough) +# define LIBIMP_FALLTHROUGH [[fallthrough]] +# endif +# if __has_cpp_attribute(maybe_unused) +# define LIBIMP_UNUSED [[maybe_unused]] +# endif +# if __has_cpp_attribute(likely) +# define LIBIMP_LIKELY(...) (__VA_ARGS__) [[likely]] +# endif +# if __has_cpp_attribute(unlikely) +# define LIBIMP_UNLIKELY(...) (__VA_ARGS__) [[unlikely]] +# endif +#endif + +#if !defined(LIBIMP_FALLTHROUGH) +# if defined(LIBIMP_CC_GNUC) +# define LIBIMP_FALLTHROUGH __attribute__((__fallthrough__)) +# else +# define LIBIMP_FALLTHROUGH +# endif +#endif + +#if !defined(LIBIMP_UNUSED) +# if defined(LIBIMP_CC_GNUC) +# define LIBIMP_UNUSED __attribute__((__unused__)) +# elif defined(LIBIMP_CC_MSVC) +# define LIBIMP_UNUSED __pragma(warning(suppress: 4100 4101 4189)) +# else +# define LIBIMP_UNUSED +# endif +#endif + +#if !defined(LIBIMP_LIKELY) +# if defined(__has_builtin) +# if __has_builtin(__builtin_expect) +# define LIBIMP_LIKELY(...) (__builtin_expect(!!(__VA_ARGS__), 1)) +# endif +# endif +#endif + +#if !defined(LIBIMP_LIKELY) +# define LIBIMP_LIKELY(...) (__VA_ARGS__) +#endif + +#if !defined(LIBIMP_UNLIKELY) +# if defined(__has_builtin) +# if __has_builtin(__builtin_expect) +# define LIBIMP_UNLIKELY(...) (__builtin_expect(!!(__VA_ARGS__), 0)) +# endif +# endif +#endif + +#if !defined(LIBIMP_UNLIKELY) +# define LIBIMP_UNLIKELY(...) (__VA_ARGS__) +#endif diff --git a/src/libipc/utility/enum_cast.h b/include/libimp/enum_cast.h similarity index 76% rename from src/libipc/utility/enum_cast.h rename to include/libimp/enum_cast.h index 23fd65e..31377a1 100644 --- a/src/libipc/utility/enum_cast.h +++ b/include/libimp/enum_cast.h @@ -1,5 +1,5 @@ /** - * @file src/enum_cast.h + * @file libimp/enum_cast.h * @author mutouyun (orz@orzz.org) * @brief Returns the underlying type of the given enum * @date 2022-03-01 @@ -8,13 +8,13 @@ #include // std::underlying_type_t -#include "libipc/def.h" +#include "libimp/def.h" -LIBIPC_NAMESPACE_BEG_ +LIBIMP_NAMESPACE_BEG_ template constexpr auto enum_cast(E e) noexcept { return static_cast>(e); } -LIBIPC_NAMESPACE_END_ +LIBIMP_NAMESPACE_END_ diff --git a/include/libimp/export.h b/include/libimp/export.h new file mode 100644 index 0000000..8d1d475 --- /dev/null +++ b/include/libimp/export.h @@ -0,0 +1,46 @@ +/** + * @file libimp/export.h + * @author mutouyun (orz@orzz.org) + * @brief Define the symbol export interfaces + * @date 2022-02-27 + */ +#pragma once + +#include "libimp/detect_plat.h" + +#if defined(Q_DECL_EXPORT) && defined(Q_DECL_IMPORT) + +# define LIBIMP_DECL_EXPORT Q_DECL_EXPORT +# define LIBIMP_DECL_IMPORT Q_DECL_IMPORT + +#else // defined(Q_DECL_EXPORT) && defined(Q_DECL_IMPORT) + +/* + * Compiler & system detection for LIBIMP_DECL_EXPORT & LIBIMP_DECL_IMPORT. + * Not using QtCore cause it shouldn't depend on Qt. +*/ +# if defined(LIBIMP_CC_MSVC) || defined(LIBIMP_OS_WIN) +# define LIBIMP_DECL_EXPORT __declspec(dllexport) +# define LIBIMP_DECL_IMPORT __declspec(dllimport) +# elif defined(LIBIMP_OS_ANDROID) || defined(LIBIMP_OS_LINUX) || defined(LIBIMP_CC_GNUC) +# define LIBIMP_DECL_EXPORT __attribute__((visibility("default"))) +# define LIBIMP_DECL_IMPORT __attribute__((visibility("default"))) +# else +# define LIBIMP_DECL_EXPORT __attribute__((visibility("default"))) +# define LIBIMP_DECL_IMPORT __attribute__((visibility("default"))) +# endif + +#endif // defined(Q_DECL_EXPORT) && defined(Q_DECL_IMPORT) + +/* + * Define LIBIMP_EXPORT for exporting function & class. +*/ +#ifndef LIBIMP_EXPORT +# if defined(LIBIMP_LIBRARY_SHARED_BUILDING__) +# define LIBIMP_EXPORT LIBIMP_DECL_EXPORT +# elif defined(LIBIMP_LIBRARY_SHARED_USING__) +# define LIBIMP_EXPORT LIBIMP_DECL_IMPORT +# else +# define LIBIMP_EXPORT +# endif +#endif /*LIBIMP_EXPORT*/ diff --git a/src/libipc/utility/generic.h b/include/libimp/generic.h similarity index 76% rename from src/libipc/utility/generic.h rename to include/libimp/generic.h index 6481046..2f11b6c 100644 --- a/src/libipc/utility/generic.h +++ b/include/libimp/generic.h @@ -1,14 +1,14 @@ /** - * @file src/generic.h + * @file libimp/generic.h * @author mutouyun (orz@orzz.org) * @brief Tools for generic programming * @date 2022-03-01 */ #pragma once -#include "libipc/def.h" +#include "libimp/def.h" -LIBIPC_NAMESPACE_BEG_ +LIBIMP_NAMESPACE_BEG_ /** * @brief Utility metafunction that maps a sequence of any types to the type void @@ -17,4 +17,4 @@ LIBIPC_NAMESPACE_BEG_ template using void_t = void; -LIBIPC_NAMESPACE_END_ +LIBIMP_NAMESPACE_END_ diff --git a/src/libipc/utility/horrible_cast.h b/include/libimp/horrible_cast.h similarity index 79% rename from src/libipc/utility/horrible_cast.h rename to include/libimp/horrible_cast.h index 907882c..88520c6 100644 --- a/src/libipc/utility/horrible_cast.h +++ b/include/libimp/horrible_cast.h @@ -1,5 +1,5 @@ /** - * @file src/horrible_cast.h + * @file libimp/horrible_cast.h * @author mutouyun (orz@orzz.org) * @date 2022-04-17 */ @@ -8,9 +8,9 @@ #include // std::decay_t #include -#include "libipc/def.h" +#include "libimp/def.h" -LIBIPC_NAMESPACE_BEG_ +LIBIMP_NAMESPACE_BEG_ template constexpr auto horrible_cast(U &&in) noexcept @@ -22,4 +22,4 @@ constexpr auto horrible_cast(U &&in) noexcept return u.out; } -LIBIPC_NAMESPACE_END_ +LIBIMP_NAMESPACE_END_ diff --git a/src/libipc/utility/pimpl.h b/include/libimp/pimpl.h similarity index 92% rename from src/libipc/utility/pimpl.h rename to include/libimp/pimpl.h index 5ec7af0..9e018f0 100644 --- a/src/libipc/utility/pimpl.h +++ b/include/libimp/pimpl.h @@ -1,5 +1,5 @@ /** - * @file src/pimpl.h + * @file libimp/pimpl.h * @author mutouyun (orz@orzz.org) * @brief Pointer To Implementation (pImpl) idiom * @date 2022-02-27 @@ -10,10 +10,10 @@ #include #include -#include "libipc/utility/construct.h" -#include "libipc/def.h" +#include "libimp/construct.h" +#include "libimp/def.h" -LIBIPC_NAMESPACE_BEG_ +LIBIMP_NAMESPACE_BEG_ namespace pimpl { template @@ -70,4 +70,4 @@ public: }; } // namespace pimpl -LIBIPC_NAMESPACE_END_ +LIBIMP_NAMESPACE_END_ diff --git a/include/libipc/result.h b/include/libimp/result.h similarity index 81% rename from include/libipc/result.h rename to include/libimp/result.h index 2ad7c23..92b39db 100644 --- a/include/libipc/result.h +++ b/include/libimp/result.h @@ -1,5 +1,5 @@ /** - * @file result.h + * @file libimp/result.h * @author mutouyun (orz@orzz.org) * @brief Define the return value type with a status code * @date 2022-04-17 @@ -9,12 +9,12 @@ #include // std::ostream #include -#include "libipc/def.h" -#include "libipc/export.h" +#include "libimp/def.h" +#include "libimp/export.h" -LIBIPC_NAMESPACE_BEG_ +LIBIMP_NAMESPACE_BEG_ -class LIBIPC_EXPORT result { +class LIBIMP_EXPORT result { std::uint64_t status_; public: @@ -34,4 +34,4 @@ public: friend std::ostream &operator<<(std::ostream &o, result const &r) noexcept; }; -LIBIPC_NAMESPACE_END_ +LIBIMP_NAMESPACE_END_ diff --git a/include/libipc/def.h b/include/libipc/def.h index de9a496..aa0c0c8 100755 --- a/include/libipc/def.h +++ b/include/libipc/def.h @@ -1,5 +1,5 @@ /** - * @file def.h + * @file libipc/def.h * @author mutouyun (orz@orzz.org) * @brief Define the trivial configuration information * @date 2022-02-27 diff --git a/include/libipc/detect_plat.h b/include/libipc/detect_plat.h deleted file mode 100644 index a90aef2..0000000 --- a/include/libipc/detect_plat.h +++ /dev/null @@ -1,155 +0,0 @@ -/** - * @file detect_plat.h - * @author mutouyun (orz@orzz.org) - * @brief Define platform detection related interfaces - * @date 2022-02-27 - */ -#pragma once - -// OS - -#if defined(WINCE) || defined(_WIN32_WCE) -# define LIBIPC_OS_WINCE -#elif defined(WIN64) || defined(_WIN64) || defined(__WIN64__) || \ - (defined(__x86_64) && defined(__MSYS__)) -#define LIBIPC_OS_WIN64 -#elif defined(WIN32) || defined(_WIN32) || defined(__WIN32__) || \ - defined(__NT__) || defined(__MSYS__) -# define LIBIPC_OS_WIN32 -#elif defined(__linux__) || defined(__linux) -# define LIBIPC_OS_LINUX -#elif defined(__QNX__) || defined(__QNXNTO__) -# define LIBIPC_OS_QNX -#elif defined(ANDROID) || defined(__ANDROID__) -# define LIBIPC_OS_ANDROID -#else -# error "This OS is unsupported." -#endif - -#if defined(LIBIPC_OS_WIN32) || defined(LIBIPC_OS_WIN64) || \ - defined(LIBIPC_OS_WINCE) -# define LIBIPC_OS_WIN -#endif - -// Compiler - -#if defined(_MSC_VER) -# define LIBIPC_CC_MSVC -#elif defined(__GNUC__) -# define LIBIPC_CC_GNUC -#else -# error "This compiler is unsupported." -#endif - -// Instruction set -// @see https://sourceforge.net/p/predef/wiki/Architectures/ - -#if defined(_M_X64) || defined(_M_AMD64) || \ - defined(__x86_64__) || defined(__x86_64) || \ - defined(__amd64__) || defined(__amd64) -# define LIBIPC_INSTR_X64 -#elif defined(_M_IA64) || defined(__IA64__) || defined(_IA64) || \ - defined(__ia64__) || defined(__ia64) -# define LIBIPC_INSTR_I64 -#elif defined(_M_IX86) || defined(_X86_) || defined(__i386__) || defined(__i386) -# define LIBIPC_INSTR_X86 -#elif defined(_M_ARM64) || defined(__arm64__) || defined(__aarch64__) -# define LIBIPC_INSTR_ARM64 -#elif defined(_M_ARM) || defined(_ARM) || defined(__arm__) || defined(__arm) -# define LIBIPC_INSTR_ARM32 -#else -# error "This instruction set is unsupported." -#endif - -#if defined(LIBIPC_INSTR_X86) || defined(LIBIPC_INSTR_X64) -# define LIBIPC_INSTR_X86_64 -#elif defined(LIBIPC_INSTR_ARM32) || defined(LIBIPC_INSTR_ARM64) -# define LIBIPC_INSTR_ARM -#endif - -// Byte order - -#if defined(__BYTE_ORDER__) -# define LIBIPC_ENDIAN_BIG (__BYTE_ORDER__ == __ORDER_BIG_ENDIAN__) -# define LIBIPC_ENDIAN_LIT (!LIBIPC_ENDIAN_BIG) -#else -# define LIBIPC_ENDIAN_BIG (0) -# define LIBIPC_ENDIAN_LIT (1) -#endif - -// C++ version - -#if (__cplusplus >= 202002L) && !defined(LIBIPC_CPP_20) -# define LIBIPC_CPP_20 -#endif -#if (__cplusplus >= 201703L) && !defined(LIBIPC_CPP_17) -# define LIBIPC_CPP_17 -#endif -#if /*(__cplusplus >= 201402L) &&*/ !defined(LIBIPC_CPP_14) -# define LIBIPC_CPP_14 -#endif - -#if !defined(LIBIPC_CPP_20) && \ - !defined(LIBIPC_CPP_17) && \ - !defined(LIBIPC_CPP_14) -# error "This C++ version is unsupported." -#endif - -// C++ attributes - -#if defined(__has_cpp_attribute) -# if __has_cpp_attribute(fallthrough) -# define LIBIPC_FALLTHROUGH [[fallthrough]] -# endif -# if __has_cpp_attribute(maybe_unused) -# define LIBIPC_UNUSED [[maybe_unused]] -# endif -# if __has_cpp_attribute(likely) -# define LIBIPC_LIKELY(...) (__VA_ARGS__) [[likely]] -# endif -# if __has_cpp_attribute(unlikely) -# define LIBIPC_UNLIKELY(...) (__VA_ARGS__) [[unlikely]] -# endif -#endif - -#if !defined(LIBIPC_FALLTHROUGH) -# if defined(LIBIPC_CC_GNUC) -# define LIBIPC_FALLTHROUGH __attribute__((__fallthrough__)) -# else -# define LIBIPC_FALLTHROUGH -# endif -#endif - -#if !defined(LIBIPC_UNUSED) -# if defined(LIBIPC_CC_GNUC) -# define LIBIPC_UNUSED __attribute__((__unused__)) -# elif defined(LIBIPC_CC_MSVC) -# define LIBIPC_UNUSED __pragma(warning(suppress: 4100 4101 4189)) -# else -# define LIBIPC_UNUSED -# endif -#endif - -#if !defined(LIBIPC_LIKELY) -# if defined(__has_builtin) -# if __has_builtin(__builtin_expect) -# define LIBIPC_LIKELY(...) (__builtin_expect(!!(__VA_ARGS__), 1)) -# endif -# endif -#endif - -#if !defined(LIBIPC_LIKELY) -# define LIBIPC_LIKELY(...) (__VA_ARGS__) -#endif - -#if !defined(LIBIPC_UNLIKELY) -# if defined(__has_builtin) -# if __has_builtin(__builtin_expect) -# define LIBIPC_UNLIKELY(...) (__builtin_expect(!!(__VA_ARGS__), 0)) -# endif -# endif -#endif - -#if !defined(LIBIPC_UNLIKELY) -# define LIBIPC_UNLIKELY(...) (__VA_ARGS__) -#endif diff --git a/include/libipc/export.h b/include/libipc/export.h deleted file mode 100755 index 40a6879..0000000 --- a/include/libipc/export.h +++ /dev/null @@ -1,46 +0,0 @@ -/** - * @file export.h - * @author mutouyun (orz@orzz.org) - * @brief Define the symbol export interfaces - * @date 2022-02-27 - */ -#pragma once - -#include "libipc/detect_plat.h" - -#if defined(Q_DECL_EXPORT) && defined(Q_DECL_IMPORT) - -# define LIBIPC_DECL_EXPORT Q_DECL_EXPORT -# define LIBIPC_DECL_IMPORT Q_DECL_IMPORT - -#else // defined(Q_DECL_EXPORT) && defined(Q_DECL_IMPORT) - -/* - * Compiler & system detection for LIBIPC_DECL_EXPORT & LIBIPC_DECL_IMPORT. - * Not using QtCore cause it shouldn't depend on Qt. -*/ -# if defined(LIBIPC_CC_MSVC) || defined(LIBIPC_OS_WIN) -# define LIBIPC_DECL_EXPORT __declspec(dllexport) -# define LIBIPC_DECL_IMPORT __declspec(dllimport) -# elif defined(LIBIPC_OS_ANDROID) || defined(LIBIPC_OS_LINUX) || defined(LIBIPC_CC_GNUC) -# define LIBIPC_DECL_EXPORT __attribute__((visibility("default"))) -# define LIBIPC_DECL_IMPORT __attribute__((visibility("default"))) -# else -# define LIBIPC_DECL_EXPORT __attribute__((visibility("default"))) -# define LIBIPC_DECL_IMPORT __attribute__((visibility("default"))) -# endif - -#endif // defined(Q_DECL_EXPORT) && defined(Q_DECL_IMPORT) - -/* - * Define LIBIPC_EXPORT for exporting function & class. -*/ -#ifndef LIBIPC_EXPORT -# if defined(LIBIPC_LIBRARY_SHARED_BUILDING__) -# define LIBIPC_EXPORT LIBIPC_DECL_EXPORT -# elif defined(LIBIPC_LIBRARY_SHARED_USING__) -# define LIBIPC_EXPORT LIBIPC_DECL_IMPORT -# else -# define LIBIPC_EXPORT -# endif -#endif /*LIBIPC_EXPORT*/ diff --git a/include/libipc/mmap.h b/include/libipc/mmap.h index d8d57be..aefeb14 100644 --- a/include/libipc/mmap.h +++ b/include/libipc/mmap.h @@ -1,14 +1,14 @@ /** - * @file mmap.h + * @file libipc/mmap.h * @author mutouyun (orz@orzz.org) * @brief Define the methods of memory-mapped file I/O * @date 2022-04-17 */ #pragma once +#include "libimp/export.h" +#include "libimp/result.h" #include "libipc/def.h" -#include "libipc/export.h" -#include "libipc/result.h" LIBIPC_NAMESPACE_BEG_ diff --git a/include/libipc/shm.h b/include/libipc/shm.h index 408a8aa..b2ed519 100644 --- a/include/libipc/shm.h +++ b/include/libipc/shm.h @@ -1,5 +1,5 @@ /** - * @file shm.h + * @file libipc/shm.h * @author mutouyun (orz@orzz.org) * @brief Define the shared memory access interface * @date 2022-04-17 diff --git a/include/libipc/spin_lock.h b/include/libipc/spin_lock.h index 1ed94d9..7f31889 100644 --- a/include/libipc/spin_lock.h +++ b/include/libipc/spin_lock.h @@ -1,5 +1,5 @@ /** - * @file spin_lock.h + * @file libipc/spin_lock.h * @author mutouyun (orz@orzz.org) * @brief Define spin locks * @date 2022-02-27 @@ -13,7 +13,7 @@ #include #include -#include "libipc/detect_plat.h" +#include "libimp/detect_plat.h" #include "libipc/def.h" /** diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 37efae1..38f4cb3 100755 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -1,46 +1,3 @@ -project(ipc) -aux_source_directory(${LIBIPC_PROJECT_DIR}/src/libipc SRC_FILES) - -file(GLOB HEAD_FILES - ${LIBIPC_PROJECT_DIR}/include/libipc/*.h) - -if (LIBIPC_BUILD_SHARED_LIBS) - add_library(${PROJECT_NAME} SHARED ${SRC_FILES} ${HEAD_FILES}) - target_compile_definitions(${PROJECT_NAME} - INTERFACE - LIBIPC_LIBRARY_SHARED_USING__ - PRIVATE - LIBIPC_LIBRARY_SHARED_BUILDING__) -else() - add_library(${PROJECT_NAME} STATIC ${SRC_FILES} ${HEAD_FILES}) -endif() - -# set output directory -set_target_properties(${PROJECT_NAME} - PROPERTIES - ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/lib" - LIBRARY_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/lib" - RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin") - -# set version -set_target_properties(${PROJECT_NAME} - PROPERTIES - VERSION 2.0.0 - SOVERSION 4) - -target_include_directories(${PROJECT_NAME} - PUBLIC ${LIBIPC_PROJECT_DIR}/include - PRIVATE ${LIBIPC_PROJECT_DIR}/src) - -if(NOT MSVC) - target_link_libraries(${PROJECT_NAME} PUBLIC - $<$>:pthread> - $<$,$>>:rt>) -endif() - -install( - TARGETS ${PROJECT_NAME} - RUNTIME DESTINATION bin - LIBRARY DESTINATION lib - ARCHIVE DESTINATION lib) +add_subdirectory(libimp) +add_subdirectory(libipc) diff --git a/src/libimp/CMakeLists.txt b/src/libimp/CMakeLists.txt new file mode 100644 index 0000000..f61ecf1 --- /dev/null +++ b/src/libimp/CMakeLists.txt @@ -0,0 +1,25 @@ +project(imp) + +aux_source_directory(${LIBIPC_PROJECT_DIR}/src/libimp SRC_FILES) + +file(GLOB HEAD_FILES + ${LIBIPC_PROJECT_DIR}/include/libimp/*.h) + +add_library(${PROJECT_NAME} STATIC ${SRC_FILES} ${HEAD_FILES}) + +# set output directory +set_target_properties(${PROJECT_NAME} + PROPERTIES + ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/lib" + LIBRARY_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/lib" + RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin") + +target_include_directories(${PROJECT_NAME} + PUBLIC ${LIBIPC_PROJECT_DIR}/include + PRIVATE ${LIBIPC_PROJECT_DIR}/src) + +install( + TARGETS ${PROJECT_NAME} + RUNTIME DESTINATION bin + LIBRARY DESTINATION lib + ARCHIVE DESTINATION lib) diff --git a/src/libipc/result.cpp b/src/libimp/result.cpp similarity index 90% rename from src/libipc/result.cpp rename to src/libimp/result.cpp index 1110fe9..055703f 100644 --- a/src/libipc/result.cpp +++ b/src/libimp/result.cpp @@ -1,8 +1,8 @@ -#include "libipc/result.h" -#include "libipc/utility/horrible_cast.h" +#include "libimp/result.h" +#include "libimp/horrible_cast.h" -LIBIPC_NAMESPACE_BEG_ +LIBIMP_NAMESPACE_BEG_ namespace { struct result_code_info { @@ -47,4 +47,4 @@ std::ostream &operator<<(std::ostream &o, result const &r) noexcept { return o; } -LIBIPC_NAMESPACE_END_ +LIBIMP_NAMESPACE_END_ diff --git a/src/libipc/CMakeLists.txt b/src/libipc/CMakeLists.txt new file mode 100644 index 0000000..60007c1 --- /dev/null +++ b/src/libipc/CMakeLists.txt @@ -0,0 +1,47 @@ +project(ipc) + +aux_source_directory(${LIBIPC_PROJECT_DIR}/src/libipc SRC_FILES) + +file(GLOB HEAD_FILES + ${LIBIPC_PROJECT_DIR}/include/libipc/*.h) + +if (LIBIPC_BUILD_SHARED_LIBS) + add_library(${PROJECT_NAME} SHARED ${SRC_FILES} ${HEAD_FILES}) + target_compile_definitions(${PROJECT_NAME} + INTERFACE + LIBIPC_LIBRARY_SHARED_USING__ + PRIVATE + LIBIPC_LIBRARY_SHARED_BUILDING__) +else() + add_library(${PROJECT_NAME} STATIC ${SRC_FILES} ${HEAD_FILES}) +endif() + +# set output directory +set_target_properties(${PROJECT_NAME} + PROPERTIES + ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/lib" + LIBRARY_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/lib" + RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin") + +# set version +set_target_properties(${PROJECT_NAME} + PROPERTIES + VERSION 2.0.0 + SOVERSION 4) + +target_include_directories(${PROJECT_NAME} + PUBLIC ${LIBIPC_PROJECT_DIR}/include + PRIVATE ${LIBIPC_PROJECT_DIR}/src) + +if(NOT MSVC) + target_link_libraries(${PROJECT_NAME} PUBLIC + $<$>:pthread> + $<$,$>>:rt>) +endif() +target_link_libraries(${PROJECT_NAME} PUBLIC imp) + +install( + TARGETS ${PROJECT_NAME} + RUNTIME DESTINATION bin + LIBRARY DESTINATION lib + ARCHIVE DESTINATION lib) diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index dfd7fc2..8633271 100755 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -21,5 +21,5 @@ file(GLOB HEAD_FILES ${LIBIPC_PROJECT_DIR}/test/*.h) add_executable(${PROJECT_NAME} ${SRC_FILES} ${HEAD_FILES}) link_directories(${LIBIPC_PROJECT_DIR}/3rdparty/gperftools) -target_link_libraries(${PROJECT_NAME} gtest gtest_main ipc) +target_link_libraries(${PROJECT_NAME} gtest gtest_main imp ipc) #target_link_libraries(${PROJECT_NAME} tcmalloc_minimal) diff --git a/test/test_detect_plat.cpp b/test/test_detect_plat.cpp index 99ec8a2..4ec8400 100644 --- a/test/test_detect_plat.cpp +++ b/test/test_detect_plat.cpp @@ -4,45 +4,45 @@ #include "gtest/gtest.h" -#include "libipc/detect_plat.h" +#include "libimp/detect_plat.h" namespace { } // namespace TEST(detect_plat, os) { -#if defined(LIBIPC_OS_WINCE) - std::cout << "LIBIPC_OS_WINCE\n"; -#elif defined(LIBIPC_OS_WIN) - std::cout << "LIBIPC_OS_WIN\n"; -#elif defined(LIBIPC_OS_LINUX) - std::cout << "LIBIPC_OS_LINUX\n"; -#elif defined(LIBIPC_OS_QNX) - std::cout << "LIBIPC_OS_QNX\n"; -#elif defined(LIBIPC_OS_ANDROID) - std::cout << "LIBIPC_OS_ANDROID\n"; +#if defined(LIBIMP_OS_WINCE) + std::cout << "LIBIMP_OS_WINCE\n"; +#elif defined(LIBIMP_OS_WIN) + std::cout << "LIBIMP_OS_WIN\n"; +#elif defined(LIBIMP_OS_LINUX) + std::cout << "LIBIMP_OS_LINUX\n"; +#elif defined(LIBIMP_OS_QNX) + std::cout << "LIBIMP_OS_QNX\n"; +#elif defined(LIBIMP_OS_ANDROID) + std::cout << "LIBIMP_OS_ANDROID\n"; #else ASSERT_TRUE(false); #endif } TEST(detect_plat, cc) { -#if defined(LIBIPC_CC_MSVC) - std::cout << "LIBIPC_CC_MSVC\n"; -#elif defined(LIBIPC_CC_GNUC) - std::cout << "LIBIPC_CC_GNUC\n"; +#if defined(LIBIMP_CC_MSVC) + std::cout << "LIBIMP_CC_MSVC\n"; +#elif defined(LIBIMP_CC_GNUC) + std::cout << "LIBIMP_CC_GNUC\n"; #else ASSERT_TRUE(false); #endif } TEST(detect_plat, cpp) { -#if defined(LIBIPC_CPP_20) - std::cout << "LIBIPC_CPP_20\n"; -#elif defined(LIBIPC_CPP_17) - std::cout << "LIBIPC_CPP_17\n"; -#elif defined(LIBIPC_CPP_14) - std::cout << "LIBIPC_CPP_14\n"; +#if defined(LIBIMP_CPP_20) + std::cout << "LIBIMP_CPP_20\n"; +#elif defined(LIBIMP_CPP_17) + std::cout << "LIBIMP_CPP_17\n"; +#elif defined(LIBIMP_CPP_14) + std::cout << "LIBIMP_CPP_14\n"; #else ASSERT_TRUE(false); #endif @@ -57,18 +57,18 @@ TEST(detect_plat, byte_order) { c.a = 1; return c.b == 1; }; - EXPECT_EQ(!!LIBIPC_ENDIAN_LIT, is_endian_little()); - EXPECT_NE(!!LIBIPC_ENDIAN_BIG, is_endian_little()); + EXPECT_EQ(!!LIBIMP_ENDIAN_LIT, is_endian_little()); + EXPECT_NE(!!LIBIMP_ENDIAN_BIG, is_endian_little()); } TEST(detect_plat, fallthrough) { switch (0) { case 0: std::cout << "fallthrough 0\n"; - LIBIPC_FALLTHROUGH; + LIBIMP_FALLTHROUGH; case 1: std::cout << "fallthrough 1\n"; - LIBIPC_FALLTHROUGH; + LIBIMP_FALLTHROUGH; default: std::cout << "fallthrough default\n"; break; @@ -76,14 +76,14 @@ TEST(detect_plat, fallthrough) { } TEST(detect_plat, unused) { - LIBIPC_UNUSED int abc; + LIBIMP_UNUSED int abc; } TEST(detect_plat, likely_unlikely) { int xx = sizeof(int); - if LIBIPC_LIKELY(xx < sizeof(long long)) { + if LIBIMP_LIKELY(xx < sizeof(long long)) { std::cout << "sizeof(int) < sizeof(long long)\n"; - } else if LIBIPC_UNLIKELY(xx < sizeof(char)) { + } else if LIBIMP_UNLIKELY(xx < sizeof(char)) { std::cout << "sizeof(int) < sizeof(char)\n"; } else { std::cout << "sizeof(int) < whatever\n"; diff --git a/test/test_result.cpp b/test/test_result.cpp index b89d2b3..e04c6e3 100644 --- a/test/test_result.cpp +++ b/test/test_result.cpp @@ -3,10 +3,10 @@ #include "gtest/gtest.h" -#include "libipc/result.h" +#include "libimp/result.h" TEST(result, ok) { - ipc::result ret; + imp::result ret; EXPECT_FALSE(ret); EXPECT_FALSE(ret.ok()); EXPECT_EQ(ret.code(), 0); @@ -23,7 +23,7 @@ TEST(result, ok) { } TEST(result, code) { - ipc::result ret(true, 1234); + imp::result ret(true, 1234); EXPECT_TRUE(ret); EXPECT_TRUE(ret.ok()); EXPECT_EQ(ret.code(), 1234); @@ -40,16 +40,16 @@ TEST(result, code) { } TEST(result, compare) { - ipc::result r1, r2; + imp::result r1, r2; EXPECT_EQ(r1, r2); - ipc::result r3(true); + imp::result r3(true); EXPECT_NE(r1, r3); - ipc::result r4(true, 222222); + imp::result r4(true, 222222); EXPECT_NE(r3, r4); - ipc::result r5(false, 222222); + imp::result r5(false, 222222); EXPECT_NE(r4, r5); r3 = r5; EXPECT_EQ(r3, r5); @@ -57,17 +57,17 @@ TEST(result, compare) { TEST(result, print) { std::stringstream ss; - ipc::result r1; + imp::result r1; ss << r1; EXPECT_EQ(ss.str(), "[fail, code = 0]"); ss = {}; - ipc::result r2(true, 65537); + imp::result r2(true, 65537); ss << r2; EXPECT_EQ(ss.str(), "[succ, code = 65537]"); ss = {}; - ipc::result r3(true); + imp::result r3(true); ss << r3; EXPECT_EQ(ss.str(), "[succ, code = 0]"); } \ No newline at end of file diff --git a/test/test_utility.cpp b/test/test_utility.cpp index ba2bec7..c16def4 100644 --- a/test/test_utility.cpp +++ b/test/test_utility.cpp @@ -5,12 +5,11 @@ #include "gtest/gtest.h" -#include "libipc/utility/construct.h" -#include "libipc/utility/pimpl.h" -#include "libipc/utility/countof.h" -#include "libipc/utility/horrible_cast.h" - -#include "libipc/detect_plat.h" +#include "libimp/construct.h" +#include "libimp/pimpl.h" +#include "libimp/countof.h" +#include "libimp/horrible_cast.h" +#include "libimp/detect_plat.h" TEST(utility, construct) { struct Foo { @@ -19,11 +18,11 @@ TEST(utility, construct) { char c_; }; std::aligned_storage_t foo; - Foo *pfoo = ipc::construct(&foo, 123, short{321}, '1'); + Foo *pfoo = imp::construct(&foo, 123, short{321}, '1'); EXPECT_EQ(pfoo->a_, 123); EXPECT_EQ(pfoo->b_, 321); EXPECT_EQ(pfoo->c_, '1'); - ipc::destroy(pfoo); + imp::destroy(pfoo); static int bar_test_flag = 0; struct Bar : Foo { @@ -34,34 +33,34 @@ TEST(utility, construct) { ~Bar() { --bar_test_flag; } }; std::aligned_storage_t bar; - Bar *pbar = ipc::construct(&bar, 123, short(321), '1'); + Bar *pbar = imp::construct(&bar, 123, short(321), '1'); EXPECT_EQ(pbar->a_, 123); EXPECT_EQ(pbar->b_, 321); EXPECT_EQ(pbar->c_, '1'); EXPECT_EQ(bar_test_flag, 1); - ipc::destroy(pbar); + imp::destroy(pbar); EXPECT_EQ(bar_test_flag, 0); std::aligned_storage_t bars[3]; for (auto &b : bars) { - auto pb = ipc::construct(&b, 321, short(123), '3'); + auto pb = imp::construct(&b, 321, short(123), '3'); EXPECT_EQ(pb->a_, 321); EXPECT_EQ(pb->b_, 123); EXPECT_EQ(pb->c_, '3'); } - //EXPECT_EQ(bar_test_flag, ipc::countof(bars)); - ipc::destroy(reinterpret_cast(&bars)); + //EXPECT_EQ(bar_test_flag, imp::countof(bars)); + imp::destroy(reinterpret_cast(&bars)); EXPECT_EQ(bar_test_flag, 0); } namespace { -struct Foo : ipc::pimpl::Obj { +struct Foo : imp::pimpl::Obj { int *pi_; Foo(int *pi) : pi_(pi) {} }; -struct Bar : ipc::pimpl::Obj { +struct Bar : imp::pimpl::Obj { int *pi_; int *pj_; Bar(int *pi, int *pj) : pi_(pi), pj_(pj) {} @@ -70,24 +69,24 @@ struct Bar : ipc::pimpl::Obj { } // namespace TEST(utility, pimpl_is_comfortable) { - EXPECT_TRUE ((ipc::pimpl::is_comfortable::value)); - EXPECT_TRUE ((ipc::pimpl::is_comfortable::value)); - EXPECT_FALSE((ipc::pimpl::is_comfortable::value)); + EXPECT_TRUE ((imp::pimpl::is_comfortable::value)); + EXPECT_TRUE ((imp::pimpl::is_comfortable::value)); + EXPECT_FALSE((imp::pimpl::is_comfortable::value)); - EXPECT_TRUE ((ipc::pimpl::is_comfortable::value)); - EXPECT_FALSE((ipc::pimpl::is_comfortable::value)); + EXPECT_TRUE ((imp::pimpl::is_comfortable::value)); + EXPECT_FALSE((imp::pimpl::is_comfortable::value)); } TEST(utility, pimpl_inherit) { int i = 123; Foo *pfoo = Foo::make(&i); - EXPECT_EQ(ipc::pimpl::get(pfoo)->pi_, &i); + EXPECT_EQ(imp::pimpl::get(pfoo)->pi_, &i); pfoo->clear(); int j = 321; Bar *pbar = Bar::make(&i, &j); - EXPECT_EQ(ipc::pimpl::get(pbar)->pi_, &i); - EXPECT_EQ(ipc::pimpl::get(pbar)->pj_, &j); + EXPECT_EQ(imp::pimpl::get(pbar)->pi_, &i); + EXPECT_EQ(imp::pimpl::get(pbar)->pj_, &j); pbar->clear(); } @@ -95,14 +94,14 @@ TEST(utility, countof) { struct { constexpr int Size() const noexcept { return 3; } } sv; - EXPECT_FALSE(ipc::detail::countof_trait_has_size::value); - EXPECT_TRUE (ipc::detail::countof_trait_has_Size::value); + EXPECT_FALSE(imp::detail::countof_trait_has_size::value); + EXPECT_TRUE (imp::detail::countof_trait_has_Size::value); std::vector vec {1, 2, 3, 4, 5}; int arr[] {7, 6, 5, 4, 3, 2, 1}; - EXPECT_EQ(ipc::countof(sv) , sv.Size()); - EXPECT_EQ(ipc::countof(vec), vec.size()); - EXPECT_EQ(ipc::countof(arr), sizeof(arr) / sizeof(arr[0])); + EXPECT_EQ(imp::countof(sv) , sv.Size()); + EXPECT_EQ(imp::countof(vec), vec.size()); + EXPECT_EQ(imp::countof(arr), sizeof(arr) / sizeof(arr[0])); } TEST(utility, horrible_cast) { @@ -112,11 +111,11 @@ TEST(utility, horrible_cast) { struct B { char a_[sizeof(int)]; - } b = ipc::horrible_cast(a); + } b = imp::horrible_cast(a); EXPECT_EQ(b.a_[1], 0); EXPECT_EQ(b.a_[2], 0); -#if LIBIPC_ENDIAN_LIT +#if LIBIMP_ENDIAN_LIT EXPECT_EQ(b.a_[0], 123); EXPECT_EQ(b.a_[3], 0); #else @@ -124,5 +123,5 @@ TEST(utility, horrible_cast) { EXPECT_EQ(b.a_[0], 0); #endif - // ipc::horrible_cast(0ll); + // imp::horrible_cast(0ll); } \ No newline at end of file