From 757114a3c5b748567b42f273c7b78ca039ae983c Mon Sep 17 00:00:00 2001 From: Spartan322 Date: Tue, 28 Nov 2023 05:09:26 -0500 Subject: Add `deps/dryad` -> https://github.com/Spartan322/dryad Add `deps/fmt` -> https://github.com/fmtlib/fmt Add `deps/range-v3` -> https://github.com/ericniebler/range-v3 Improve parser error and warning support Update .clang-format Update `deps/SCsub` --- .../openvic-dataloader/detail/CallbackOStream.hpp | 31 +++++++++++++--------- 1 file changed, 19 insertions(+), 12 deletions(-) (limited to 'include/openvic-dataloader/detail/CallbackOStream.hpp') diff --git a/include/openvic-dataloader/detail/CallbackOStream.hpp b/include/openvic-dataloader/detail/CallbackOStream.hpp index 641d53f..f7cfc4a 100644 --- a/include/openvic-dataloader/detail/CallbackOStream.hpp +++ b/include/openvic-dataloader/detail/CallbackOStream.hpp @@ -6,10 +6,10 @@ #include namespace ovdl::detail { - template> - class BasicCallbackStreamBuffer : public std::basic_streambuf { + template> + class BasicCallbackStreamBuffer : public std::basic_streambuf { public: - using base_type = std::basic_streambuf; + using base_type = std::basic_streambuf; using callback_type = Callback; using char_type = typename base_type::char_type; using int_type = typename base_type::int_type; @@ -29,11 +29,12 @@ namespace ovdl::detail { }; int_type overflow(int_type ch) override { + auto c = static_cast(ch); if constexpr (std::is_same_v) { - _callback(&ch, 1, _user_data); + _callback(&c, 1, _user_data); return 1; } else { - return _callback(&ch, 1, _user_data); // returns the number of characters successfully written. + return _callback(&c, 1, _user_data); // returns the number of characters successfully written. } } @@ -64,22 +65,28 @@ namespace ovdl::detail { CallbackWStreamBuffer(Callback cb, void* user_data = nullptr) : base_type(cb, user_data) {} }; - template> - class BasicCallbackStream : public std::basic_ostream { + template> + class BasicCallbackStream : public std::basic_ostream { public: - using base_type = std::basic_ostream; + using base_type = std::basic_ostream; BasicCallbackStream(Callback cb, void* user_data = nullptr) : m_sbuf(cb, user_data), - std::basic_ios(&m_sbuf), - std::basic_ostream(&m_sbuf) { - std::basic_ios::init(&m_sbuf); + std::basic_ios(&m_sbuf), + std::basic_ostream(&m_sbuf) { + std::basic_ios::init(&m_sbuf); } private: - BasicCallbackStreamBuffer m_sbuf; + BasicCallbackStreamBuffer m_sbuf; }; + template + auto make_callback_stream(auto&& cb, void* user_data = nullptr) { + using Callback = std::decay_t; + return BasicCallbackStream { std::forward(cb), user_data }; + } + template class CallbackStream : public BasicCallbackStream { public: -- cgit v1.2.3-56-ga3b1