cmake库改造前
This commit is contained in:
+7
-6
@@ -1,10 +1,11 @@
|
||||
# pfr库虽然是cmake构建但是没有安装脚本
|
||||
set(Psc_Core_dependencies global::GTest global::spdlog global::magic_enum)
|
||||
rcl_add_dependency_action_targets(Psc_Core_env ${Psc_Core_dependencies})
|
||||
set_target_properties(Psc_Core_env PROPERTIES FOLDER "Psc_Core")
|
||||
set(name "Psc_Core")
|
||||
set_target_properties(Psc_Core_env PROPERTIES FOLDER ${name})
|
||||
library_is_installed_with_rely(Psc_Core_dependencies_installed ${Psc_Core_dependencies})
|
||||
if (NOT Psc_Core_dependencies_installed)
|
||||
message(STATUS "CPP_Core 依赖未安装,请先构建 Psc_Core_env 目标")
|
||||
message(STATUS "[FATAL_ERROR] ${name} 依赖未安装,请先构建 ${name}_env 目标")
|
||||
return()
|
||||
else ()
|
||||
find_package(spdlog CONFIG REQUIRED)
|
||||
@@ -19,7 +20,7 @@ add_subdirectory(${CMAKE_CURRENT_LIST_DIR}/3rd/pfr ${CMAKE_CURRENT_BINARY_DIR}/p
|
||||
add_library(Psc_Core_Interface INTERFACE)
|
||||
target_include_directories(Psc_Core_Interface INTERFACE "${base_dir}")
|
||||
target_include_directories(Psc_Core_Interface INTERFACE ${3rd_dir}/magic_enum/magic_enum/include)
|
||||
set_target_properties(Psc_Core_Interface PROPERTIES FOLDER "Psc_Core")
|
||||
set_target_properties(Psc_Core_Interface PROPERTIES FOLDER ${name})
|
||||
append_glob_source(srcs ${core_src_dir})
|
||||
add_library(Psc_Core_Static STATIC ${srcs})
|
||||
generate_aggregate_sources(${base_dir}/private_psc_global_include ${core_src_dir}/Base "../../private_psc_global_include" "global_include")
|
||||
@@ -41,6 +42,7 @@ if (WIN32)
|
||||
dbghelp
|
||||
iphlpapi
|
||||
)
|
||||
target_compile_definitions(Psc_Core_Static PUBLIC NOMINMAX)
|
||||
endif ()
|
||||
if (CMAKE_SYSTEM_NAME STREQUAL "Linux")
|
||||
target_link_libraries(Psc_Core_Static PUBLIC
|
||||
@@ -62,9 +64,8 @@ set_target_properties(Psc_Core_Static PROPERTIES
|
||||
AUTORCC OFF
|
||||
)
|
||||
set_property(TARGET Psc_Core_Static PROPERTY POSITION_INDEPENDENT_CODE ON)
|
||||
set_target_properties(Psc_Core_Static PROPERTIES FOLDER "Psc_Core")
|
||||
set_target_properties(Psc_Core_Static PROPERTIES FOLDER ${name})
|
||||
add_executable(Psc_Core_exe ${CMAKE_CURRENT_LIST_DIR}/main.cpp)
|
||||
target_link_libraries(Psc_Core_exe PRIVATE Psc_Core_Static)
|
||||
set_target_properties(Psc_Core_exe PROPERTIES FOLDER "Psc_Core")
|
||||
|
||||
set_target_properties(Psc_Core_exe PROPERTIES FOLDER ${name})
|
||||
|
||||
|
||||
@@ -1,14 +1,10 @@
|
||||
#pragma once
|
||||
#include <algorithm>
|
||||
#include <cstdint>
|
||||
#include <cstring>
|
||||
#include <memory_resource>
|
||||
#include <mutex>
|
||||
#include <string>
|
||||
#include <string_view>
|
||||
#include <vector>
|
||||
#include "../system/export.h"
|
||||
#include "Psc_Cpp_Core/Base/global_include.h"
|
||||
namespace Psc {
|
||||
// -------------------- utils --------------------
|
||||
template <typename Size_T>
|
||||
@@ -33,7 +29,8 @@ template <typename MutexT, typename Size_T>
|
||||
class Base_RingBuffer {
|
||||
static_assert(std::is_unsigned_v<Size_T>, "Size_T must be unsigned");
|
||||
public:
|
||||
explicit Base_RingBuffer(std::pmr::memory_resource* resource = std::pmr::get_default_resource()) : buf_(resource) {}
|
||||
explicit Base_RingBuffer(std::pmr::memory_resource* resource = std::pmr::get_default_resource()) : buf_(resource) {
|
||||
}
|
||||
void init(Size_T min_capacity) {
|
||||
// 防御:min_capacity + 1 溢出
|
||||
if (min_capacity >= std::numeric_limits<Size_T>::max()) {
|
||||
@@ -76,8 +73,7 @@ protected:
|
||||
void write_bytes_unsafe(const void* data, Size_T len) {
|
||||
const Size_T end = std::min(len, capacity - tail);
|
||||
std::memcpy(buf_.data() + tail, data, end);
|
||||
std::memcpy(buf_.data(), static_cast<const std::uint8_t*>(data) + end,
|
||||
len - end);
|
||||
std::memcpy(buf_.data(), static_cast<const std::uint8_t*>(data) + end, len - end);
|
||||
tail = (tail + len) & mask_;
|
||||
}
|
||||
void read_bytes_unsafe(void* out, Size_T len) {
|
||||
@@ -174,8 +170,7 @@ public:
|
||||
const Size_T cap = this->capacity;
|
||||
const Size_T end = std::min(msg_len, cap - off);
|
||||
std::memcpy(out, this->buf_.data() + off, end);
|
||||
std::memcpy(static_cast<std::uint8_t*>(out) + end, this->buf_.data(),
|
||||
msg_len - end);
|
||||
std::memcpy(static_cast<std::uint8_t*>(out) + end, this->buf_.data(), msg_len - end);
|
||||
out_len = msg_len;
|
||||
return true;
|
||||
}
|
||||
@@ -249,8 +244,7 @@ public:
|
||||
// 等价于从 head 开始 peek actual 字节
|
||||
const Size_T end = std::min(actual, this->capacity - this->head);
|
||||
std::memcpy(out, this->buf_.data() + this->head, end);
|
||||
std::memcpy(static_cast<std::uint8_t*>(out) + end, this->buf_.data(),
|
||||
actual - end);
|
||||
std::memcpy(static_cast<std::uint8_t*>(out) + end, this->buf_.data(), actual - end);
|
||||
return actual;
|
||||
}
|
||||
// peek 指定 out_len 字节(不消费);成功则返回 true 并保持 out_len 不变
|
||||
@@ -262,8 +256,7 @@ public:
|
||||
return false;
|
||||
const Size_T end = std::min(out_len, this->capacity - this->head);
|
||||
std::memcpy(out, this->buf_.data() + this->head, end);
|
||||
std::memcpy(static_cast<std::uint8_t*>(out) + end, this->buf_.data(),
|
||||
out_len - end);
|
||||
std::memcpy(static_cast<std::uint8_t*>(out) + end, this->buf_.data(), out_len - end);
|
||||
return true;
|
||||
}
|
||||
// best effort:尽可能写入,返回实际写入字节数
|
||||
|
||||
Reference in New Issue
Block a user