1
0

refactor shared

This commit is contained in:
2026-01-08 19:23:19 +08:00
parent 07cc58fb36
commit 64368b7837
23 changed files with 400 additions and 234 deletions

View File

@@ -1,13 +1,15 @@
#pragma once
#include "char_types.hpp"
#include <string>
#include <string_view>
#if defined(BASALT_OS_WINDOWS)
#include <Windows.h>
#else
// Nothing was included in POSIX
#endif
namespace Basalt::Shared {
namespace basalt::shared::pipe_operator {
class PipeOperator {
public:
@@ -20,7 +22,7 @@ namespace Basalt::Shared {
#endif
public:
PipeOperator(const std::basic_string_view<BSCHAR> name);
PipeOperator(const char_types::BSStringView& name);
~PipeOperator();
// Delete copy ctor
PipeOperator(const PipeOperator&) = delete;
@@ -29,10 +31,30 @@ namespace Basalt::Shared {
PipeOperator(PipeOperator&&) noexcept;
PipeOperator& operator=(PipeOperator&& other) noexcept;
public:
void Read(void* buffer, size_t size);
void Write(const void* buffer, size_t size);
template<typename TPod>
void ReadPod(TPod& buffer) {
Read(&buffer, sizeof(TPod));
}
template<typename TPod>
void WritePod(const TPod& buffer) {
Write(&buffer, sizeof(TPod));
}
void ReadString(std::string& buffer) {
size_t length = 0;
ReadPod(length);
buffer.resize(length);
Read(buffer.data(), length);
}
void WriteString(std::string_view& buffer) {
WritePod(buffer.size());
Write(buffer.data(), buffer.size());
}
private:
Handle m_Handle;
};
} // namespace Basalt::Shared
} // namespace basalt::shared::pipe_operator