From 2c8a03ea9982ddd809acf59b4970e75553c35d93 Mon Sep 17 00:00:00 2001 From: makeyavelly Date: Tue, 24 Jan 2023 21:36:38 +0300 Subject: [PATCH] add output operator into buffer --- core/buffer.hpp | 16 ++++++++++++++++ core/uvector.hpp | 8 +------- 2 files changed, 17 insertions(+), 7 deletions(-) diff --git a/core/buffer.hpp b/core/buffer.hpp index 361c6b57a..07949995d 100644 --- a/core/buffer.hpp +++ b/core/buffer.hpp @@ -1,5 +1,6 @@ #pragma once +#include #include #include #include @@ -141,5 +142,20 @@ namespace core { std::memcpy(data_, source, bytes); } } + + template + friend stream_t& operator<<(stream_t &stream, const buffer& buf) { + if (!buf.data_) { + stream << "{NULL_BITMASK}"; + return stream; + } + for (auto i = 0u; i < buf.size_; ++i) { + if (i > 0) { + stream << "'"; + } + stream << std::bitset<8>(*(reinterpret_cast(buf.data_) + i)); + } + return stream; + } }; } // namespace core diff --git a/core/uvector.hpp b/core/uvector.hpp index 783939a28..32424f31d 100644 --- a/core/uvector.hpp +++ b/core/uvector.hpp @@ -5,7 +5,6 @@ #include #include #include -#include #include "core/assert/assert.hpp" @@ -133,12 +132,7 @@ namespace core { template friend stream_t& operator<<(stream_t &stream, const uvector& v) { - for (auto i = 0u; i < v.storage_.size(); ++i) { - if (i > 0) { - stream << "'"; - } - stream << std::bitset<8>(*reinterpret_cast(v.storage_.data() + i)); - } + stream << v.storage_; return stream; } };