mirror of
https://github.com/mutouyun/cpp-ipc.git
synced 2025-12-07 01:06:45 +08:00
use ipc::detail::max/min instead of std::max/min
This commit is contained in:
parent
ad9818a89b
commit
8a8c534f53
10
src/ipc.cpp
10
src/ipc.cpp
@ -29,11 +29,7 @@ using namespace ipc;
|
|||||||
using msg_id_t = std::size_t;
|
using msg_id_t = std::size_t;
|
||||||
|
|
||||||
template <std::size_t DataSize,
|
template <std::size_t DataSize,
|
||||||
#if __cplusplus >= 201703L
|
std::size_t AlignSize = (ipc::detail::min)(DataSize, alignof(std::max_align_t))>
|
||||||
std::size_t AlignSize = (std::min)(DataSize, alignof(std::max_align_t))>
|
|
||||||
#else /*__cplusplus < 201703L*/
|
|
||||||
std::size_t AlignSize = (alignof(std::max_align_t) < DataSize) ? alignof(std::max_align_t) : DataSize>
|
|
||||||
#endif/*__cplusplus < 201703L*/
|
|
||||||
struct msg_t;
|
struct msg_t;
|
||||||
|
|
||||||
template <std::size_t AlignSize>
|
template <std::size_t AlignSize>
|
||||||
@ -60,7 +56,7 @@ struct msg_t {
|
|||||||
template <typename T>
|
template <typename T>
|
||||||
buff_t make_cache(T& data, std::size_t size) {
|
buff_t make_cache(T& data, std::size_t size) {
|
||||||
auto ptr = mem::alloc(size);
|
auto ptr = mem::alloc(size);
|
||||||
std::memcpy(ptr, &data, (std::min)(sizeof(data), size));
|
std::memcpy(ptr, &data, (ipc::detail::min)(sizeof(data), size));
|
||||||
return { ptr, size, mem::free };
|
return { ptr, size, mem::free };
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -74,7 +70,7 @@ struct cache_t {
|
|||||||
|
|
||||||
void append(void const * data, std::size_t size) {
|
void append(void const * data, std::size_t size) {
|
||||||
if (fill_ >= buff_.size() || data == nullptr || size == 0) return;
|
if (fill_ >= buff_.size() || data == nullptr || size == 0) return;
|
||||||
auto new_fill = (std::min)(fill_ + size, buff_.size());
|
auto new_fill = (ipc::detail::min)(fill_ + size, buff_.size());
|
||||||
std::memcpy(static_cast<byte_t*>(buff_.data()) + fill_, data, new_fill - fill_);
|
std::memcpy(static_cast<byte_t*>(buff_.data()) + fill_, data, new_fill - fill_);
|
||||||
fill_ = new_fill;
|
fill_ = new_fill;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -10,6 +10,8 @@
|
|||||||
#include "def.h"
|
#include "def.h"
|
||||||
#include "rw_lock.h"
|
#include "rw_lock.h"
|
||||||
|
|
||||||
|
#include "platform/detail.h"
|
||||||
|
|
||||||
namespace ipc {
|
namespace ipc {
|
||||||
namespace mem {
|
namespace mem {
|
||||||
|
|
||||||
@ -148,11 +150,7 @@ public:
|
|||||||
using alloc_policy = AllocP;
|
using alloc_policy = AllocP;
|
||||||
|
|
||||||
enum : std::size_t {
|
enum : std::size_t {
|
||||||
#if __cplusplus >= 201703L
|
block_size = (ipc::detail::max)(BlockSize, sizeof(void*))
|
||||||
block_size = (std::max)(BlockSize, sizeof(void*))
|
|
||||||
#else /*__cplusplus < 201703L*/
|
|
||||||
block_size = (BlockSize < sizeof(void*)) ? sizeof(void*) : BlockSize
|
|
||||||
#endif/*__cplusplus < 201703L*/
|
|
||||||
};
|
};
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|||||||
@ -6,6 +6,7 @@
|
|||||||
#include <type_traits>
|
#include <type_traits>
|
||||||
#include <tuple>
|
#include <tuple>
|
||||||
#include <atomic>
|
#include <atomic>
|
||||||
|
#include <algorithm>
|
||||||
|
|
||||||
#include "def.h"
|
#include "def.h"
|
||||||
#include "export.h"
|
#include "export.h"
|
||||||
@ -57,6 +58,8 @@ namespace detail {
|
|||||||
using std::unique_ptr;
|
using std::unique_ptr;
|
||||||
using std::unique_lock;
|
using std::unique_lock;
|
||||||
using std::shared_lock;
|
using std::shared_lock;
|
||||||
|
using std::max;
|
||||||
|
using std::min;
|
||||||
|
|
||||||
#else /*__cplusplus < 201703L*/
|
#else /*__cplusplus < 201703L*/
|
||||||
|
|
||||||
@ -81,6 +84,16 @@ constexpr auto shared_lock(T&& lc) {
|
|||||||
return std::shared_lock<std::decay_t<T>> { std::forward<T>(lc) };
|
return std::shared_lock<std::decay_t<T>> { std::forward<T>(lc) };
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template <typename T>
|
||||||
|
constexpr const T& (max)(const T& a, const T& b) {
|
||||||
|
return (a < b) ? b : a;
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename T>
|
||||||
|
constexpr const T& (min)(const T& a, const T& b) {
|
||||||
|
return (b < a) ? b : a;
|
||||||
|
}
|
||||||
|
|
||||||
#endif/*__cplusplus < 201703L*/
|
#endif/*__cplusplus < 201703L*/
|
||||||
|
|
||||||
template <typename F, typename D>
|
template <typename F, typename D>
|
||||||
|
|||||||
@ -6,11 +6,12 @@
|
|||||||
#include <string>
|
#include <string>
|
||||||
#include <locale>
|
#include <locale>
|
||||||
#include <codecvt>
|
#include <codecvt>
|
||||||
#include <algorithm>
|
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
|
|
||||||
#include "concept.h"
|
#include "concept.h"
|
||||||
|
|
||||||
|
#include "platform/detail.h"
|
||||||
|
|
||||||
namespace ipc::detail {
|
namespace ipc::detail {
|
||||||
|
|
||||||
struct has_value_type_ {
|
struct has_value_type_ {
|
||||||
@ -49,7 +50,7 @@ inline auto to_tchar(T* dst, char const * src, std::size_t size) -> IsSameChar<T
|
|||||||
template <typename T>
|
template <typename T>
|
||||||
inline auto to_tchar(T* dst, char const * src, std::size_t size) -> IsSameChar<T, wchar_t, void> {
|
inline auto to_tchar(T* dst, char const * src, std::size_t size) -> IsSameChar<T, wchar_t, void> {
|
||||||
auto wstr = std::wstring_convert<std::codecvt_utf8_utf16<wchar_t>>{}.from_bytes(src, src + size);
|
auto wstr = std::wstring_convert<std::codecvt_utf8_utf16<wchar_t>>{}.from_bytes(src, src + size);
|
||||||
std::memcpy(dst, wstr.data(), (std::min)(wstr.size(), size));
|
std::memcpy(dst, wstr.data(), (ipc::detail::min)(wstr.size(), size));
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace ipc::detail
|
} // namespace ipc::detail
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user