#pragma once #include "char_types.hpp" #include #include #if defined(BASALT_OS_WINDOWS) #include #else // Nothing was included in POSIX #endif namespace basalt::shared::pipe_operator { class PipeOperator { public: #if defined(BASALT_OS_WINDOWS) using Handle = HANDLE; static constexpr Handle BAD_PIPE_HANDLE = INVALID_HANDLE_VALUE; #else using Handle = int; static constexpr Handle BAD_PIPE_HANDLE = -1; #endif public: PipeOperator(const char_types::BSStringView& name); ~PipeOperator(); // Delete copy ctor PipeOperator(const PipeOperator&) = delete; PipeOperator& operator=(const PipeOperator&) = delete; // Implement move ctor 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 void read_pod(TPod& buffer) { read(&buffer, sizeof(TPod)); } template void write_pod(const TPod& buffer) { write(&buffer, sizeof(TPod)); } void read_string(std::string& buffer) { std::size_t length = 0; read_pod(length); buffer.resize(length); read(buffer.data(), length * sizeof(std::string::value_type)); } void write_string(const std::string_view& buffer) { auto length = buffer.size(); write_pod(length); write(buffer.data(), length * sizeof(std::string_view::value_type)); } void read_bsstring(char_types::BSString& buffer) { std::size_t length = 0; read_pod(length); buffer.resize(length); read(buffer.data(), length * sizeof(char_types::BSString::value_type)); } void write_bsstring(const char_types::BSStringView& buffer) { auto length = buffer.size(); write_pod(length); write(buffer.data(), length * sizeof(char_types::BSStringView::value_type)); } private: Handle m_Handle; }; } // namespace basalt::shared::pipe_operator