diff options
author | yazevnul <yazevnul@yandex-team.ru> | 2022-02-10 16:46:46 +0300 |
---|---|---|
committer | Daniil Cherednik <dcherednik@yandex-team.ru> | 2022-02-10 16:46:46 +0300 |
commit | 8cbc307de0221f84c80c42dcbe07d40727537e2c (patch) | |
tree | 625d5a673015d1df891e051033e9fcde5c7be4e5 /util/stream | |
parent | 30d1ef3941e0dc835be7609de5ebee66958f215a (diff) | |
download | ydb-8cbc307de0221f84c80c42dcbe07d40727537e2c.tar.gz |
Restoring authorship annotation for <yazevnul@yandex-team.ru>. Commit 1 of 2.
Diffstat (limited to 'util/stream')
63 files changed, 810 insertions, 810 deletions
diff --git a/util/stream/aligned.cpp b/util/stream/aligned.cpp index 2fd12d15b7..2b5ec6d41b 100644 --- a/util/stream/aligned.cpp +++ b/util/stream/aligned.cpp @@ -18,7 +18,7 @@ size_t TAlignedInput::DoReadTo(TString& st, char ch) { return ret; } -ui64 TAlignedInput::DoReadAll(IOutputStream& out) { +ui64 TAlignedInput::DoReadAll(IOutputStream& out) { ui64 ret = Stream_->ReadAll(out); Position_ += ret; return ret; diff --git a/util/stream/aligned.h b/util/stream/aligned.h index 70e7be05a9..672ea25494 100644 --- a/util/stream/aligned.h +++ b/util/stream/aligned.h @@ -15,9 +15,9 @@ * Proxy input stream that provides additional functions that make reading * aligned data easier. */ -class TAlignedInput: public IInputStream { +class TAlignedInput: public IInputStream { public: - TAlignedInput(IInputStream* s) + TAlignedInput(IInputStream* s) : Stream_(s) , Position_(0) { @@ -30,7 +30,7 @@ public: * @param alignment Alignment. Must be a power of 2. */ void Align(size_t alignment = sizeof(void*)) { - Y_ASSERT(IsPowerOf2(alignment)); + Y_ASSERT(IsPowerOf2(alignment)); if (Position_ & (alignment - 1)) { size_t len = alignment - (Position_ & (alignment - 1)); @@ -45,10 +45,10 @@ private: size_t DoRead(void* ptr, size_t len) override; size_t DoSkip(size_t len) override; size_t DoReadTo(TString& st, char ch) override; - ui64 DoReadAll(IOutputStream& out) override; + ui64 DoReadAll(IOutputStream& out) override; private: - IInputStream* Stream_; + IInputStream* Stream_; ui64 Position_; }; @@ -56,9 +56,9 @@ private: * Proxy output stream that provides additional functions that make writing * aligned data easier. */ -class TAlignedOutput: public IOutputStream { +class TAlignedOutput: public IOutputStream { public: - TAlignedOutput(IOutputStream* s) + TAlignedOutput(IOutputStream* s) : Stream_(s) , Position_(0) { @@ -78,10 +78,10 @@ public: * @param alignment Alignment. Must be a power of 2. */ void Align(size_t alignment = sizeof(void*)) { - Y_ASSERT(IsPowerOf2(alignment)); + Y_ASSERT(IsPowerOf2(alignment)); static char unused[sizeof(void*) * 2]; - Y_ASSERT(alignment <= sizeof(unused)); + Y_ASSERT(alignment <= sizeof(unused)); if (Position_ & (alignment - 1)) { DoWrite(unused, alignment - (Position_ & (alignment - 1))); @@ -92,7 +92,7 @@ private: void DoWrite(const void* ptr, size_t len) override; private: - IOutputStream* Stream_; + IOutputStream* Stream_; ui64 Position_; }; diff --git a/util/stream/aligned_ut.cpp b/util/stream/aligned_ut.cpp index e980d05cf7..b8eaeea437 100644 --- a/util/stream/aligned_ut.cpp +++ b/util/stream/aligned_ut.cpp @@ -2,7 +2,7 @@ #include <library/cpp/testing/unittest/registar.h> -class TNastyInputStream: public IInputStream { +class TNastyInputStream: public IInputStream { public: TNastyInputStream() : Pos_(0) @@ -33,8 +33,8 @@ private: size_t Pos_; }; -Y_UNIT_TEST_SUITE(TAlignedTest) { - Y_UNIT_TEST(AlignInput) { +Y_UNIT_TEST_SUITE(TAlignedTest) { + Y_UNIT_TEST(AlignInput) { TNastyInputStream input0; TAlignedInput alignedInput(&input0); diff --git a/util/stream/buffer.h b/util/stream/buffer.h index 9dc99dbe49..3520be22de 100644 --- a/util/stream/buffer.h +++ b/util/stream/buffer.h @@ -58,7 +58,7 @@ private: /** * Input stream that reads from an external `TBuffer`. */ -class TBufferInput: public IZeroCopyInputFastReadTo { +class TBufferInput: public IZeroCopyInputFastReadTo { public: /** * Constructs a stream that reads from an external buffer. It's up to the diff --git a/util/stream/buffer_ut.cpp b/util/stream/buffer_ut.cpp index 3494696190..4958f3baca 100644 --- a/util/stream/buffer_ut.cpp +++ b/util/stream/buffer_ut.cpp @@ -8,8 +8,8 @@ #include "str.h" -Y_UNIT_TEST_SUITE(TBufferTest) { - Y_UNIT_TEST(Transfer) { +Y_UNIT_TEST_SUITE(TBufferTest) { + Y_UNIT_TEST(Transfer) { TBuffer buffer("razrazraz", 9); TBufferInput input(buffer); @@ -21,7 +21,7 @@ Y_UNIT_TEST_SUITE(TBufferTest) { UNIT_ASSERT_VALUES_EQUAL(output.Str(), "razraz"); } - Y_UNIT_TEST(ReadTo) { + Y_UNIT_TEST(ReadTo) { TBuffer buffer("1234567890", 10); TBufferInput input(buffer); @@ -58,7 +58,7 @@ Y_UNIT_TEST_SUITE(TBufferTest) { UNIT_ASSERT(0 == memcmp(buffer.data(), str.begin(), buffer.size())); } - Y_UNIT_TEST(Write) { + Y_UNIT_TEST(Write) { TBuffer buffer; TBufferOutput output(buffer); output << "1" @@ -75,7 +75,7 @@ Y_UNIT_TEST_SUITE(TBufferTest) { buffer.size())); } - Y_UNIT_TEST(WriteChars) { + Y_UNIT_TEST(WriteChars) { TBuffer buffer; TBufferOutput output(buffer); output << '1' << '2' << '3' << '4' << '5' << '6' << '7' << '8' << '9' << '0'; diff --git a/util/stream/buffered.cpp b/util/stream/buffered.cpp index a00e592e1c..230b743688 100644 --- a/util/stream/buffered.cpp +++ b/util/stream/buffered.cpp @@ -7,9 +7,9 @@ class TBufferedInput::TImpl: public TAdditionalStorage<TImpl> { public: - inline TImpl(IInputStream* slave) + inline TImpl(IInputStream* slave) : Slave_(slave) - , MemInput_(nullptr, 0) + , MemInput_(nullptr, 0) { } @@ -99,7 +99,7 @@ public: return ret; } - inline void Reset(IInputStream* slave) { + inline void Reset(IInputStream* slave) { Slave_ = slave; } @@ -113,11 +113,11 @@ private: } private: - IInputStream* Slave_; + IInputStream* Slave_; TMemoryInput MemInput_; }; -TBufferedInput::TBufferedInput(IInputStream* slave, size_t buflen) +TBufferedInput::TBufferedInput(IInputStream* slave, size_t buflen) : Impl_(new (buflen) TImpl(slave)) { } @@ -143,13 +143,13 @@ size_t TBufferedInput::DoReadTo(TString& st, char ch) { return Impl_->ReadTo(st, ch); } -void TBufferedInput::Reset(IInputStream* slave) { +void TBufferedInput::Reset(IInputStream* slave) { Impl_->Reset(slave); } class TBufferedOutputBase::TImpl { public: - inline TImpl(IOutputStream* slave) + inline TImpl(IOutputStream* slave) : Slave_(slave) , MemOut_(nullptr, 0) , PropagateFlush_(false) @@ -191,7 +191,7 @@ public: const size_t good_len = DownToBufferGranularity(full_len); const size_t write_from_buf = good_len - stored; - using TPart = IOutputStream::TPart; + using TPart = IOutputStream::TPart; alignas(TPart) char data[2 * sizeof(TPart)]; TPart* parts = reinterpret_cast<TPart*>(data); @@ -282,7 +282,7 @@ private: virtual size_t Len() const noexcept = 0; private: - IOutputStream* Slave_; + IOutputStream* Slave_; TMemoryOutput MemOut_; bool PropagateFlush_; bool PropagateFinish_; @@ -290,7 +290,7 @@ private: namespace { struct TSimpleImpl: public TBufferedOutputBase::TImpl, public TAdditionalStorage<TSimpleImpl> { - inline TSimpleImpl(IOutputStream* slave) + inline TSimpleImpl(IOutputStream* slave) : TBufferedOutputBase::TImpl(slave) { Reset(); @@ -315,7 +315,7 @@ namespace { Step = 4096 }; - inline TAdaptiveImpl(IOutputStream* slave) + inline TAdaptiveImpl(IOutputStream* slave) : TBufferedOutputBase::TImpl(slave) , N_(0) { @@ -346,12 +346,12 @@ namespace { }; } -TBufferedOutputBase::TBufferedOutputBase(IOutputStream* slave) +TBufferedOutputBase::TBufferedOutputBase(IOutputStream* slave) : Impl_(new TAdaptiveImpl(slave)) { } -TBufferedOutputBase::TBufferedOutputBase(IOutputStream* slave, size_t buflen) +TBufferedOutputBase::TBufferedOutputBase(IOutputStream* slave, size_t buflen) : Impl_(new (buflen) TSimpleImpl(slave)) { } @@ -413,14 +413,14 @@ void TBufferedOutputBase::SetFinishPropagateMode(bool propagate) noexcept { } } -TBufferedOutput::TBufferedOutput(IOutputStream* slave, size_t buflen) +TBufferedOutput::TBufferedOutput(IOutputStream* slave, size_t buflen) : TBufferedOutputBase(slave, buflen) { } TBufferedOutput::~TBufferedOutput() = default; -TAdaptiveBufferedOutput::TAdaptiveBufferedOutput(IOutputStream* slave) +TAdaptiveBufferedOutput::TAdaptiveBufferedOutput(IOutputStream* slave) : TBufferedOutputBase(slave) { } diff --git a/util/stream/buffered.h b/util/stream/buffered.h index 0847186141..3e57740e24 100644 --- a/util/stream/buffered.h +++ b/util/stream/buffered.h @@ -20,9 +20,9 @@ * Note that it does not claim ownership of the underlying stream, so it's up * to the user to free it. */ -class TBufferedInput: public IZeroCopyInput { +class TBufferedInput: public IZeroCopyInput { public: - TBufferedInput(IInputStream* slave, size_t buflen = 8192); + TBufferedInput(IInputStream* slave, size_t buflen = 8192); TBufferedInput(TBufferedInput&&) noexcept; TBufferedInput& operator=(TBufferedInput&&) noexcept; @@ -35,7 +35,7 @@ public: * * @param slave New underlying stream. */ - void Reset(IInputStream* slave); + void Reset(IInputStream* slave); protected: size_t DoRead(void* buf, size_t len) override; @@ -69,7 +69,7 @@ public: * * @param slave Underlying stream. */ - TBufferedOutputBase(IOutputStream* slave); + TBufferedOutputBase(IOutputStream* slave); /** * Constructs a buffered stream with the given size of the buffer. @@ -77,7 +77,7 @@ public: * @param slave Underlying stream. * @param buflen Size of the buffer. */ - TBufferedOutputBase(IOutputStream* slave, size_t buflen); + TBufferedOutputBase(IOutputStream* slave, size_t buflen); TBufferedOutputBase(TBufferedOutputBase&&) noexcept; TBufferedOutputBase& operator=(TBufferedOutputBase&&) noexcept; @@ -129,7 +129,7 @@ private: */ class TBufferedOutput: public TBufferedOutputBase { public: - TBufferedOutput(IOutputStream* slave, size_t buflen = 8192); + TBufferedOutput(IOutputStream* slave, size_t buflen = 8192); ~TBufferedOutput() override; TBufferedOutput(TBufferedOutput&&) noexcept = default; @@ -144,7 +144,7 @@ public: */ class TAdaptiveBufferedOutput: public TBufferedOutputBase { public: - TAdaptiveBufferedOutput(IOutputStream* slave); + TAdaptiveBufferedOutput(IOutputStream* slave); ~TAdaptiveBufferedOutput() override; TAdaptiveBufferedOutput(TAdaptiveBufferedOutput&&) noexcept = default; @@ -153,7 +153,7 @@ public: namespace NPrivate { struct TMyBufferedOutput: public TBufferedOutput { - inline TMyBufferedOutput(IOutputStream* slave, size_t buflen) + inline TMyBufferedOutput(IOutputStream* slave, size_t buflen) : TBufferedOutput(slave, buflen) { SetFinishPropagateMode(true); @@ -162,7 +162,7 @@ namespace NPrivate { template <class T> struct TBufferedStreamFor { - using TResult = std::conditional_t<std::is_base_of<IInputStream, T>::value, TBufferedInput, TMyBufferedOutput>; + using TResult = std::conditional_t<std::is_base_of<IInputStream, T>::value, TBufferedInput, TMyBufferedOutput>; }; } diff --git a/util/stream/buffered_ut.cpp b/util/stream/buffered_ut.cpp index 41d2fc3030..4d97247175 100644 --- a/util/stream/buffered_ut.cpp +++ b/util/stream/buffered_ut.cpp @@ -5,7 +5,7 @@ #include <util/generic/string.h> #include <util/random/mersenne.h> -Y_UNIT_TEST_SUITE(TestBufferedIO) { +Y_UNIT_TEST_SUITE(TestBufferedIO) { template <class TOut> inline void Run(TOut&& out) { TMersenne<ui64> r; @@ -22,7 +22,7 @@ Y_UNIT_TEST_SUITE(TestBufferedIO) { } } - Y_UNIT_TEST(TestEqual) { + Y_UNIT_TEST(TestEqual) { TString s1; TString s2; @@ -32,7 +32,7 @@ Y_UNIT_TEST_SUITE(TestBufferedIO) { UNIT_ASSERT_VALUES_EQUAL(s1, s2); } - Y_UNIT_TEST(Test1) { + Y_UNIT_TEST(Test1) { TString s; TBuffered<TStringOutput>(100, s).Write("1", 1); @@ -40,7 +40,7 @@ Y_UNIT_TEST_SUITE(TestBufferedIO) { UNIT_ASSERT_VALUES_EQUAL(s, "1"); } - Y_UNIT_TEST(Test2) { + Y_UNIT_TEST(Test2) { TString s; TBuffered<TStringOutput>(1, s).Write("12", 2); @@ -48,7 +48,7 @@ Y_UNIT_TEST_SUITE(TestBufferedIO) { UNIT_ASSERT_VALUES_EQUAL(s, "12"); } - Y_UNIT_TEST(Test3) { + Y_UNIT_TEST(Test3) { TString s; auto&& b = TBuffered<TStringOutput>(1, s); @@ -60,7 +60,7 @@ Y_UNIT_TEST_SUITE(TestBufferedIO) { UNIT_ASSERT_VALUES_EQUAL(s, "112"); } - Y_UNIT_TEST(Test4) { + Y_UNIT_TEST(Test4) { TString s; auto&& b = TBuffered<TStringOutput>(1, s); @@ -107,7 +107,7 @@ Y_UNIT_TEST_SUITE(TestBufferedIO) { UNIT_ASSERT_STRINGS_EQUAL(str1, str2); } - Y_UNIT_TEST(TestInput) { + Y_UNIT_TEST(TestInput) { TString s("0123456789abcdefghijklmn"); TBuffered<TStringInput> in(5, s); char c; @@ -128,7 +128,7 @@ Y_UNIT_TEST_SUITE(TestBufferedIO) { UNIT_ASSERT_VALUES_EQUAL(in.Skip(6), 3); //24 eof } - Y_UNIT_TEST(TestReadTo) { + Y_UNIT_TEST(TestReadTo) { TString s("0123456789abc"); TBuffered<TStringInput> in(2, s); TString t; diff --git a/util/stream/debug.cpp b/util/stream/debug.cpp index afd5b3e1c7..3ccb1abf38 100644 --- a/util/stream/debug.cpp +++ b/util/stream/debug.cpp @@ -31,7 +31,7 @@ namespace { } } - IOutputStream* Out; + IOutputStream* Out; int Level; }; } @@ -41,7 +41,7 @@ struct TSingletonTraits<TDbgSelector> { static constexpr size_t Priority = 8; }; -IOutputStream& StdDbgStream() noexcept { +IOutputStream& StdDbgStream() noexcept { return *(Singleton<TDbgSelector>()->Out); } diff --git a/util/stream/debug.h b/util/stream/debug.h index 92d6d4b42d..6faaf8d7c1 100644 --- a/util/stream/debug.h +++ b/util/stream/debug.h @@ -10,7 +10,7 @@ /** * Debug output stream. Writes into `stderr`. */ -class TDebugOutput: public IOutputStream { +class TDebugOutput: public IOutputStream { public: inline TDebugOutput() noexcept = default; ~TDebugOutput() override = default; @@ -26,7 +26,7 @@ private: * @returns Standard debug stream. * @see Cdbg */ -IOutputStream& StdDbgStream() noexcept; +IOutputStream& StdDbgStream() noexcept; /** * This function returns the current debug level as set via `DBGOUT` environment diff --git a/util/stream/direct_io.h b/util/stream/direct_io.h index 2e1f2e07dd..dff843b35c 100644 --- a/util/stream/direct_io.h +++ b/util/stream/direct_io.h @@ -4,7 +4,7 @@ #include "output.h" #include <util/system/direct_io.h> -class TRandomAccessFileInput: public IInputStream { +class TRandomAccessFileInput: public IInputStream { public: TRandomAccessFileInput(TDirectIOBufferedFile& file, ui64 position); @@ -17,7 +17,7 @@ private: ui64 Position; }; -class TRandomAccessFileOutput: public IOutputStream { +class TRandomAccessFileOutput: public IOutputStream { public: TRandomAccessFileOutput(TDirectIOBufferedFile& file); diff --git a/util/stream/direct_io_ut.cpp b/util/stream/direct_io_ut.cpp index 01d09db232..04784f5b0d 100644 --- a/util/stream/direct_io_ut.cpp +++ b/util/stream/direct_io_ut.cpp @@ -1,71 +1,71 @@ #include <library/cpp/testing/unittest/registar.h> #include <util/generic/string.h> -#include <util/generic/array_size.h> -#include <util/system/env.h> +#include <util/generic/array_size.h> +#include <util/system/env.h> -#include "buffered.h" -#include "direct_io.h" +#include "buffered.h" +#include "direct_io.h" -Y_UNIT_TEST_SUITE(TDirectIOTests) { +Y_UNIT_TEST_SUITE(TDirectIOTests) { // Decrease numBufToWrite further if tests continue to time out static void Y_NO_INLINE Test(EOpenMode mode, size_t numBufToWrite) { - const char TEMPLATE[] = "qwertyuiopQWERTYUIOPasdfghjklASD"; - const auto TEMPLATE_SIZE = Y_ARRAY_SIZE(TEMPLATE) - 1; - static_assert(TEMPLATE_SIZE > 0, "must be greater than zero"); - - const size_t BUFFER_SIZE = 32 * 1024; - static_assert(0 == BUFFER_SIZE % TEMPLATE_SIZE, "must be divisible"); - - const size_t CHUNK_SIZE_TO_READ = 512; - static_assert(0 == CHUNK_SIZE_TO_READ % TEMPLATE_SIZE, "must be divisible"); - - // filling buffer - // TEMPLATE|TEMPLATE|TEMPLATE|... - auto&& buffer = TBuffer{BUFFER_SIZE}; - for (size_t i = 0; i < BUFFER_SIZE / TEMPLATE_SIZE; ++i) { - buffer.Append(TEMPLATE, TEMPLATE_SIZE); - } - - // filling file - // TEMPLATE|TEMPLATE|TEMPLATE|... + const char TEMPLATE[] = "qwertyuiopQWERTYUIOPasdfghjklASD"; + const auto TEMPLATE_SIZE = Y_ARRAY_SIZE(TEMPLATE) - 1; + static_assert(TEMPLATE_SIZE > 0, "must be greater than zero"); + + const size_t BUFFER_SIZE = 32 * 1024; + static_assert(0 == BUFFER_SIZE % TEMPLATE_SIZE, "must be divisible"); + + const size_t CHUNK_SIZE_TO_READ = 512; + static_assert(0 == CHUNK_SIZE_TO_READ % TEMPLATE_SIZE, "must be divisible"); + + // filling buffer + // TEMPLATE|TEMPLATE|TEMPLATE|... + auto&& buffer = TBuffer{BUFFER_SIZE}; + for (size_t i = 0; i < BUFFER_SIZE / TEMPLATE_SIZE; ++i) { + buffer.Append(TEMPLATE, TEMPLATE_SIZE); + } + + // filling file + // TEMPLATE|TEMPLATE|TEMPLATE|... const auto fileName = TString("test.file"); - auto&& directIOBuffer = TDirectIOBufferedFile{fileName, RdWr | CreateAlways | mode}; - { - auto&& output = TRandomAccessFileOutput{directIOBuffer}; + auto&& directIOBuffer = TDirectIOBufferedFile{fileName, RdWr | CreateAlways | mode}; + { + auto&& output = TRandomAccessFileOutput{directIOBuffer}; for (size_t i = 0; i < numBufToWrite; ++i) { - output.Write(buffer.Data(), BUFFER_SIZE); - } - } - - auto&& reader = TRandomAccessFileInput{directIOBuffer, 0}; - auto&& input = TBufferedInput{&reader, 1 << 17}; - auto bytesRead = size_t{}; - while (auto len = input.Read(buffer.Data(), CHUNK_SIZE_TO_READ)) { - bytesRead += len; - while (len) { - if (len < TEMPLATE_SIZE) { - UNIT_ASSERT(!memcmp(buffer.Data(), TEMPLATE, len)); - len = 0; - } else { - UNIT_ASSERT(!memcmp(buffer.Data(), TEMPLATE, TEMPLATE_SIZE)); - len -= TEMPLATE_SIZE; - } - } - } - + output.Write(buffer.Data(), BUFFER_SIZE); + } + } + + auto&& reader = TRandomAccessFileInput{directIOBuffer, 0}; + auto&& input = TBufferedInput{&reader, 1 << 17}; + auto bytesRead = size_t{}; + while (auto len = input.Read(buffer.Data(), CHUNK_SIZE_TO_READ)) { + bytesRead += len; + while (len) { + if (len < TEMPLATE_SIZE) { + UNIT_ASSERT(!memcmp(buffer.Data(), TEMPLATE, len)); + len = 0; + } else { + UNIT_ASSERT(!memcmp(buffer.Data(), TEMPLATE, TEMPLATE_SIZE)); + len -= TEMPLATE_SIZE; + } + } + } + UNIT_ASSERT_VALUES_EQUAL(bytesRead, numBufToWrite * BUFFER_SIZE); } - Y_UNIT_TEST(ReadWriteTest) { + Y_UNIT_TEST(ReadWriteTest) { Test(0, 100 * 32); - } - - Y_UNIT_TEST(ReadWriteDirectTest) { + } + + Y_UNIT_TEST(ReadWriteDirectTest) { Test(Direct, 100 * 4); - } - - Y_UNIT_TEST(ReadWriteDirectSeqTest) { + } + + Y_UNIT_TEST(ReadWriteDirectSeqTest) { Test(Direct | Seq, 100 * 4); } } diff --git a/util/stream/file.cpp b/util/stream/file.cpp index dc5d2f6311..348a7bfced 100644 --- a/util/stream/file.cpp +++ b/util/stream/file.cpp @@ -30,7 +30,7 @@ size_t TUnbufferedFileInput::DoSkip(size_t len) { * actually doing one read is cheaper. Experiments show that the * border that separates two implementations performance-wise lies * in the range of 384-512 bytes (assuming that the file is in OS cache). */ - return IInputStream::DoSkip(len); + return IInputStream::DoSkip(len); } /* TFile::Seek can seek beyond the end of file, so we need to do @@ -81,14 +81,14 @@ public: }; TMappedFileInput::TMappedFileInput(const TFile& file) - : TMemoryInput(nullptr, 0) + : TMemoryInput(nullptr, 0) , Impl_(new TImpl(file)) { Reset(Impl_->Data(), Impl_->Size()); } TMappedFileInput::TMappedFileInput(const TString& path) - : TMemoryInput(nullptr, 0) + : TMemoryInput(nullptr, 0) , Impl_(new TImpl(TFile(path, OpenExisting | RdOnly))) { Reset(Impl_->Data(), Impl_->Size()); diff --git a/util/stream/file.h b/util/stream/file.h index c1cf4f591d..1e5217debc 100644 --- a/util/stream/file.h +++ b/util/stream/file.h @@ -1,6 +1,6 @@ #pragma once -#include "fwd.h" +#include "fwd.h" #include "input.h" #include "output.h" #include "buffered.h" diff --git a/util/stream/file_ut.cpp b/util/stream/file_ut.cpp index ac0f09796e..b39e0d56f5 100644 --- a/util/stream/file_ut.cpp +++ b/util/stream/file_ut.cpp @@ -8,8 +8,8 @@ static const char* TmpFileName = "./fileio"; static const char* TmpFileContents = "To do good to Mankind is the chivalrous plan"; static const char* TmpFileSubstring = strstr(TmpFileContents, "chivalrous"); -Y_UNIT_TEST_SUITE(TFileTest) { - Y_UNIT_TEST(InputTest) { +Y_UNIT_TEST_SUITE(TFileTest) { + Y_UNIT_TEST(InputTest) { TTempFile tmp(TmpFileName); { @@ -42,7 +42,7 @@ Y_UNIT_TEST_SUITE(TFileTest) { } } - Y_UNIT_TEST(EmptyMapTest) { + Y_UNIT_TEST(EmptyMapTest) { TTempFile tmp(TmpFileName); { diff --git a/util/stream/format.cpp b/util/stream/format.cpp index 3996130df5..25f0162552 100644 --- a/util/stream/format.cpp +++ b/util/stream/format.cpp @@ -11,7 +11,7 @@ namespace NFormatPrivate { return (value - res1 < res2 - value) ? (i64)res1 : (i64)res2; } - static inline IOutputStream& PrintDoubleShortly(IOutputStream& os, const double& d) { + static inline IOutputStream& PrintDoubleShortly(IOutputStream& os, const double& d) { // General case: request 3 significant digits // Side-effect: allows exponential representation EFloatToStringMode mode = PREC_NDIGITS; @@ -37,7 +37,7 @@ namespace NFormatPrivate { } template <> -void Out<NFormatPrivate::THumanReadableSize>(IOutputStream& stream, const NFormatPrivate::THumanReadableSize& value) { +void Out<NFormatPrivate::THumanReadableSize>(IOutputStream& stream, const NFormatPrivate::THumanReadableSize& value) { ui64 base = value.Format == SF_BYTES ? 1024 : 1000; ui64 base2 = base * base; ui64 base3 = base * base2; @@ -71,7 +71,7 @@ void Out<NFormatPrivate::THumanReadableSize>(IOutputStream& stream, const NForma } template <> -void Out<NFormatPrivate::THumanReadableDuration>(IOutputStream& os, const NFormatPrivate::THumanReadableDuration& hr) { +void Out<NFormatPrivate::THumanReadableDuration>(IOutputStream& os, const NFormatPrivate::THumanReadableDuration& hr) { TTempBuf buf; TMemoryOutput ss(buf.Data(), buf.Size()); @@ -107,7 +107,7 @@ void Out<NFormatPrivate::THumanReadableDuration>(IOutputStream& os, const NForma char names[] = {'d', 'h', 'm', 's'}; bool first = true; - for (size_t i = 0; i < Y_ARRAY_SIZE(times); ++i) { + for (size_t i = 0; i < Y_ARRAY_SIZE(times); ++i) { if (times[i] > 0) { if (!first) { ss << ' '; @@ -122,13 +122,13 @@ void Out<NFormatPrivate::THumanReadableDuration>(IOutputStream& os, const NForma os.Write(buf.Data(), written); } -void Time(IOutputStream& l) { +void Time(IOutputStream& l) { l << millisec(); } -void TimeHumanReadable(IOutputStream& l) { +void TimeHumanReadable(IOutputStream& l) { char timeStr[30]; - const time_t t = time(nullptr); + const time_t t = time(nullptr); l << ctime_r(&t, timeStr); } diff --git a/util/stream/format.h b/util/stream/format.h index b033208a1b..98e5964f7e 100644 --- a/util/stream/format.h +++ b/util/stream/format.h @@ -22,13 +22,13 @@ enum ESizeFormat { }; namespace NFormatPrivate { - template <size_t Value> + template <size_t Value> struct TLog2: std::integral_constant<size_t, TLog2<Value / 2>::value + 1> {}; - template <> + template <> struct TLog2<1>: std::integral_constant<size_t, 0> {}; - static inline void WriteChars(IOutputStream& os, char c, size_t count) { + static inline void WriteChars(IOutputStream& os, char c, size_t count) { if (count == 0) return; TTempBuf buf(count); @@ -51,7 +51,7 @@ namespace NFormatPrivate { }; template <typename T> - IOutputStream& operator<<(IOutputStream& o, const TLeftPad<T>& lp) { + IOutputStream& operator<<(IOutputStream& o, const TLeftPad<T>& lp) { TTempBuf buf; TMemoryOutput ss(buf.Data(), buf.Size()); ss << lp.Value; @@ -78,7 +78,7 @@ namespace NFormatPrivate { }; template <typename T> - IOutputStream& operator<<(IOutputStream& o, const TRightPad<T>& lp) { + IOutputStream& operator<<(IOutputStream& o, const TRightPad<T>& lp) { TTempBuf buf; TMemoryOutput ss(buf.Data(), buf.Size()); ss << lp.Value; @@ -107,7 +107,7 @@ namespace NFormatPrivate { using TUnsignedBaseNumber = TBaseNumber<std::make_unsigned_t<std::remove_cv_t<T>>, Base>; template <typename T, size_t Base> - IOutputStream& operator<<(IOutputStream& stream, const TBaseNumber<T, Base>& value) { + IOutputStream& operator<<(IOutputStream& stream, const TBaseNumber<T, Base>& value) { char buf[8 * sizeof(T) + 1]; /* Add 1 for sign. */ TStringBuf str(buf, IntToString<Base>(value.Value, buf, sizeof(buf))); @@ -143,7 +143,7 @@ namespace NFormatPrivate { }; template <typename Char, size_t Base> - IOutputStream& operator<<(IOutputStream& os, const TBaseText<Char, Base>& text) { + IOutputStream& operator<<(IOutputStream& os, const TBaseText<Char, Base>& text) { for (size_t i = 0; i < text.Text.size(); ++i) { if (i != 0) { os << ' '; @@ -164,7 +164,7 @@ namespace NFormatPrivate { }; template <typename T> - IOutputStream& operator<<(IOutputStream& o, const TFloatPrecision<T>& prec) { + IOutputStream& operator<<(IOutputStream& o, const TFloatPrecision<T>& prec) { char buf[512]; size_t count = FloatToString(prec.Value, buf, sizeof(buf), prec.Mode, prec.NDigits); o << TStringBuf(buf, count); @@ -174,7 +174,7 @@ namespace NFormatPrivate { struct THumanReadableDuration { TDuration Value; - constexpr THumanReadableDuration(const TDuration& value) + constexpr THumanReadableDuration(const TDuration& value) : Value(value) { } @@ -190,7 +190,7 @@ namespace NFormatPrivate { * Output manipulator basically equivalent to `std::setw` and `std::setfill` * combined. * - * When written into a `IOutputStream`, writes out padding characters first, + * When written into a `IOutputStream`, writes out padding characters first, * and then provided value. * * Example usage: @@ -204,7 +204,7 @@ namespace NFormatPrivate { * @see RightPad */ template <typename T> -static constexpr ::NFormatPrivate::TLeftPad<T> LeftPad(const T& value, const size_t width, const char padc = ' ') noexcept { +static constexpr ::NFormatPrivate::TLeftPad<T> LeftPad(const T& value, const size_t width, const char padc = ' ') noexcept { return ::NFormatPrivate::TLeftPad<T>(value, width, padc); } @@ -216,7 +216,7 @@ static constexpr ::NFormatPrivate::TLeftPad<const T*> LeftPad(const T (&value)[N /** * Output manipulator similar to `std::setw` and `std::setfill`. * - * When written into a `IOutputStream`, writes provided value first, and then + * When written into a `IOutputStream`, writes provided value first, and then * the padding characters. * * Example usage: @@ -230,7 +230,7 @@ static constexpr ::NFormatPrivate::TLeftPad<const T*> LeftPad(const T (&value)[N * @see LeftPad */ template <typename T> -static constexpr ::NFormatPrivate::TRightPad<T> RightPad(const T& value, const size_t width, const char padc = ' ') noexcept { +static constexpr ::NFormatPrivate::TRightPad<T> RightPad(const T& value, const size_t width, const char padc = ' ') noexcept { return ::NFormatPrivate::TRightPad<T>(value, width, padc); } @@ -242,7 +242,7 @@ static constexpr ::NFormatPrivate::TRightPad<const T*> RightPad(const T (&value) /** * Output manipulator similar to `std::setbase(16)`. * - * When written into a `IOutputStream`, writes out the provided value in + * When written into a `IOutputStream`, writes out the provided value in * hexadecimal form. The value is treated as unsigned, even if its type is in * fact signed. * @@ -263,7 +263,7 @@ static constexpr ::NFormatPrivate::TUnsignedBaseNumber<T, 16> Hex(const T& value /** * Output manipulator similar to `std::setbase(16)`. * - * When written into a `IOutputStream`, writes out the provided value in + * When written into a `IOutputStream`, writes out the provided value in * hexadecimal form. * * Example usage: @@ -283,7 +283,7 @@ static constexpr ::NFormatPrivate::TBaseNumber<T, 16> SHex(const T& value, const /** * Output manipulator similar to `std::setbase(2)`. * - * When written into a `IOutputStream`, writes out the provided value in + * When written into a `IOutputStream`, writes out the provided value in * binary form. The value is treated as unsigned, even if its type is in * fact signed. * @@ -304,7 +304,7 @@ static constexpr ::NFormatPrivate::TUnsignedBaseNumber<T, 2> Bin(const T& value, /** * Output manipulator similar to `std::setbase(2)`. * - * When written into a `IOutputStream`, writes out the provided value in + * When written into a `IOutputStream`, writes out the provided value in * binary form. * * Example usage: @@ -324,7 +324,7 @@ static constexpr ::NFormatPrivate::TBaseNumber<T, 2> SBin(const T& value, const /** * Output manipulator for hexadecimal string output. * - * When written into a `IOutputStream`, writes out the provided characters + * When written into a `IOutputStream`, writes out the provided characters * in hexadecimal form divided by space character. * * Example usage: @@ -343,7 +343,7 @@ static inline ::NFormatPrivate::TBaseText<TChar, 16> HexText(const TBasicStringB /** * Output manipulator for binary string output. * - * When written into a `IOutputStream`, writes out the provided characters + * When written into a `IOutputStream`, writes out the provided characters * in binary form divided by space character. * * Example usage: @@ -361,7 +361,7 @@ static inline ::NFormatPrivate::TBaseText<TChar, 2> BinText(const TBasicStringBu /** * Output manipulator for printing `TDuration` values. * - * When written into a `IOutputStream`, writes out the provided `TDuration` + * When written into a `IOutputStream`, writes out the provided `TDuration` * in auto-adjusted human-readable format. * * Example usage: @@ -372,7 +372,7 @@ static inline ::NFormatPrivate::TBaseText<TChar, 2> BinText(const TBasicStringBu * * @param value Value to output. */ -static constexpr ::NFormatPrivate::THumanReadableDuration HumanReadable(const TDuration duration) noexcept { +static constexpr ::NFormatPrivate::THumanReadableDuration HumanReadable(const TDuration duration) noexcept { return ::NFormatPrivate::THumanReadableDuration(duration); } @@ -380,7 +380,7 @@ static constexpr ::NFormatPrivate::THumanReadableDuration HumanReadable(const TD * Output manipulator for writing out human-readable number of elements / memory * amount in `ls -h` style. * - * When written into a `IOutputStream`, writes out the provided unsigned integer + * When written into a `IOutputStream`, writes out the provided unsigned integer * variable with small precision and a suffix (like 'K', 'M', 'G' for numbers, or * 'B', 'KiB', 'MiB', 'GiB' for bytes). * @@ -400,13 +400,13 @@ static constexpr ::NFormatPrivate::THumanReadableSize HumanReadableSize(const do return {size, format}; } -void Time(IOutputStream& l); -void TimeHumanReadable(IOutputStream& l); +void Time(IOutputStream& l); +void TimeHumanReadable(IOutputStream& l); /** * Output manipulator for adjusting precision of floating point values. * - * When written into a `IOutputStream`, writes out the provided floating point + * When written into a `IOutputStream`, writes out the provided floating point * variable with given precision. The behavior depends on provided `mode`. * * Example usage: @@ -420,14 +420,14 @@ void TimeHumanReadable(IOutputStream& l); * @see EFloatToStringMode */ template <typename T> -static constexpr ::NFormatPrivate::TFloatPrecision<T> Prec(const T& value, const EFloatToStringMode mode, const int ndigits = 0) noexcept { +static constexpr ::NFormatPrivate::TFloatPrecision<T> Prec(const T& value, const EFloatToStringMode mode, const int ndigits = 0) noexcept { return {value, mode, ndigits}; } /** * Output manipulator for adjusting precision of floating point values. * - * When written into a `IOutputStream`, writes out the provided floating point + * When written into a `IOutputStream`, writes out the provided floating point * variable with given precision. The behavior is equivalent to `Prec(value, PREC_NDIGITS, ndigits)`. * * Example usage: @@ -439,6 +439,6 @@ static constexpr ::NFormatPrivate::TFloatPrecision<T> Prec(const T& value, const * @param ndigits Number of significant digits. */ template <typename T> -static constexpr ::NFormatPrivate::TFloatPrecision<T> Prec(const T& value, const int ndigits) noexcept { +static constexpr ::NFormatPrivate::TFloatPrecision<T> Prec(const T& value, const int ndigits) noexcept { return {value, PREC_NDIGITS, ndigits}; } diff --git a/util/stream/format_ut.cpp b/util/stream/format_ut.cpp index 43245aeb48..a51d8307f9 100644 --- a/util/stream/format_ut.cpp +++ b/util/stream/format_ut.cpp @@ -3,8 +3,8 @@ #include <library/cpp/testing/unittest/registar.h> #include <util/charset/wide.h> -Y_UNIT_TEST_SUITE(TOutputStreamFormattingTest) { - Y_UNIT_TEST(TestLeftPad) { +Y_UNIT_TEST_SUITE(TOutputStreamFormattingTest) { + Y_UNIT_TEST(TestLeftPad) { TStringStream ss; ss << LeftPad(10, 4, '0'); UNIT_ASSERT_VALUES_EQUAL("0010", ss.Str()); @@ -14,7 +14,7 @@ Y_UNIT_TEST_SUITE(TOutputStreamFormattingTest) { UNIT_ASSERT_VALUES_EQUAL("222", ss.Str()); } - Y_UNIT_TEST(TestRightPad) { + Y_UNIT_TEST(TestRightPad) { TStringStream ss; ss << RightPad("aa", 4); UNIT_ASSERT_VALUES_EQUAL("aa ", ss.Str()); @@ -24,14 +24,14 @@ Y_UNIT_TEST_SUITE(TOutputStreamFormattingTest) { UNIT_ASSERT_VALUES_EQUAL("aa", ss.Str()); } - Y_UNIT_TEST(TestTime) { + Y_UNIT_TEST(TestTime) { TStringStream ss; ss << "[" << Time << "] " << "qwqw" << TimeHumanReadable << Endl; } - Y_UNIT_TEST(TestHexReference) { + Y_UNIT_TEST(TestHexReference) { /* One possible implementation of Hex() stores a reference to the given object. This can lead to wrong results if the given object is a temporary @@ -46,7 +46,7 @@ Y_UNIT_TEST_SUITE(TOutputStreamFormattingTest) { UNIT_ASSERT_VALUES_EQUAL("0x01234567", ss->Str()); } - Y_UNIT_TEST(TestHexText) { + Y_UNIT_TEST(TestHexText) { { TStringStream ss; ss << HexText(TStringBuf("abcи")); @@ -60,13 +60,13 @@ Y_UNIT_TEST_SUITE(TOutputStreamFormattingTest) { } } - Y_UNIT_TEST(TestBin) { + Y_UNIT_TEST(TestBin) { UNIT_ASSERT_VALUES_EQUAL(ToString(Bin(static_cast<ui32>(2), nullptr)), "10"); UNIT_ASSERT_VALUES_EQUAL(ToString(SBin(static_cast<i32>(-2), nullptr)), "-10"); UNIT_ASSERT_VALUES_EQUAL(ToString(SBin(static_cast<i32>(-2))), "-0b00000000000000000000000000000010"); UNIT_ASSERT_VALUES_EQUAL(ToString(SBin(static_cast<i32>(-2), HF_FULL)), "-00000000000000000000000000000010"); UNIT_ASSERT_VALUES_EQUAL(ToString(Bin(static_cast<ui32>(15), nullptr)), "1111"); - UNIT_ASSERT_VALUES_EQUAL(ToString(Bin(static_cast<ui32>(1))), "0b00000000000000000000000000000001"); + UNIT_ASSERT_VALUES_EQUAL(ToString(Bin(static_cast<ui32>(1))), "0b00000000000000000000000000000001"); UNIT_ASSERT_VALUES_EQUAL(ToString(Bin(static_cast<ui32>(-1))), "0b11111111111111111111111111111111"); UNIT_ASSERT_VALUES_EQUAL(ToString(Bin(static_cast<i32>(-1))), "0b11111111111111111111111111111111"); UNIT_ASSERT_VALUES_EQUAL(ToString(Bin(static_cast<i32>(-1), nullptr)), "11111111111111111111111111111111"); @@ -75,13 +75,13 @@ Y_UNIT_TEST_SUITE(TOutputStreamFormattingTest) { UNIT_ASSERT_VALUES_EQUAL(ToString(Bin(static_cast<ui64>(1234587912357ull))), "0b0000000000000000000000010001111101110011001011001000100010100101"); } - Y_UNIT_TEST(TestBinText) { + Y_UNIT_TEST(TestBinText) { UNIT_ASSERT_VALUES_EQUAL(ToString(BinText(TStringBuf("\1"))), "00000001"); UNIT_ASSERT_VALUES_EQUAL(ToString(BinText(TStringBuf("\1\1"))), "00000001 00000001"); UNIT_ASSERT_VALUES_EQUAL(ToString(BinText(TStringBuf("aaa"))), "01100001 01100001 01100001"); } - Y_UNIT_TEST(TestPrec) { + Y_UNIT_TEST(TestPrec) { TStringStream ss; ss << Prec(1.2345678901234567, PREC_AUTO); UNIT_ASSERT_VALUES_EQUAL("1.2345678901234567", ss.Str()); @@ -95,7 +95,7 @@ Y_UNIT_TEST_SUITE(TOutputStreamFormattingTest) { UNIT_ASSERT_VALUES_EQUAL("1.235", ss.Str()); } - Y_UNIT_TEST(TestHumanReadableSize1000) { + Y_UNIT_TEST(TestHumanReadableSize1000) { UNIT_ASSERT_VALUES_EQUAL(ToString(HumanReadableSize(0, SF_QUANTITY)), "0"); UNIT_ASSERT_VALUES_EQUAL(ToString(HumanReadableSize(1, SF_QUANTITY)), "1"); @@ -111,7 +111,7 @@ Y_UNIT_TEST_SUITE(TOutputStreamFormattingTest) { UNIT_ASSERT_VALUES_EQUAL(ToString(HumanReadableSize(-12345678 * 1000ll, SF_QUANTITY)), "-12.3G"); } - Y_UNIT_TEST(TestHumanReadableSize1024) { + Y_UNIT_TEST(TestHumanReadableSize1024) { UNIT_ASSERT_VALUES_EQUAL(ToString(HumanReadableSize(0, SF_BYTES)), "0B"); UNIT_ASSERT_VALUES_EQUAL(ToString(HumanReadableSize(100, SF_BYTES)), "100B"); @@ -161,7 +161,7 @@ Y_UNIT_TEST_SUITE(TOutputStreamFormattingTest) { UNIT_ASSERT_VALUES_EQUAL(ToString(HumanReadableSize(-1010ll * 1024 * 1024 * 1024 * 1024, SF_BYTES)), "-1010TiB"); } - Y_UNIT_TEST(TestHumanReadableDuration) { + Y_UNIT_TEST(TestHumanReadableDuration) { UNIT_ASSERT_VALUES_EQUAL(ToString(HumanReadable(TDuration::MicroSeconds(0))), "0us"); UNIT_ASSERT_VALUES_EQUAL(ToString(HumanReadable(TDuration::MicroSeconds(1))), "1us"); UNIT_ASSERT_VALUES_EQUAL(ToString(HumanReadable(TDuration::MicroSeconds(100))), "100us"); diff --git a/util/stream/fwd.cpp b/util/stream/fwd.cpp index 4214b6df83..2261ef316c 100644 --- a/util/stream/fwd.cpp +++ b/util/stream/fwd.cpp @@ -1 +1 @@ -#include "fwd.h" +#include "fwd.h" diff --git a/util/stream/fwd.h b/util/stream/fwd.h index 307676c6a7..3f0b89299b 100644 --- a/util/stream/fwd.h +++ b/util/stream/fwd.h @@ -1,100 +1,100 @@ -#pragma once - -#include <util/system/types.h> - -class IInputStream; -class IOutputStream; - -class IZeroCopyInput; -class IZeroCopyInputFastReadTo; +#pragma once + +#include <util/system/types.h> + +class IInputStream; +class IOutputStream; + +class IZeroCopyInput; +class IZeroCopyInputFastReadTo; class IZeroCopyOutput; - -using TStreamManipulator = void (*)(IOutputStream&); - -class TLengthLimitedInput; -class TCountingInput; -class TCountingOutput; - -class TMemoryInput; -class TMemoryOutput; -class TMemoryWriteBuffer; - -class TMultiInput; - -class TNullInput; -class TNullOutput; -class TNullIO; - -class TPipeBase; -class TPipeInput; -class TPipeOutput; -class TPipedBase; -class TPipedInput; -class TPipedOutput; - -class TStringInput; -class TStringOutput; -class TStringStream; - -class TTeeOutput; - + +using TStreamManipulator = void (*)(IOutputStream&); + +class TLengthLimitedInput; +class TCountingInput; +class TCountingOutput; + +class TMemoryInput; +class TMemoryOutput; +class TMemoryWriteBuffer; + +class TMultiInput; + +class TNullInput; +class TNullOutput; +class TNullIO; + +class TPipeBase; +class TPipeInput; +class TPipeOutput; +class TPipedBase; +class TPipedInput; +class TPipedOutput; + +class TStringInput; +class TStringOutput; +class TStringStream; + +class TTeeOutput; + class TTempBufOutput; - -struct TEol; - -template <typename TEndOfToken> -class TStreamTokenizer; - + +struct TEol; + +template <typename TEndOfToken> +class TStreamTokenizer; + enum ETraceLevel: ui8; - -class IWalkInput; - -struct TZLibError; -struct TZLibCompressorError; -struct TZLibDecompressorError; - -namespace ZLib { + +class IWalkInput; + +struct TZLibError; +struct TZLibCompressorError; +struct TZLibDecompressorError; + +namespace ZLib { enum StreamType: ui8; -} - +} + class TZLibDecompress; -class TZLibCompress; -class TBufferedZLibDecompress; - -using TZDecompress = TBufferedZLibDecompress; - -class TAlignedInput; -class TAlignedOutput; - -class TBufferInput; -class TBufferOutput; -class TBufferStream; - -class TBufferedInput; -class TBufferedOutputBase; -class TBufferedOutput; -class TAdaptiveBufferedOutput; - -template <class TSlave> -class TBuffered; - -template <class TSlave> -class TAdaptivelyBuffered; - -class TDebugOutput; - -class TRandomAccessFileInput; -class TRandomAccessFileOutput; -class TBufferedFileOutputEx; - -class TUnbufferedFileInput; -class TMappedFileInput; -class TUnbufferedFileOutput; - -class TFileInput; -using TIFStream = TFileInput; - -class TFixedBufferFileOutput; -using TOFStream = TFixedBufferFileOutput; - -using TFileOutput = TAdaptivelyBuffered<TUnbufferedFileOutput>; +class TZLibCompress; +class TBufferedZLibDecompress; + +using TZDecompress = TBufferedZLibDecompress; + +class TAlignedInput; +class TAlignedOutput; + +class TBufferInput; +class TBufferOutput; +class TBufferStream; + +class TBufferedInput; +class TBufferedOutputBase; +class TBufferedOutput; +class TAdaptiveBufferedOutput; + +template <class TSlave> +class TBuffered; + +template <class TSlave> +class TAdaptivelyBuffered; + +class TDebugOutput; + +class TRandomAccessFileInput; +class TRandomAccessFileOutput; +class TBufferedFileOutputEx; + +class TUnbufferedFileInput; +class TMappedFileInput; +class TUnbufferedFileOutput; + +class TFileInput; +using TIFStream = TFileInput; + +class TFixedBufferFileOutput; +using TOFStream = TFixedBufferFileOutput; + +using TFileOutput = TAdaptivelyBuffered<TUnbufferedFileOutput>; diff --git a/util/stream/hex.cpp b/util/stream/hex.cpp index 1c05330504..639a7d9370 100644 --- a/util/stream/hex.cpp +++ b/util/stream/hex.cpp @@ -3,7 +3,7 @@ #include "output.h" #include <util/string/hex.h> -void HexEncode(const void* in, size_t len, IOutputStream& out) { +void HexEncode(const void* in, size_t len, IOutputStream& out) { static const size_t NUM_OF_BYTES = 32; char buffer[NUM_OF_BYTES * 2]; @@ -15,7 +15,7 @@ void HexEncode(const void* in, size_t len, IOutputStream& out) { } } -void HexDecode(const void* in, size_t len, IOutputStream& out) { +void HexDecode(const void* in, size_t len, IOutputStream& out) { Y_ENSURE(!(len & 1), TStringBuf("Odd buffer length passed to HexDecode")); static const size_t NUM_OF_BYTES = 32; diff --git a/util/stream/hex.h b/util/stream/hex.h index a018933b1b..abe13e30ca 100644 --- a/util/stream/hex.h +++ b/util/stream/hex.h @@ -2,7 +2,7 @@ #include <util/system/types.h> -class IOutputStream; +class IOutputStream; -void HexEncode(const void* in, size_t len, IOutputStream& out); -void HexDecode(const void* in, size_t len, IOutputStream& out); +void HexEncode(const void* in, size_t len, IOutputStream& out); +void HexDecode(const void* in, size_t len, IOutputStream& out); diff --git a/util/stream/hex_ut.cpp b/util/stream/hex_ut.cpp index 5074a0b616..81c26b27c2 100644 --- a/util/stream/hex_ut.cpp +++ b/util/stream/hex_ut.cpp @@ -3,7 +3,7 @@ #include <library/cpp/testing/unittest/registar.h> #include "str.h" -Y_UNIT_TEST_SUITE(THexCodingTest) { +Y_UNIT_TEST_SUITE(THexCodingTest) { void TestImpl(const TString& data) { TString encoded; TStringOutput encodedOut(encoded); @@ -18,12 +18,12 @@ Y_UNIT_TEST_SUITE(THexCodingTest) { UNIT_ASSERT_EQUAL(decoded, data); } - Y_UNIT_TEST(TestEncodeDecodeToStream) { + Y_UNIT_TEST(TestEncodeDecodeToStream) { TString data = "100ABAcaba500,$%0987123456 \n\t\x01\x02\x03."; TestImpl(data); } - Y_UNIT_TEST(TestEmpty) { + Y_UNIT_TEST(TestEmpty) { TestImpl(""); } } diff --git a/util/stream/holder.h b/util/stream/holder.h index c60a4e510c..fabbc860b1 100644 --- a/util/stream/holder.h +++ b/util/stream/holder.h @@ -5,18 +5,18 @@ #include <utility> #include <type_traits> -class IInputStream; -class IOutputStream; +class IInputStream; +class IOutputStream; namespace NPrivate { - template <class Stream, bool isInput = std::is_base_of<IInputStream, Stream>::value> + template <class Stream, bool isInput = std::is_base_of<IInputStream, Stream>::value> struct TStreamBase { - using TType = IInputStream; + using TType = IInputStream; }; template <class Stream> struct TStreamBase<Stream, false> { - using TType = IOutputStream; + using TType = IOutputStream; }; } diff --git a/util/stream/input.cpp b/util/stream/input.cpp index 6e8170f2f9..a365b9c0d0 100644 --- a/util/stream/input.cpp +++ b/util/stream/input.cpp @@ -13,11 +13,11 @@ #include <cstdlib> -IInputStream::IInputStream() noexcept = default; +IInputStream::IInputStream() noexcept = default; -IInputStream::~IInputStream() = default; +IInputStream::~IInputStream() = default; -size_t IInputStream::DoReadTo(TString& st, char to) { +size_t IInputStream::DoReadTo(TString& st, char to) { char ch; if (!Read(&ch, 1)) { @@ -40,7 +40,7 @@ size_t IInputStream::DoReadTo(TString& st, char to) { return result; } -ui64 IInputStream::DoReadAll(IOutputStream& out) { +ui64 IInputStream::DoReadAll(IOutputStream& out) { TTempBuf buffer; void* ptr = buffer.Data(); size_t size = buffer.Size(); @@ -54,7 +54,7 @@ ui64 IInputStream::DoReadAll(IOutputStream& out) { return result; } -size_t IInputStream::Load(void* buf_in, size_t len) { +size_t IInputStream::Load(void* buf_in, size_t len) { char* buf = (char*)buf_in; while (len) { @@ -71,14 +71,14 @@ size_t IInputStream::Load(void* buf_in, size_t len) { return buf - (char*)buf_in; } -void IInputStream::LoadOrFail(void* buf, size_t len) { +void IInputStream::LoadOrFail(void* buf, size_t len) { const size_t realLen = Load(buf, len); - if (Y_UNLIKELY(realLen != len)) { + if (Y_UNLIKELY(realLen != len)) { ythrow yexception() << "Failed to read required number of bytes from stream! Expected: " << len << ", gained: " << realLen << "!"; } } -size_t IInputStream::ReadLine(TString& st) { +size_t IInputStream::ReadLine(TString& st) { const size_t ret = ReadTo(st, '\n'); if (ret && !st.empty() && st.back() == '\r') { @@ -88,7 +88,7 @@ size_t IInputStream::ReadLine(TString& st) { return ret; } -size_t IInputStream::ReadLine(TUtf16String& w) { +size_t IInputStream::ReadLine(TUtf16String& w) { TString s; size_t result = ReadLine(s); @@ -99,7 +99,7 @@ size_t IInputStream::ReadLine(TUtf16String& w) { return result; } -TString IInputStream::ReadLine() { +TString IInputStream::ReadLine() { TString ret; if (!ReadLine(ret)) { @@ -109,7 +109,7 @@ TString IInputStream::ReadLine() { return ret; } -TString IInputStream::ReadTo(char ch) { +TString IInputStream::ReadTo(char ch) { TString ret; if (!ReadTo(ret, ch)) { @@ -119,11 +119,11 @@ TString IInputStream::ReadTo(char ch) { return ret; } -size_t IInputStream::Skip(size_t sz) { +size_t IInputStream::Skip(size_t sz) { return DoSkip(sz); } -size_t IInputStream::DoSkip(size_t sz) { +size_t IInputStream::DoSkip(size_t sz) { if (sz < 128) { return Load(alloca(sz), sz); } @@ -145,7 +145,7 @@ size_t IInputStream::DoSkip(size_t sz) { return total; } -TString IInputStream::ReadAll() { +TString IInputStream::ReadAll() { TString result; TStringOutput stream(result); @@ -154,16 +154,16 @@ TString IInputStream::ReadAll() { return result; } -ui64 IInputStream::ReadAll(IOutputStream& out) { +ui64 IInputStream::ReadAll(IOutputStream& out) { return DoReadAll(out); } -ui64 TransferData(IInputStream* in, IOutputStream* out) { +ui64 TransferData(IInputStream* in, IOutputStream* out) { return in->ReadAll(*out); } namespace { - struct TStdIn: public IInputStream { + struct TStdIn: public IInputStream { ~TStdIn() override = default; size_t DoRead(void* buf, size_t len) override { @@ -250,7 +250,7 @@ namespace { #endif } -IInputStream& NPrivate::StdInStream() noexcept { +IInputStream& NPrivate::StdInStream() noexcept { return *SingletonWithPriority<TGetLine, 4>(); } @@ -262,7 +262,7 @@ static inline bool IsStdDelimiter(char c) { return (c == '\0') || (c == ' ') || (c == '\r') || (c == '\n') || (c == '\t'); } -static void ReadUpToDelimiter(IInputStream& i, TString& s) { +static void ReadUpToDelimiter(IInputStream& i, TString& s) { char c; while (i.ReadChar(c)) { // skip delimiters if (!IsStdDelimiter(c)) { @@ -278,13 +278,13 @@ static void ReadUpToDelimiter(IInputStream& i, TString& s) { // specialization for string-related stuff template <> -void In<TString>(IInputStream& i, TString& s) { +void In<TString>(IInputStream& i, TString& s) { s.resize(0); ReadUpToDelimiter(i, s); } template <> -void In<TUtf16String>(IInputStream& i, TUtf16String& w) { +void In<TUtf16String>(IInputStream& i, TUtf16String& w) { TString s; ReadUpToDelimiter(i, s); @@ -299,7 +299,7 @@ void In<TUtf16String>(IInputStream& i, TUtf16String& w) { #define SPEC_FOR_CHAR(T) \ template <> \ - void In<T>(IInputStream & i, T & t) { \ + void In<T>(IInputStream & i, T & t) { \ i.ReadChar((char&)t); \ } @@ -313,7 +313,7 @@ SPEC_FOR_CHAR(signed char) #define SPEC_FOR_NUMBER(T) \ template <> \ - void In<T>(IInputStream & i, T & t) { \ + void In<T>(IInputStream & i, T & t) { \ char buf[128]; \ size_t pos = 0; \ while (i.ReadChar(buf[0])) { \ diff --git a/util/stream/input.h b/util/stream/input.h index f0d5807ed2..4858660457 100644 --- a/util/stream/input.h +++ b/util/stream/input.h @@ -4,7 +4,7 @@ #include <util/generic/noncopyable.h> #include <util/system/defaults.h> -class IOutputStream; +class IOutputStream; /** * @addtogroup Streams_Base @@ -14,15 +14,15 @@ class IOutputStream; /** * Abstract input stream. */ -class IInputStream: public TNonCopyable { +class IInputStream: public TNonCopyable { public: - IInputStream() noexcept; - virtual ~IInputStream(); + IInputStream() noexcept; + virtual ~IInputStream(); - IInputStream(IInputStream&&) noexcept { + IInputStream(IInputStream&&) noexcept { } - IInputStream& operator=(IInputStream&&) noexcept { + IInputStream& operator=(IInputStream&&) noexcept { return *this; } @@ -107,7 +107,7 @@ public: * @param out Output stream to use. * @returns Total number of characters read from the stream. */ - ui64 ReadAll(IOutputStream& out); + ui64 ReadAll(IOutputStream& out); /** * Reads all data from the stream until the first occurrence of '\n'. Also @@ -215,7 +215,7 @@ protected: * this stream. * @throws yexception If IO error occurs. */ - virtual ui64 DoReadAll(IOutputStream& out); + virtual ui64 DoReadAll(IOutputStream& out); }; /** @@ -224,10 +224,10 @@ protected: * @param in Input stream. * @param out Output stream. */ -ui64 TransferData(IInputStream* in, IOutputStream* out); +ui64 TransferData(IInputStream* in, IOutputStream* out); /** - * `operator>>` for `IInputStream` by default delegates to this function. + * `operator>>` for `IInputStream` by default delegates to this function. * * Note that while `operator>>` uses overloading (and thus argument-dependent * lookup), `In` uses template specializations. This makes it possible to @@ -241,10 +241,10 @@ ui64 TransferData(IInputStream* in, IOutputStream* out); * @param in Input stream to read from. * @param[out] value Value to read. * @throws `yexception` on invalid input or end of stream. - * @see Out(IOutputStream&, T&) + * @see Out(IOutputStream&, T&) */ template <typename T> -void In(IInputStream& in, T& value); +void In(IInputStream& in, T& value); /** * Reads a value from the stream. @@ -253,16 +253,16 @@ void In(IInputStream& in, T& value); * @param[out] value Value to read. * @returns Input stream. * @throws `yexception` on invalid input or end of stream. - * @see operator<<(IOutputStream&, T&) + * @see operator<<(IOutputStream&, T&) */ template <typename T> -inline IInputStream& operator>>(IInputStream& in, T& value) { +inline IInputStream& operator>>(IInputStream& in, T& value) { In<T>(in, value); return in; } namespace NPrivate { - IInputStream& StdInStream() noexcept; + IInputStream& StdInStream() noexcept; } /** diff --git a/util/stream/input_ut.cpp b/util/stream/input_ut.cpp index 4a93f5458e..63e2d08c88 100644 --- a/util/stream/input_ut.cpp +++ b/util/stream/input_ut.cpp @@ -21,7 +21,7 @@ public: } template <typename FuncType> - void ForInput(const TStringBuf text, const FuncType& func) { + void ForInput(const TStringBuf text, const FuncType& func) { TFile tempFile(TFile::Temporary("input_ut")); tempFile.Write(text.data(), text.size()); tempFile.FlushData(); @@ -41,7 +41,7 @@ private: int StdInCopy_; }; -class TNoInput: public IInputStream { +class TNoInput: public IInputStream { public: TNoInput(ui64 size) : Size_(size) @@ -59,7 +59,7 @@ private: ui64 Size_; }; -class TNoOutput: public IOutputStream { +class TNoOutput: public IOutputStream { public: TNoOutput() = default; @@ -68,7 +68,7 @@ protected: } }; -class TSimpleStringInput: public IInputStream { +class TSimpleStringInput: public IInputStream { public: TSimpleStringInput(const TString& string) : String_(string) @@ -77,7 +77,7 @@ public: protected: size_t DoRead(void* buf, size_t len) override { - Y_ASSERT(len != 0); + Y_ASSERT(len != 0); if (String_.empty()) { return 0; @@ -92,8 +92,8 @@ private: TString String_; }; -Y_UNIT_TEST_SUITE(TInputTest) { - Y_UNIT_TEST(BigTransfer) { +Y_UNIT_TEST_SUITE(TInputTest) { + Y_UNIT_TEST(BigTransfer) { ui64 size = 1024ull * 1024ull * 1024ull * 5; TNoInput input(size); TNoOutput output; @@ -103,7 +103,7 @@ Y_UNIT_TEST_SUITE(TInputTest) { UNIT_ASSERT_VALUES_EQUAL(transferred, size); } - Y_UNIT_TEST(TestReadTo) { + Y_UNIT_TEST(TestReadTo) { /* This one tests default implementation of ReadTo. */ TSimpleStringInput in("0123456789abc"); @@ -117,7 +117,7 @@ Y_UNIT_TEST_SUITE(TInputTest) { UNIT_ASSERT_VALUES_EQUAL(t, "89abc"); } - Y_UNIT_TEST(TestReadLine) { + Y_UNIT_TEST(TestReadLine) { TSimpleStringInput in("1\n22\n333"); TString t; @@ -131,7 +131,7 @@ Y_UNIT_TEST_SUITE(TInputTest) { UNIT_ASSERT_VALUES_EQUAL(t, "333"); } - Y_UNIT_TEST(TestStdInReadTo) { + Y_UNIT_TEST(TestStdInReadTo) { std::pair<std::pair<TStringBuf, char>, TStringBuf> testPairs[] = { {{"", '\n'}, ""}, {{"\n", '\n'}, ""}, diff --git a/util/stream/ios_ut.cpp b/util/stream/ios_ut.cpp index 139f4296e5..30ae17cdf4 100644 --- a/util/stream/ios_ut.cpp +++ b/util/stream/ios_ut.cpp @@ -1,7 +1,7 @@ -#include "output.h" +#include "output.h" #include "tokenizer.h" -#include "buffer.h" -#include "buffered.h" +#include "buffer.h" +#include "buffered.h" #include "walk.h" #include <library/cpp/testing/unittest/registar.h> @@ -169,7 +169,7 @@ void TStreamsTest::TestMemoryStream() { } } -class TMyStringOutput: public IOutputStream { +class TMyStringOutput: public IOutputStream { public: inline TMyStringOutput(TString& s, size_t buflen) noexcept : S_(s) @@ -279,7 +279,7 @@ void TStreamsTest::TestBufferStream() { } namespace { - class TStringListInput: public IWalkInput { + class TStringListInput: public IWalkInput { public: TStringListInput(const TVector<TString>& data) : Data_(data) @@ -331,7 +331,7 @@ namespace { "\rone two", "123", "\t\r "}; - void TestStreamReadTo1(IInputStream& input, const char* comment) { + void TestStreamReadTo1(IInputStream& input, const char* comment) { TString tmp; input.ReadTo(tmp, 'c'); UNIT_ASSERT_VALUES_EQUAL_C(tmp, "111a222b333", comment); @@ -347,7 +347,7 @@ namespace { UNIT_ASSERT_VALUES_EQUAL_C(tmp, "66f", comment); } - void TestStreamReadTo2(IInputStream& input, const char* comment) { + void TestStreamReadTo2(IInputStream& input, const char* comment) { TString s; size_t i = 0; while (input.ReadLine(s)) { @@ -357,17 +357,17 @@ namespace { } } - void TestStreamReadTo3(IInputStream& input, const char* comment) { + void TestStreamReadTo3(IInputStream& input, const char* comment) { UNIT_ASSERT_VALUES_EQUAL_C(input.ReadLine(), "111a222b333c444d555e666f", comment); } - void TestStreamReadTo4(IInputStream& input, const char* comment) { + void TestStreamReadTo4(IInputStream& input, const char* comment) { UNIT_ASSERT_VALUES_EQUAL_C(input.ReadTo('\0'), "one", comment); UNIT_ASSERT_VALUES_EQUAL_C(input.ReadTo('\0'), "two", comment); UNIT_ASSERT_VALUES_EQUAL_C(input.ReadTo('\0'), "three", comment); } - void TestStrokaInput(IInputStream& input, const char* comment) { + void TestStrokaInput(IInputStream& input, const char* comment) { TString line; ui32 i = 0; TInstant start = Now(); @@ -392,7 +392,7 @@ namespace { test(bdi, "TBufferedInput"); TVector<TString> lst(1, text); TStringListInput sli(lst); - test(sli, "IWalkInput"); + test(sli, "IWalkInput"); } } @@ -422,7 +422,7 @@ void TStreamsTest::TestWtrokaInput() { size_t i = 0; while (is.ReadLine(w)) { - UNIT_ASSERT(i < Y_ARRAY_SIZE(Expected)); + UNIT_ASSERT(i < Y_ARRAY_SIZE(Expected)); UNIT_ASSERT_VALUES_EQUAL(w, UTF8ToWide(Expected[i])); ++i; diff --git a/util/stream/labeled.h b/util/stream/labeled.h index 2cc539d241..cd0017b00f 100644 --- a/util/stream/labeled.h +++ b/util/stream/labeled.h @@ -13,7 +13,7 @@ * // Outputs "a = 1, b = 2, c = 3, a + b + c = 6" * @endcode */ -#define LabeledOutput(...) "" Y_PASS_VA_ARGS(Y_MAP_ARGS_WITH_LAST(__LABELED_OUTPUT_NONLAST__, __LABELED_OUTPUT_IMPL__, __VA_ARGS__)) +#define LabeledOutput(...) "" Y_PASS_VA_ARGS(Y_MAP_ARGS_WITH_LAST(__LABELED_OUTPUT_NONLAST__, __LABELED_OUTPUT_IMPL__, __VA_ARGS__)) #define __LABELED_OUTPUT_IMPL__(x) << #x " = " << (x) #define __LABELED_OUTPUT_NONLAST__(x) __LABELED_OUTPUT_IMPL__(x) << ", " diff --git a/util/stream/labeled_ut.cpp b/util/stream/labeled_ut.cpp index 12d0dc5004..f30fdebe8b 100644 --- a/util/stream/labeled_ut.cpp +++ b/util/stream/labeled_ut.cpp @@ -2,8 +2,8 @@ #include <library/cpp/testing/unittest/registar.h> -Y_UNIT_TEST_SUITE(TLabeledOutputTest) { - Y_UNIT_TEST(TBasicTest) { +Y_UNIT_TEST_SUITE(TLabeledOutputTest) { + Y_UNIT_TEST(TBasicTest) { TStringStream out; int x = 3; out << LabeledOutput(x, 1, 2, 3 + 4); diff --git a/util/stream/length.cpp b/util/stream/length.cpp index 9907fe2ac9..04dfcedb49 100644 --- a/util/stream/length.cpp +++ b/util/stream/length.cpp @@ -34,7 +34,7 @@ size_t TCountingInput::DoReadTo(TString& st, char ch) { return ret; } -ui64 TCountingInput::DoReadAll(IOutputStream& out) { +ui64 TCountingInput::DoReadAll(IOutputStream& out) { const ui64 ret = Slave_->ReadAll(out); Count_ += ret; return ret; diff --git a/util/stream/length.h b/util/stream/length.h index 4d508ae24d..79eb59e2e0 100644 --- a/util/stream/length.h +++ b/util/stream/length.h @@ -12,9 +12,9 @@ * This can be useful for breaking up the slave stream into small chunks and * treat these as separate streams. */ -class TLengthLimitedInput: public IInputStream { +class TLengthLimitedInput: public IInputStream { public: - inline TLengthLimitedInput(IInputStream* slave, ui64 length) noexcept + inline TLengthLimitedInput(IInputStream* slave, ui64 length) noexcept : Slave_(slave) , Length_(length) { @@ -31,16 +31,16 @@ private: size_t DoSkip(size_t len) override; private: - IInputStream* Slave_; + IInputStream* Slave_; ui64 Length_; }; /** * Proxy input stream that counts the number of characters read. */ -class TCountingInput: public IInputStream { +class TCountingInput: public IInputStream { public: - inline TCountingInput(IInputStream* slave) noexcept + inline TCountingInput(IInputStream* slave) noexcept : Slave_(slave) , Count_() { @@ -60,19 +60,19 @@ private: size_t DoRead(void* buf, size_t len) override; size_t DoSkip(size_t len) override; size_t DoReadTo(TString& st, char ch) override; - ui64 DoReadAll(IOutputStream& out) override; + ui64 DoReadAll(IOutputStream& out) override; private: - IInputStream* Slave_; + IInputStream* Slave_; ui64 Count_; }; /** * Proxy output stream that counts the number of characters written. */ -class TCountingOutput: public IOutputStream { +class TCountingOutput: public IOutputStream { public: - inline TCountingOutput(IOutputStream* slave) noexcept + inline TCountingOutput(IOutputStream* slave) noexcept : Slave_(slave) , Count_() { @@ -95,6 +95,6 @@ private: void DoWrite(const void* buf, size_t len) override; private: - IOutputStream* Slave_; + IOutputStream* Slave_; ui64 Count_; }; diff --git a/util/stream/length_ut.cpp b/util/stream/length_ut.cpp index 8968448954..9cc4621624 100644 --- a/util/stream/length_ut.cpp +++ b/util/stream/length_ut.cpp @@ -4,8 +4,8 @@ #include <util/generic/string.h> -Y_UNIT_TEST_SUITE(TestLengthIO) { - Y_UNIT_TEST(TestLengthLimitedInput) { +Y_UNIT_TEST_SUITE(TestLengthIO) { + Y_UNIT_TEST(TestLengthLimitedInput) { char buf[16]; TStringStream s1("abcd"); @@ -14,7 +14,7 @@ Y_UNIT_TEST_SUITE(TestLengthIO) { UNIT_ASSERT_VALUES_EQUAL(l1.Read(buf, 1), 0); } - Y_UNIT_TEST(TestCountingInput) { + Y_UNIT_TEST(TestCountingInput) { char buf[16]; TStringStream s1("abc\ndef\n"); @@ -34,7 +34,7 @@ Y_UNIT_TEST_SUITE(TestLengthIO) { UNIT_ASSERT_VALUES_EQUAL(l1.Counter(), 8); } - Y_UNIT_TEST(TestCountingOutput) { + Y_UNIT_TEST(TestCountingOutput) { TStringStream s1; TCountingOutput l1(&s1); diff --git a/util/stream/mem.cpp b/util/stream/mem.cpp index 22a3339e27..c352eb3894 100644 --- a/util/stream/mem.cpp +++ b/util/stream/mem.cpp @@ -14,7 +14,7 @@ TMemoryInput::TMemoryInput(const void* buf, size_t len) noexcept { } -TMemoryInput::TMemoryInput(const TStringBuf buf) noexcept +TMemoryInput::TMemoryInput(const TStringBuf buf) noexcept : Buf_(buf.data()) , Len_(buf.size()) { diff --git a/util/stream/mem.h b/util/stream/mem.h index 18a5d46772..bde672528d 100644 --- a/util/stream/mem.h +++ b/util/stream/mem.h @@ -13,7 +13,7 @@ /** * Input stream that reads data from a memory block. */ -class TMemoryInput: public IZeroCopyInputFastReadTo { +class TMemoryInput: public IZeroCopyInputFastReadTo { public: TMemoryInput() noexcept; @@ -26,11 +26,11 @@ public: * @param len Size of the memory block. */ TMemoryInput(const void* buf, size_t len) noexcept; - explicit TMemoryInput(const TStringBuf buf) noexcept; + explicit TMemoryInput(const TStringBuf buf) noexcept; ~TMemoryInput() override; TMemoryInput(const TMemoryInput& other) noexcept - : IZeroCopyInputFastReadTo() + : IZeroCopyInputFastReadTo() , Buf_(other.Buf_) , Len_(other.Len_) { @@ -89,10 +89,10 @@ public: * * @param stream Zero copy stream to initialize from. */ - void Fill(IZeroCopyInput* stream) { + void Fill(IZeroCopyInput* stream) { Len_ = stream->Next(&Buf_); if (!Len_) { - Reset(nullptr, 0); + Reset(nullptr, 0); } } @@ -229,7 +229,7 @@ public: * this stream uses. */ void SetPos(char* ptr) { - Y_ASSERT(Beg_ <= ptr); + Y_ASSERT(Beg_ <= ptr); SetPosImpl(ptr); } @@ -244,7 +244,7 @@ public: protected: void SetPosImpl(char* ptr) { - Y_ASSERT(End_ >= ptr); + Y_ASSERT(End_ >= ptr); Buf_ = ptr; } diff --git a/util/stream/mem_ut.cpp b/util/stream/mem_ut.cpp index f388ae66ac..cd8c047435 100644 --- a/util/stream/mem_ut.cpp +++ b/util/stream/mem_ut.cpp @@ -2,8 +2,8 @@ #include <library/cpp/testing/unittest/registar.h> -Y_UNIT_TEST_SUITE(TestMemIO) { - Y_UNIT_TEST(TestReadTo) { +Y_UNIT_TEST_SUITE(TestMemIO) { + Y_UNIT_TEST(TestReadTo) { TString s("0123456789abc"); TMemoryInput in(s); @@ -50,7 +50,7 @@ Y_UNIT_TEST_SUITE(TestMemIO) { UNIT_ASSERT(0 == memcmp(buffer, result, strlen(result))); } - Y_UNIT_TEST(Write) { + Y_UNIT_TEST(Write) { char buffer[20]; TMemoryOutput output(buffer, sizeof(buffer)); output << "1" @@ -67,7 +67,7 @@ Y_UNIT_TEST_SUITE(TestMemIO) { UNIT_ASSERT(0 == memcmp(buffer, result, strlen(result))); } - Y_UNIT_TEST(WriteChars) { + Y_UNIT_TEST(WriteChars) { char buffer[20]; TMemoryOutput output(buffer, sizeof(buffer)); output << '1' << '2' << '3' << '4' << '5' << '6' << '7' << '8' << '9' << '0'; diff --git a/util/stream/multi.cpp b/util/stream/multi.cpp index b2354298a0..5866bad44a 100644 --- a/util/stream/multi.cpp +++ b/util/stream/multi.cpp @@ -1,7 +1,7 @@ #include "null.h" #include "multi.h" -TMultiInput::TMultiInput(IInputStream* f, IInputStream* s) noexcept +TMultiInput::TMultiInput(IInputStream* f, IInputStream* s) noexcept : C_(f) , N_(s) { diff --git a/util/stream/multi.h b/util/stream/multi.h index 8bfd462d99..aad061f23c 100644 --- a/util/stream/multi.h +++ b/util/stream/multi.h @@ -10,9 +10,9 @@ /** * A proxy input stream that concatenates two slave streams into one. */ -class TMultiInput: public IInputStream { +class TMultiInput: public IInputStream { public: - TMultiInput(IInputStream* f, IInputStream* s) noexcept; + TMultiInput(IInputStream* f, IInputStream* s) noexcept; ~TMultiInput() override; private: @@ -21,8 +21,8 @@ private: size_t DoReadTo(TString& st, char ch) override; private: - IInputStream* C_; - IInputStream* N_; + IInputStream* C_; + IInputStream* N_; }; /** diff --git a/util/stream/multi_ut.cpp b/util/stream/multi_ut.cpp index fc2553b533..2f16772196 100644 --- a/util/stream/multi_ut.cpp +++ b/util/stream/multi_ut.cpp @@ -3,12 +3,12 @@ #include "str.h" #include <library/cpp/testing/unittest/registar.h> -Y_UNIT_TEST_SUITE(TestMultiInput) { +Y_UNIT_TEST_SUITE(TestMultiInput) { struct TTestCase { TMemoryInput Input1; TMemoryInput Input2; TMultiInput MultiInput; - TTestCase(const TStringBuf in1, const TStringBuf in2) + TTestCase(const TStringBuf in1, const TStringBuf in2) : Input1(in1) , Input2(in2) , MultiInput(&Input1, &Input2) @@ -23,7 +23,7 @@ Y_UNIT_TEST_SUITE(TestMultiInput) { } }; - Y_UNIT_TEST(TestReadTo) { + Y_UNIT_TEST(TestReadTo) { TString t; TTestCase simpleCase("0123456789abc", "defghijk"); @@ -32,7 +32,7 @@ Y_UNIT_TEST_SUITE(TestMultiInput) { simpleCase.TestReadToResult('z', 5, "ghijk"); } - Y_UNIT_TEST(TestReadToBetweenStreams) { + Y_UNIT_TEST(TestReadToBetweenStreams) { TTestCase case1("0123456789abc", "defghijk"); case1.TestReadToResult('c', 13, "0123456789ab"); case1.TestReadToResult('k', 8, "defghij"); diff --git a/util/stream/null.h b/util/stream/null.h index 8c335a9a78..a87df475bc 100644 --- a/util/stream/null.h +++ b/util/stream/null.h @@ -11,7 +11,7 @@ /** * Null input stream. Does nothing, contains no data. */ -class TNullInput: public IZeroCopyInput { +class TNullInput: public IZeroCopyInput { public: TNullInput() noexcept; ~TNullInput() override; @@ -25,7 +25,7 @@ private: /** * Null output stream. Just ignores whatever is written into it. */ -class TNullOutput: public IOutputStream { +class TNullOutput: public IOutputStream { public: TNullOutput() noexcept; ~TNullOutput() override; diff --git a/util/stream/output.cpp b/util/stream/output.cpp index db81b81b70..a71f46ac48 100644 --- a/util/stream/output.cpp +++ b/util/stream/output.cpp @@ -20,27 +20,27 @@ #include <string_view> #include <cstdio> -#if defined(_win_) +#if defined(_win_) #include <io.h> -#endif +#endif constexpr size_t MAX_UTF8_BYTES = 4; // UTF-8-encoded code point takes between 1 and 4 bytes -IOutputStream::IOutputStream() noexcept = default; +IOutputStream::IOutputStream() noexcept = default; -IOutputStream::~IOutputStream() = default; +IOutputStream::~IOutputStream() = default; -void IOutputStream::DoFlush() { +void IOutputStream::DoFlush() { /* * do nothing */ } -void IOutputStream::DoFinish() { +void IOutputStream::DoFinish() { Flush(); } -void IOutputStream::DoWriteV(const TPart* parts, size_t count) { +void IOutputStream::DoWriteV(const TPart* parts, size_t count) { for (size_t i = 0; i < count; ++i) { const TPart& part = parts[i]; @@ -69,7 +69,7 @@ void Out<wchar32>(IOutputStream& o, wchar32 ch) { o.Write(buffer, length); } -static void WriteString(IOutputStream& o, const wchar16* w, size_t n) { +static void WriteString(IOutputStream& o, const wchar16* w, size_t n) { const size_t buflen = (n * MAX_UTF8_BYTES); // * 4 because the conversion functions can convert unicode character into maximum 4 bytes of UTF8 TTempBuf buffer(buflen + 1); char* const data = buffer.Data(); @@ -90,12 +90,12 @@ static void WriteString(IOutputStream& o, const wchar32* w, size_t n) { } template <> -void Out<TString>(IOutputStream& o, const TString& p) { +void Out<TString>(IOutputStream& o, const TString& p) { o.Write(p.data(), p.size()); } template <> -void Out<std::string>(IOutputStream& o, const std::string& p) { +void Out<std::string>(IOutputStream& o, const std::string& p) { o.Write(p.data(), p.length()); } @@ -130,7 +130,7 @@ void Out<TUtf32StringBuf>(IOutputStream& o, const TUtf32StringBuf& p) { } template <> -void Out<const wchar16*>(IOutputStream& o, const wchar16* w) { +void Out<const wchar16*>(IOutputStream& o, const wchar16* w) { if (w) { WriteString(o, w, std::char_traits<wchar16>::length(w)); } else { @@ -148,7 +148,7 @@ void Out<const wchar32*>(IOutputStream& o, const wchar32* w) { } template <> -void Out<TUtf16String>(IOutputStream& o, const TUtf16String& w) { +void Out<TUtf16String>(IOutputStream& o, const TUtf16String& w) { WriteString(o, w.c_str(), w.size()); } @@ -159,19 +159,19 @@ void Out<TUtf32String>(IOutputStream& o, const TUtf32String& w) { #define DEF_CONV_DEFAULT(type) \ template <> \ - void Out<type>(IOutputStream & o, type p) { \ + void Out<type>(IOutputStream & o, type p) { \ o << ToString(p); \ } #define DEF_CONV_CHR(type) \ template <> \ - void Out<type>(IOutputStream & o, type p) { \ + void Out<type>(IOutputStream & o, type p) { \ o.Write((char)p); \ } #define DEF_CONV_NUM(type, len) \ template <> \ - void Out<type>(IOutputStream & o, type p) { \ + void Out<type>(IOutputStream & o, type p) { \ char buf[len]; \ o.Write(buf, ToString(p, buf, sizeof(buf))); \ } \ @@ -211,12 +211,12 @@ void Out<typename std::vector<bool>::reference>(IOutputStream& o, const std::vec #ifndef TSTRING_IS_STD_STRING template <> -void Out<TBasicCharRef<TString>>(IOutputStream& o, const TBasicCharRef<TString>& c) { +void Out<TBasicCharRef<TString>>(IOutputStream& o, const TBasicCharRef<TString>& c) { o << static_cast<char>(c); } template <> -void Out<TBasicCharRef<TUtf16String>>(IOutputStream& o, const TBasicCharRef<TUtf16String>& c) { +void Out<TBasicCharRef<TUtf16String>>(IOutputStream& o, const TBasicCharRef<TUtf16String>& c) { o << static_cast<wchar16>(c); } @@ -227,19 +227,19 @@ void Out<TBasicCharRef<TUtf32String>>(IOutputStream& o, const TBasicCharRef<TUtf #endif template <> -void Out<const void*>(IOutputStream& o, const void* t) { +void Out<const void*>(IOutputStream& o, const void* t) { o << Hex(size_t(t)); } template <> -void Out<void*>(IOutputStream& o, void* t) { +void Out<void*>(IOutputStream& o, void* t) { Out<const void*>(o, t); } using TNullPtr = decltype(nullptr); template <> -void Out<TNullPtr>(IOutputStream& o, TTypeTraits<TNullPtr>::TFuncParam) { +void Out<TNullPtr>(IOutputStream& o, TTypeTraits<TNullPtr>::TFuncParam) { o << TStringBuf("nullptr"); } @@ -258,7 +258,7 @@ namespace { public: using TLogFuncPtr = void (*)(int, const char*, const char*); - class TAndroidStdOutput: public IOutputStream { + class TAndroidStdOutput: public IOutputStream { public: inline TAndroidStdOutput(TLogFuncPtr logFuncPtr) noexcept : Buffer() @@ -339,7 +339,7 @@ namespace { #endif // _android_ namespace { - class TStdOutput: public IOutputStream { + class TStdOutput: public IOutputStream { public: inline TStdOutput(FILE* f) noexcept : F_(f) @@ -355,7 +355,7 @@ namespace { // On Windows, if 'F_' is console -- 'fwrite' returns count of written characters. // If, for example, console output codepage is UTF-8, then returned value is // not equal to 'len'. So, we ignore some 'errno' values... - if ((errno == 0 || errno == EINVAL || errno == EILSEQ) && _isatty(fileno(F_))) { + if ((errno == 0 || errno == EINVAL || errno == EILSEQ) && _isatty(fileno(F_))) { return; } #endif @@ -401,7 +401,7 @@ namespace { }; } -IOutputStream& NPrivate::StdErrStream() noexcept { +IOutputStream& NPrivate::StdErrStream() noexcept { #if defined(_android_) if (TAndroidStdIOStreams::Enabled) { return TAndroidStdIOStreams::Instance().Err; @@ -410,7 +410,7 @@ IOutputStream& NPrivate::StdErrStream() noexcept { return TStdIOStreams::Instance().Err; } -IOutputStream& NPrivate::StdOutStream() noexcept { +IOutputStream& NPrivate::StdOutStream() noexcept { #if defined(_android_) if (TAndroidStdIOStreams::Enabled) { return TAndroidStdIOStreams::Instance().Out; @@ -423,6 +423,6 @@ void RedirectStdioToAndroidLog(bool redirect) { #if defined(_android_) TAndroidStdIOStreams::Enabled = redirect; #else - Y_UNUSED(redirect); + Y_UNUSED(redirect); #endif } diff --git a/util/stream/output.h b/util/stream/output.h index 00eef50b95..3b40c4396f 100644 --- a/util/stream/output.h +++ b/util/stream/output.h @@ -1,6 +1,6 @@ #pragma once -#include "fwd.h" +#include "fwd.h" #include "labeled.h" #include <util/generic/noncopyable.h> @@ -18,7 +18,7 @@ /** * Abstract output stream. */ -class IOutputStream: public TNonCopyable { +class IOutputStream: public TNonCopyable { public: /** * Data block for output. @@ -30,7 +30,7 @@ public: { } - inline TPart(const TStringBuf s) noexcept + inline TPart(const TStringBuf s) noexcept : buf(s.data()) , len(s.size()) { @@ -52,13 +52,13 @@ public: size_t len; }; - IOutputStream() noexcept; - virtual ~IOutputStream(); + IOutputStream() noexcept; + virtual ~IOutputStream(); - IOutputStream(IOutputStream&&) noexcept { + IOutputStream(IOutputStream&&) noexcept { } - IOutputStream& operator=(IOutputStream&&) noexcept { + IOutputStream& operator=(IOutputStream&&) noexcept { return *this; }; @@ -79,7 +79,7 @@ public: * * @param st String to write. */ - inline void Write(const TStringBuf st) { + inline void Write(const TStringBuf st) { Write(st.data(), st.size()); } @@ -171,7 +171,7 @@ protected: }; /** - * `operator<<` for `IOutputStream` by default delegates to this function. + * `operator<<` for `IOutputStream` by default delegates to this function. * * Note that while `operator<<` uses overloading (and thus argument-dependent * lookup), `Out` uses template specializations. This makes it possible to @@ -186,14 +186,14 @@ protected: * @param value Value to write. */ template <class T> -void Out(IOutputStream& out, typename TTypeTraits<T>::TFuncParam value); +void Out(IOutputStream& out, typename TTypeTraits<T>::TFuncParam value); -#define Y_DECLARE_OUT_SPEC(MODIF, T, stream, value) \ - template <> \ - MODIF void Out<T>(IOutputStream & stream, TTypeTraits<T>::TFuncParam value) +#define Y_DECLARE_OUT_SPEC(MODIF, T, stream, value) \ + template <> \ + MODIF void Out<T>(IOutputStream & stream, TTypeTraits<T>::TFuncParam value) template <> -inline void Out<const char*>(IOutputStream& o, const char* t) { +inline void Out<const char*>(IOutputStream& o, const char* t) { if (t) { o.Write(t); } else { @@ -202,24 +202,24 @@ inline void Out<const char*>(IOutputStream& o, const char* t) { } template <> -void Out<const wchar16*>(IOutputStream& o, const wchar16* w); +void Out<const wchar16*>(IOutputStream& o, const wchar16* w); template <> void Out<const wchar32*>(IOutputStream& o, const wchar32* w); -static inline IOutputStream& operator<<(IOutputStream& o, TStreamManipulator m) { +static inline IOutputStream& operator<<(IOutputStream& o, TStreamManipulator m) { m(o); return o; } -static inline IOutputStream& operator<<(IOutputStream& o, const char* t) { +static inline IOutputStream& operator<<(IOutputStream& o, const char* t) { Out<const char*>(o, t); return o; } -static inline IOutputStream& operator<<(IOutputStream& o, char* t) { +static inline IOutputStream& operator<<(IOutputStream& o, char* t) { Out<const char*>(o, t); return o; @@ -239,12 +239,12 @@ static inline std::enable_if_t<!std::is_scalar<T>::value, IOutputStream&> operat return o; } -static inline IOutputStream& operator<<(IOutputStream& o, const wchar16* t) { +static inline IOutputStream& operator<<(IOutputStream& o, const wchar16* t) { Out<const wchar16*>(o, t); return o; } -static inline IOutputStream& operator<<(IOutputStream& o, wchar16* t) { +static inline IOutputStream& operator<<(IOutputStream& o, wchar16* t) { Out<const wchar16*>(o, t); return o; } @@ -260,8 +260,8 @@ static inline IOutputStream& operator<<(IOutputStream& o, wchar32* t) { } namespace NPrivate { - IOutputStream& StdOutStream() noexcept; - IOutputStream& StdErrStream() noexcept; + IOutputStream& StdOutStream() noexcept; + IOutputStream& StdErrStream() noexcept; } /** @@ -282,14 +282,14 @@ namespace NPrivate { /** * End-of-line output manipulator, basically the same as `std::endl`. */ -static inline void Endl(IOutputStream& o) { +static inline void Endl(IOutputStream& o) { (o << '\n').Flush(); } /** * Flushing stream manipulator, basically the same as `std::flush`. */ -static inline void Flush(IOutputStream& o) { +static inline void Flush(IOutputStream& o) { o.Flush(); } diff --git a/util/stream/pipe.cpp b/util/stream/pipe.cpp index 51be1934a7..ff5b778802 100644 --- a/util/stream/pipe.cpp +++ b/util/stream/pipe.cpp @@ -8,7 +8,7 @@ class TPipeBase::TImpl { public: inline TImpl(const TString& command, const char* mode) - : Pipe_(nullptr) + : Pipe_(nullptr) { #ifndef _freebsd_ if (strcmp(mode, "r+") == 0) { @@ -16,13 +16,13 @@ public: } #endif Pipe_ = ::popen(command.data(), mode); - if (Pipe_ == nullptr) { + if (Pipe_ == nullptr) { ythrow TSystemError() << "failed to open pipe: " << command.Quote(); } } inline ~TImpl() { - if (Pipe_ != nullptr) { + if (Pipe_ != nullptr) { ::pclose(Pipe_); } } @@ -44,14 +44,14 @@ TPipeInput::TPipeInput(const TString& command) } size_t TPipeInput::DoRead(void* buf, size_t len) { - if (Impl_->Pipe_ == nullptr) { + if (Impl_->Pipe_ == nullptr) { return 0; } size_t bytesRead = ::fread(buf, 1, len, Impl_->Pipe_); if (bytesRead == 0) { int exitStatus = ::pclose(Impl_->Pipe_); - Impl_->Pipe_ = nullptr; + Impl_->Pipe_ = nullptr; if (exitStatus == -1) { ythrow TSystemError() << "pclose() failed"; } else if (exitStatus != 0) { @@ -67,14 +67,14 @@ TPipeOutput::TPipeOutput(const TString& command) } void TPipeOutput::DoWrite(const void* buf, size_t len) { - if (Impl_->Pipe_ == nullptr || len != ::fwrite(buf, 1, len, Impl_->Pipe_)) { + if (Impl_->Pipe_ == nullptr || len != ::fwrite(buf, 1, len, Impl_->Pipe_)) { ythrow TSystemError() << "fwrite failed"; } } void TPipeOutput::Close() { int exitStatus = ::pclose(Impl_->Pipe_); - Impl_->Pipe_ = nullptr; + Impl_->Pipe_ = nullptr; if (exitStatus == -1) { ythrow TSystemError() << "pclose() failed"; } else if (exitStatus != 0) { diff --git a/util/stream/pipe.h b/util/stream/pipe.h index 18525b9517..e736860a3a 100644 --- a/util/stream/pipe.h +++ b/util/stream/pipe.h @@ -88,7 +88,7 @@ protected: /** * Input stream that binds to a standard output stream of an existing process. */ -class TPipedInput: public TPipedBase, public IInputStream { +class TPipedInput: public TPipedBase, public IInputStream { public: TPipedInput(PIPEHANDLE fd); ~TPipedInput() override; @@ -100,7 +100,7 @@ private: /** * Output stream that binds to a standard input stream of an existing process. */ -class TPipedOutput: public TPipedBase, public IOutputStream { +class TPipedOutput: public TPipedBase, public IOutputStream { public: TPipedOutput(PIPEHANDLE fd); ~TPipedOutput() override; diff --git a/util/stream/printf.cpp b/util/stream/printf.cpp index f3eeca7afc..f7adaa2b2a 100644 --- a/util/stream/printf.cpp +++ b/util/stream/printf.cpp @@ -1,11 +1,11 @@ -#include "output.h" +#include "output.h" #include "printf.h" #include <util/generic/scope.h> #include <util/memory/tempbuf.h> #include <util/generic/yexception.h> -size_t Printf(IOutputStream& out, const char* fmt, ...) { +size_t Printf(IOutputStream& out, const char* fmt, ...) { va_list lst; va_start(lst, fmt); @@ -16,7 +16,7 @@ size_t Printf(IOutputStream& out, const char* fmt, ...) { return Printf(out, fmt, lst); } -static inline size_t TryPrintf(void* ptr, size_t len, IOutputStream& out, const char* fmt, va_list params) { +static inline size_t TryPrintf(void* ptr, size_t len, IOutputStream& out, const char* fmt, va_list params) { va_list lst; va_copy(lst, params); const int ret = vsnprintf((char*)ptr, len, fmt, lst); @@ -33,7 +33,7 @@ static inline size_t TryPrintf(void* ptr, size_t len, IOutputStream& out, const return (size_t)ret; } -size_t Printf(IOutputStream& out, const char* fmt, va_list params) { +size_t Printf(IOutputStream& out, const char* fmt, va_list params) { size_t guess = 0; while (true) { diff --git a/util/stream/printf.h b/util/stream/printf.h index 1c7ddc0664..c6199a15ef 100644 --- a/util/stream/printf.h +++ b/util/stream/printf.h @@ -2,7 +2,7 @@ #include <util/system/compat.h> -class IOutputStream; +class IOutputStream; /** * Stream-based `printf` function. Prints formatted data into the provided stream. @@ -12,7 +12,7 @@ class IOutputStream; * @param fmt Format string. * @param ... Additional arguments. */ -size_t Y_PRINTF_FORMAT(2, 3) Printf(IOutputStream& out, const char* fmt, ...); +size_t Y_PRINTF_FORMAT(2, 3) Printf(IOutputStream& out, const char* fmt, ...); /** * Stream-based `vprintf` function. Prints formatted data from variable argument @@ -22,4 +22,4 @@ size_t Y_PRINTF_FORMAT(2, 3) Printf(IOutputStream& out, const char* fmt, ...); * @param fmt Format string. * @param params Additional arguments as a variable argument list. */ -size_t Y_PRINTF_FORMAT(2, 0) Printf(IOutputStream& out, const char* fmt, va_list params); +size_t Y_PRINTF_FORMAT(2, 0) Printf(IOutputStream& out, const char* fmt, va_list params); diff --git a/util/stream/printf_ut.cpp b/util/stream/printf_ut.cpp index 0eab167062..fbfee58af4 100644 --- a/util/stream/printf_ut.cpp +++ b/util/stream/printf_ut.cpp @@ -1,13 +1,13 @@ -#include "null.h" +#include "null.h" #include "printf.h" -#include "str.h" +#include "str.h" #include <util/generic/string.h> - + #include <library/cpp/testing/unittest/registar.h> -Y_UNIT_TEST_SUITE(TStreamPrintfTest) { - Y_UNIT_TEST(TestPrintf) { +Y_UNIT_TEST_SUITE(TStreamPrintfTest) { + Y_UNIT_TEST(TestPrintf) { TStringStream ss; UNIT_ASSERT_EQUAL(Printf(ss, "qw %s %d", "er", 1), 7); @@ -18,11 +18,11 @@ Y_UNIT_TEST_SUITE(TStreamPrintfTest) { #pragma GCC diagnostic ignored "-Wformat-zero-length" #endif // __GNUC__ - Y_UNIT_TEST(TestZeroString) { + Y_UNIT_TEST(TestZeroString) { UNIT_ASSERT_EQUAL(Printf(Cnull, ""), 0); } - Y_UNIT_TEST(TestLargePrintf) { + Y_UNIT_TEST(TestLargePrintf) { TString s = NUnitTest::RandomString(1000000); TStringStream ss; diff --git a/util/stream/str.h b/util/stream/str.h index 028bd572c0..07dc24861a 100644 --- a/util/stream/str.h +++ b/util/stream/str.h @@ -15,7 +15,7 @@ /** * Input stream for reading data from a string. */ -class TStringInput: public IZeroCopyInputFastReadTo { +class TStringInput: public IZeroCopyInputFastReadTo { public: /** * Constructs a string input stream that reads character data from the @@ -109,7 +109,7 @@ private: */ class TStringStream: private TEmbedPolicy<TString>, public TStringInput, public TStringOutput { using TEmbeddedString = TEmbedPolicy<TString>; - + public: inline TStringStream() : TEmbeddedString() diff --git a/util/stream/str_ut.cpp b/util/stream/str_ut.cpp index fc6b46c31a..930c5eac95 100644 --- a/util/stream/str_ut.cpp +++ b/util/stream/str_ut.cpp @@ -7,7 +7,7 @@ template <typename T> const T ReturnConstTemp(); Y_UNIT_TEST_SUITE(TStringInputOutputTest) { - Y_UNIT_TEST(Lvalue) { + Y_UNIT_TEST(Lvalue) { TString str = "Hello, World!"; TStringInput input(str); @@ -16,7 +16,7 @@ Y_UNIT_TEST_SUITE(TStringInputOutputTest) { UNIT_ASSERT_VALUES_EQUAL(result, str); } - Y_UNIT_TEST(ConstRef) { + Y_UNIT_TEST(ConstRef) { TString str = "Hello, World!"; const TString& r = str; TStringInput input(r); @@ -26,7 +26,7 @@ Y_UNIT_TEST_SUITE(TStringInputOutputTest) { UNIT_ASSERT_VALUES_EQUAL(result, str); } - Y_UNIT_TEST(NonConstRef) { + Y_UNIT_TEST(NonConstRef) { TString str = "Hello, World!"; TString& r = str; TStringInput input(r); @@ -36,7 +36,7 @@ Y_UNIT_TEST_SUITE(TStringInputOutputTest) { UNIT_ASSERT_VALUES_EQUAL(result, str); } - Y_UNIT_TEST(Transfer) { + Y_UNIT_TEST(Transfer) { TString inputString = "some_string"; TStringInput input(inputString); @@ -48,7 +48,7 @@ Y_UNIT_TEST_SUITE(TStringInputOutputTest) { UNIT_ASSERT_VALUES_EQUAL(inputString, outputString); } - Y_UNIT_TEST(SkipReadAll) { + Y_UNIT_TEST(SkipReadAll) { TString string0 = "All animals are equal, but some animals are more equal than others."; TString string1; @@ -68,7 +68,7 @@ Y_UNIT_TEST_SUITE(TStringInputOutputTest) { UNIT_ASSERT_VALUES_EQUAL(string2, string1.substr(5)); } - Y_UNIT_TEST(OperatorBool) { + Y_UNIT_TEST(OperatorBool) { TStringStream str; UNIT_ASSERT(!str); str << "data"; @@ -77,7 +77,7 @@ Y_UNIT_TEST_SUITE(TStringInputOutputTest) { UNIT_ASSERT(!str); } - Y_UNIT_TEST(TestReadTo) { + Y_UNIT_TEST(TestReadTo) { TString s("0123456789abc"); TString t; @@ -113,7 +113,7 @@ Y_UNIT_TEST_SUITE(TStringInputOutputTest) { UNIT_ASSERT_STRINGS_EQUAL(str1, str2); } - Y_UNIT_TEST(Write) { + Y_UNIT_TEST(Write) { TString str; TStringOutput output(str); output << "1" @@ -129,7 +129,7 @@ Y_UNIT_TEST_SUITE(TStringInputOutputTest) { "55555"); } - Y_UNIT_TEST(WriteChars) { + Y_UNIT_TEST(WriteChars) { TString str; TStringOutput output(str); output << '1' << '2' << '3' << '4' << '5' << '6' << '7' << '8' << '9' << '0'; diff --git a/util/stream/tee.cpp b/util/stream/tee.cpp index 99873b95ba..ffa597648a 100644 --- a/util/stream/tee.cpp +++ b/util/stream/tee.cpp @@ -1,6 +1,6 @@ #include "tee.h" -TTeeOutput::TTeeOutput(IOutputStream* l, IOutputStream* r) noexcept +TTeeOutput::TTeeOutput(IOutputStream* l, IOutputStream* r) noexcept : L_(l) , R_(r) { diff --git a/util/stream/tee.h b/util/stream/tee.h index c69e232fb9..83711d7059 100644 --- a/util/stream/tee.h +++ b/util/stream/tee.h @@ -10,9 +10,9 @@ /** * A proxy output stream that writes into two slave streams simultaneously. */ -class TTeeOutput: public IOutputStream { +class TTeeOutput: public IOutputStream { public: - TTeeOutput(IOutputStream* l, IOutputStream* r) noexcept; + TTeeOutput(IOutputStream* l, IOutputStream* r) noexcept; ~TTeeOutput() override; private: @@ -21,8 +21,8 @@ private: void DoFinish() override; private: - IOutputStream* L_; - IOutputStream* R_; + IOutputStream* L_; + IOutputStream* R_; }; /** @} */ diff --git a/util/stream/tempbuf.cpp b/util/stream/tempbuf.cpp index 801a1fabb0..4fd8fc8112 100644 --- a/util/stream/tempbuf.cpp +++ b/util/stream/tempbuf.cpp @@ -7,7 +7,7 @@ namespace { } void TTempBufOutput::DoWrite(const void* data, size_t len) { - if (Y_LIKELY(len <= Left())) { + if (Y_LIKELY(len <= Left())) { Append(data, len); } else { const size_t filled = Filled(); diff --git a/util/stream/tokenizer.h b/util/stream/tokenizer.h index b2398efdd1..bc27650ce4 100644 --- a/util/stream/tokenizer.h +++ b/util/stream/tokenizer.h @@ -2,10 +2,10 @@ #include "input.h" -#include <util/generic/buffer.h> -#include <util/generic/mem_copy.h> -#include <util/generic/strbuf.h> -#include <util/system/compiler.h> +#include <util/generic/buffer.h> +#include <util/generic/mem_copy.h> +#include <util/generic/strbuf.h> +#include <util/system/compiler.h> #include <util/system/yassert.h> /** @@ -20,12 +20,12 @@ * @tparam TEndOfToken Predicate for token delimiter characters. * @see TEol */ -template <typename TEndOfToken> +template <typename TEndOfToken> class TStreamTokenizer { public: class TIterator { public: - inline TIterator(TStreamTokenizer* const parent) + inline TIterator(TStreamTokenizer* const parent) : Parent_(parent) , AtEnd_(!Parent_->Next(Data_, Len_)) { @@ -53,21 +53,21 @@ public: return !(*this == l); } - /** - * @return Return null-terminated character array with current token. - * The pointer may be invalid after iterator increment. - */ + /** + * @return Return null-terminated character array with current token. + * The pointer may be invalid after iterator increment. + */ inline const char* Data() const noexcept { - Y_ASSERT(!AtEnd_); + Y_ASSERT(!AtEnd_); return Data_; } - /** - * @return Length of current token. - */ + /** + * @return Length of current token. + */ inline size_t Length() const noexcept { - Y_ASSERT(!AtEnd_); + Y_ASSERT(!AtEnd_); return Len_; } @@ -77,27 +77,27 @@ public: } inline TStringBuf operator*() noexcept { - return TStringBuf{Data_, Len_}; + return TStringBuf{Data_, Len_}; } private: inline void Next() { - Y_ASSERT(Parent_); + Y_ASSERT(Parent_); AtEnd_ = !Parent_->Next(Data_, Len_); } private: - TStreamTokenizer* const Parent_; + TStreamTokenizer* const Parent_; char* Data_; size_t Len_; bool AtEnd_; }; - inline TStreamTokenizer(IInputStream* const input, const TEndOfToken& eot = TEndOfToken(), - const size_t initial = 1024) + inline TStreamTokenizer(IInputStream* const input, const TEndOfToken& eot = TEndOfToken(), + const size_t initial = 1024) : Input_(input) - , Buf_(initial) + , Buf_(initial) , Cur_(BufBegin()) , End_(BufBegin()) , Eot_(eot) @@ -112,7 +112,7 @@ public: do { while (it != End_) { if (Eot_(*it)) { - *it = '\0'; + *it = '\0'; buf = Cur_; len = it - Cur_; @@ -125,7 +125,7 @@ public: } if (Fill() == 0 && End_ != BufEnd()) { - *it = '\0'; + *it = '\0'; buf = Cur_; len = it - Cur_; @@ -135,25 +135,25 @@ public: } } while (it != BufEnd()); - Y_ASSERT(it == BufEnd()); - Y_ASSERT(End_ == BufEnd()); + Y_ASSERT(it == BufEnd()); + Y_ASSERT(End_ == BufEnd()); const size_t blen = End_ - Cur_; if (Cur_ == BufBegin()) { - Y_ASSERT(blen == Buf_.Capacity()); + Y_ASSERT(blen == Buf_.Capacity()); /* * do reallocate */ - Buf_.Reserve(Buf_.Capacity() * 4); + Buf_.Reserve(Buf_.Capacity() * 4); CheckBuf(); } else { /* * do move */ - MemMove(BufBegin(), Cur_, blen); + MemMove(BufBegin(), Cur_, blen); } Cur_ = BufBegin(); @@ -162,14 +162,14 @@ public: } } - inline TIterator begin() { - return TIterator{this}; - } - + inline TIterator begin() { + return TIterator{this}; + } + inline TIterator end() noexcept { - return {}; - } - + return {}; + } + private: inline size_t Fill() { const size_t avail = BufEnd() - End_; @@ -181,22 +181,22 @@ private: } inline char* BufBegin() noexcept { - return Buf_.Data(); + return Buf_.Data(); } inline char* BufEnd() noexcept { - return Buf_.Data() + Buf_.Capacity(); + return Buf_.Data() + Buf_.Capacity(); } inline void CheckBuf() const { - if (!Buf_.Data()) { + if (!Buf_.Data()) { throw std::bad_alloc(); } } private: - IInputStream* const Input_; - TBuffer Buf_; + IInputStream* const Input_; + TBuffer Buf_; char* Cur_; char* End_; TEndOfToken Eot_; diff --git a/util/stream/tokenizer_ut.cpp b/util/stream/tokenizer_ut.cpp index afc566da86..37bb12e7d2 100644 --- a/util/stream/tokenizer_ut.cpp +++ b/util/stream/tokenizer_ut.cpp @@ -1,264 +1,264 @@ #include <library/cpp/testing/unittest/registar.h> - -#include <util/generic/array_size.h> -#include <util/generic/strbuf.h> - -#include "mem.h" -#include "null.h" -#include "tokenizer.h" - -static inline void CheckIfNullTerminated(const TStringBuf str) { + +#include <util/generic/array_size.h> +#include <util/generic/strbuf.h> + +#include "mem.h" +#include "null.h" +#include "tokenizer.h" + +static inline void CheckIfNullTerminated(const TStringBuf str) { UNIT_ASSERT_VALUES_EQUAL('\0', *(str.data() + str.size())); -} - -Y_UNIT_TEST_SUITE(TStreamTokenizerTests) { - Y_UNIT_TEST(EmptyStreamTest) { - auto&& input = TNullInput{}; - auto&& tokenizer = TStreamTokenizer<TEol>{&input}; - auto tokensCount = size_t{}; - for (auto it = tokenizer.begin(); tokenizer.end() != it; ++it) { - CheckIfNullTerminated(TStringBuf{it->Data(), it->Length()}); - ++tokensCount; - } - UNIT_ASSERT_VALUES_EQUAL(0, tokensCount); - } - - Y_UNIT_TEST(EmptyTokensTest) { - const char data[] = "\n\n"; - const auto dataSize = Y_ARRAY_SIZE(data) - 1; - auto&& input = TMemoryInput{data, dataSize}; - auto&& tokenizer = TStreamTokenizer<TEol>{&input}; - auto tokensCount = size_t{}; - for (auto it = tokenizer.begin(); tokenizer.end() != it; ++it) { - CheckIfNullTerminated(TStringBuf{it->Data(), it->Length()}); - UNIT_ASSERT_VALUES_EQUAL(0, it->Length()); - ++tokensCount; - } - UNIT_ASSERT_VALUES_EQUAL(2, tokensCount); - } - - Y_UNIT_TEST(LastTokenendDoesntSatisfyPredicateTest) { - const char data[] = "abc\ndef\nxxxxxx"; - const auto dataSize = Y_ARRAY_SIZE(data) - 1; +} + +Y_UNIT_TEST_SUITE(TStreamTokenizerTests) { + Y_UNIT_TEST(EmptyStreamTest) { + auto&& input = TNullInput{}; + auto&& tokenizer = TStreamTokenizer<TEol>{&input}; + auto tokensCount = size_t{}; + for (auto it = tokenizer.begin(); tokenizer.end() != it; ++it) { + CheckIfNullTerminated(TStringBuf{it->Data(), it->Length()}); + ++tokensCount; + } + UNIT_ASSERT_VALUES_EQUAL(0, tokensCount); + } + + Y_UNIT_TEST(EmptyTokensTest) { + const char data[] = "\n\n"; + const auto dataSize = Y_ARRAY_SIZE(data) - 1; + auto&& input = TMemoryInput{data, dataSize}; + auto&& tokenizer = TStreamTokenizer<TEol>{&input}; + auto tokensCount = size_t{}; + for (auto it = tokenizer.begin(); tokenizer.end() != it; ++it) { + CheckIfNullTerminated(TStringBuf{it->Data(), it->Length()}); + UNIT_ASSERT_VALUES_EQUAL(0, it->Length()); + ++tokensCount; + } + UNIT_ASSERT_VALUES_EQUAL(2, tokensCount); + } + + Y_UNIT_TEST(LastTokenendDoesntSatisfyPredicateTest) { + const char data[] = "abc\ndef\nxxxxxx"; + const auto dataSize = Y_ARRAY_SIZE(data) - 1; const TStringBuf tokens[] = {TStringBuf("abc"), TStringBuf("def"), TStringBuf("xxxxxx")}; - const auto tokensSize = Y_ARRAY_SIZE(tokens); - auto&& input = TMemoryInput{data, dataSize}; - auto&& tokenizer = TStreamTokenizer<TEol>{&input}; - auto tokensCount = size_t{}; - for (auto it = tokenizer.begin(); tokenizer.end() != it; ++it) { - UNIT_ASSERT(tokensCount < tokensSize); - const auto token = TStringBuf{it->Data(), it->Length()}; - CheckIfNullTerminated(token); - UNIT_ASSERT_VALUES_EQUAL(tokens[tokensCount], token); - ++tokensCount; - } - UNIT_ASSERT_VALUES_EQUAL(tokensSize, tokensCount); - } - - Y_UNIT_TEST(FirstTokenIsEmptyTest) { - const char data[] = "\ndef\nxxxxxx"; - const auto dataSize = Y_ARRAY_SIZE(data) - 1; + const auto tokensSize = Y_ARRAY_SIZE(tokens); + auto&& input = TMemoryInput{data, dataSize}; + auto&& tokenizer = TStreamTokenizer<TEol>{&input}; + auto tokensCount = size_t{}; + for (auto it = tokenizer.begin(); tokenizer.end() != it; ++it) { + UNIT_ASSERT(tokensCount < tokensSize); + const auto token = TStringBuf{it->Data(), it->Length()}; + CheckIfNullTerminated(token); + UNIT_ASSERT_VALUES_EQUAL(tokens[tokensCount], token); + ++tokensCount; + } + UNIT_ASSERT_VALUES_EQUAL(tokensSize, tokensCount); + } + + Y_UNIT_TEST(FirstTokenIsEmptyTest) { + const char data[] = "\ndef\nxxxxxx"; + const auto dataSize = Y_ARRAY_SIZE(data) - 1; const TStringBuf tokens[] = {TStringBuf(), TStringBuf("def"), TStringBuf("xxxxxx")}; - const auto tokensSize = Y_ARRAY_SIZE(tokens); - auto&& input = TMemoryInput{data, dataSize}; - auto&& tokenizer = TStreamTokenizer<TEol>{&input}; - auto tokensCount = size_t{}; - for (auto it = tokenizer.begin(); tokenizer.end() != it; ++it) { - UNIT_ASSERT(tokensCount < tokensSize); - const auto token = TStringBuf{it->Data(), it->Length()}; - CheckIfNullTerminated(token); - UNIT_ASSERT_VALUES_EQUAL(tokens[tokensCount], token); - ++tokensCount; - } - UNIT_ASSERT_VALUES_EQUAL(tokensSize, tokensCount); - } - - Y_UNIT_TEST(PredicateDoesntMatch) { - const char data[] = "1234567890-=!@#$%^&*()_+QWERTYUIOP{}qwertyuiop[]ASDFGHJKL:"; - const auto dataSize = Y_ARRAY_SIZE(data) - 1; - auto&& input = TMemoryInput{data, dataSize}; - auto&& tokenizer = TStreamTokenizer<TEol>{&input}; - auto tokensCount = size_t{}; - for (auto it = tokenizer.begin(); tokenizer.end() != it; ++it) { - const auto token = TStringBuf{it->Data(), it->Length()}; - CheckIfNullTerminated(token); - UNIT_ASSERT_VALUES_EQUAL(data, token); - ++tokensCount; - } - UNIT_ASSERT_VALUES_EQUAL(1, tokensCount); - } - - Y_UNIT_TEST(SimpleTest) { - const char data[] = "qwerty\n1234567890\n"; - const auto dataSize = Y_ARRAY_SIZE(data) - 1; + const auto tokensSize = Y_ARRAY_SIZE(tokens); + auto&& input = TMemoryInput{data, dataSize}; + auto&& tokenizer = TStreamTokenizer<TEol>{&input}; + auto tokensCount = size_t{}; + for (auto it = tokenizer.begin(); tokenizer.end() != it; ++it) { + UNIT_ASSERT(tokensCount < tokensSize); + const auto token = TStringBuf{it->Data(), it->Length()}; + CheckIfNullTerminated(token); + UNIT_ASSERT_VALUES_EQUAL(tokens[tokensCount], token); + ++tokensCount; + } + UNIT_ASSERT_VALUES_EQUAL(tokensSize, tokensCount); + } + + Y_UNIT_TEST(PredicateDoesntMatch) { + const char data[] = "1234567890-=!@#$%^&*()_+QWERTYUIOP{}qwertyuiop[]ASDFGHJKL:"; + const auto dataSize = Y_ARRAY_SIZE(data) - 1; + auto&& input = TMemoryInput{data, dataSize}; + auto&& tokenizer = TStreamTokenizer<TEol>{&input}; + auto tokensCount = size_t{}; + for (auto it = tokenizer.begin(); tokenizer.end() != it; ++it) { + const auto token = TStringBuf{it->Data(), it->Length()}; + CheckIfNullTerminated(token); + UNIT_ASSERT_VALUES_EQUAL(data, token); + ++tokensCount; + } + UNIT_ASSERT_VALUES_EQUAL(1, tokensCount); + } + + Y_UNIT_TEST(SimpleTest) { + const char data[] = "qwerty\n1234567890\n"; + const auto dataSize = Y_ARRAY_SIZE(data) - 1; const TStringBuf tokens[] = {TStringBuf("qwerty"), TStringBuf("1234567890")}; - const auto tokensSize = Y_ARRAY_SIZE(tokens); - auto&& input = TMemoryInput{data, dataSize}; - auto&& tokenizer = TStreamTokenizer<TEol>{&input}; - auto tokensCount = size_t{}; - for (auto it = tokenizer.begin(); tokenizer.end() != it; ++it) { - UNIT_ASSERT(tokensCount < tokensSize); - const auto token = TStringBuf{it->Data(), it->Length()}; - CheckIfNullTerminated(token); - UNIT_ASSERT_VALUES_EQUAL(tokens[tokensCount], token); - ++tokensCount; - } - UNIT_ASSERT_VALUES_EQUAL(tokensSize, tokensCount); - } - - Y_UNIT_TEST(CustomPredicateTest) { - struct TIsVerticalBar { + const auto tokensSize = Y_ARRAY_SIZE(tokens); + auto&& input = TMemoryInput{data, dataSize}; + auto&& tokenizer = TStreamTokenizer<TEol>{&input}; + auto tokensCount = size_t{}; + for (auto it = tokenizer.begin(); tokenizer.end() != it; ++it) { + UNIT_ASSERT(tokensCount < tokensSize); + const auto token = TStringBuf{it->Data(), it->Length()}; + CheckIfNullTerminated(token); + UNIT_ASSERT_VALUES_EQUAL(tokens[tokensCount], token); + ++tokensCount; + } + UNIT_ASSERT_VALUES_EQUAL(tokensSize, tokensCount); + } + + Y_UNIT_TEST(CustomPredicateTest) { + struct TIsVerticalBar { inline bool operator()(const char ch) const noexcept { - return '|' == ch; - } - }; - - const char data[] = "abc|def|xxxxxx"; - const auto dataSize = Y_ARRAY_SIZE(data) - 1; + return '|' == ch; + } + }; + + const char data[] = "abc|def|xxxxxx"; + const auto dataSize = Y_ARRAY_SIZE(data) - 1; const TStringBuf tokens[] = {TStringBuf("abc"), TStringBuf("def"), TStringBuf("xxxxxx")}; - const auto tokensSize = Y_ARRAY_SIZE(tokens); - auto&& input = TMemoryInput{data, dataSize}; - auto&& tokenizer = TStreamTokenizer<TIsVerticalBar>{&input}; - auto tokensCount = size_t{}; - for (auto it = tokenizer.begin(); tokenizer.end() != it; ++it) { - UNIT_ASSERT(tokensCount < tokensSize); - const auto token = TStringBuf{it->Data(), it->Length()}; - CheckIfNullTerminated(token); - UNIT_ASSERT_VALUES_EQUAL(tokens[tokensCount], token); - ++tokensCount; - } - UNIT_ASSERT_VALUES_EQUAL(tokensSize, tokensCount); - } - - Y_UNIT_TEST(CustomPredicateSecondTest) { - struct TIsVerticalBar { + const auto tokensSize = Y_ARRAY_SIZE(tokens); + auto&& input = TMemoryInput{data, dataSize}; + auto&& tokenizer = TStreamTokenizer<TIsVerticalBar>{&input}; + auto tokensCount = size_t{}; + for (auto it = tokenizer.begin(); tokenizer.end() != it; ++it) { + UNIT_ASSERT(tokensCount < tokensSize); + const auto token = TStringBuf{it->Data(), it->Length()}; + CheckIfNullTerminated(token); + UNIT_ASSERT_VALUES_EQUAL(tokens[tokensCount], token); + ++tokensCount; + } + UNIT_ASSERT_VALUES_EQUAL(tokensSize, tokensCount); + } + + Y_UNIT_TEST(CustomPredicateSecondTest) { + struct TIsVerticalBar { inline bool operator()(const char ch) const noexcept { - return '|' == ch || ',' == ch; - } - }; - - const char data[] = "abc|def|xxxxxx,abc|def|xxxxxx"; - const auto dataSize = Y_ARRAY_SIZE(data) - 1; + return '|' == ch || ',' == ch; + } + }; + + const char data[] = "abc|def|xxxxxx,abc|def|xxxxxx"; + const auto dataSize = Y_ARRAY_SIZE(data) - 1; const TStringBuf tokens[] = {TStringBuf("abc"), TStringBuf("def"), TStringBuf("xxxxxx"), TStringBuf("abc"), TStringBuf("def"), TStringBuf("xxxxxx")}; - const auto tokensSize = Y_ARRAY_SIZE(tokens); - auto&& input = TMemoryInput{data, dataSize}; - auto&& tokenizer = TStreamTokenizer<TIsVerticalBar>{&input}; - auto tokensCount = size_t{}; - for (auto it = tokenizer.begin(); tokenizer.end() != it; ++it) { - UNIT_ASSERT(tokensCount < tokensSize); - const auto token = TStringBuf{it->Data(), it->Length()}; - CheckIfNullTerminated(token); - UNIT_ASSERT_VALUES_EQUAL(tokens[tokensCount], token); - ++tokensCount; - } - UNIT_ASSERT_VALUES_EQUAL(tokensSize, tokensCount); - } - - Y_UNIT_TEST(FalsePredicateTest) { - struct TAlwaysFalse { + const auto tokensSize = Y_ARRAY_SIZE(tokens); + auto&& input = TMemoryInput{data, dataSize}; + auto&& tokenizer = TStreamTokenizer<TIsVerticalBar>{&input}; + auto tokensCount = size_t{}; + for (auto it = tokenizer.begin(); tokenizer.end() != it; ++it) { + UNIT_ASSERT(tokensCount < tokensSize); + const auto token = TStringBuf{it->Data(), it->Length()}; + CheckIfNullTerminated(token); + UNIT_ASSERT_VALUES_EQUAL(tokens[tokensCount], token); + ++tokensCount; + } + UNIT_ASSERT_VALUES_EQUAL(tokensSize, tokensCount); + } + + Y_UNIT_TEST(FalsePredicateTest) { + struct TAlwaysFalse { inline bool operator()(const char) const noexcept { - return false; - } - }; - - const char data[] = "1234567890-=!@#$%^&*()_+QWERTYUIOP{}qwertyuiop[]ASDFGHJKL:"; - const auto dataSize = Y_ARRAY_SIZE(data) - 1; - auto&& input = TMemoryInput{data, dataSize}; - auto&& tokenizer = TStreamTokenizer<TAlwaysFalse>{&input}; - auto tokensCount = size_t{}; - for (auto it = tokenizer.begin(); tokenizer.end() != it; ++it) { - const auto token = TStringBuf{it->Data(), it->Length()}; - CheckIfNullTerminated(token); - UNIT_ASSERT_VALUES_EQUAL(data, token); - ++tokensCount; - } - UNIT_ASSERT_VALUES_EQUAL(1, tokensCount); - } - - Y_UNIT_TEST(TruePredicateTest) { - struct TAlwaysTrue { + return false; + } + }; + + const char data[] = "1234567890-=!@#$%^&*()_+QWERTYUIOP{}qwertyuiop[]ASDFGHJKL:"; + const auto dataSize = Y_ARRAY_SIZE(data) - 1; + auto&& input = TMemoryInput{data, dataSize}; + auto&& tokenizer = TStreamTokenizer<TAlwaysFalse>{&input}; + auto tokensCount = size_t{}; + for (auto it = tokenizer.begin(); tokenizer.end() != it; ++it) { + const auto token = TStringBuf{it->Data(), it->Length()}; + CheckIfNullTerminated(token); + UNIT_ASSERT_VALUES_EQUAL(data, token); + ++tokensCount; + } + UNIT_ASSERT_VALUES_EQUAL(1, tokensCount); + } + + Y_UNIT_TEST(TruePredicateTest) { + struct TAlwaysTrue { inline bool operator()(const char) const noexcept { - return true; - } - }; - - const char data[] = "1234567890-=!@#$%^&*()_+QWERTYUIOP{}qwertyuiop[]ASDFGHJKL:"; - const auto dataSize = Y_ARRAY_SIZE(data) - 1; - auto&& input = TMemoryInput{data, dataSize}; - auto&& tokenizer = TStreamTokenizer<TAlwaysTrue>{&input}; - auto tokensCount = size_t{}; - for (auto it = tokenizer.begin(); tokenizer.end() != it; ++it) { - CheckIfNullTerminated(TStringBuf{it->Data(), it->Length()}); - UNIT_ASSERT_VALUES_EQUAL(0, it->Length()); - ++tokensCount; - } - UNIT_ASSERT_VALUES_EQUAL(dataSize, tokensCount); - } - - Y_UNIT_TEST(FirstTokenHasSizeOfTheBufferTest) { - const char data[] = "xxxxx\nxx"; - const auto dataSize = Y_ARRAY_SIZE(data) - 1; + return true; + } + }; + + const char data[] = "1234567890-=!@#$%^&*()_+QWERTYUIOP{}qwertyuiop[]ASDFGHJKL:"; + const auto dataSize = Y_ARRAY_SIZE(data) - 1; + auto&& input = TMemoryInput{data, dataSize}; + auto&& tokenizer = TStreamTokenizer<TAlwaysTrue>{&input}; + auto tokensCount = size_t{}; + for (auto it = tokenizer.begin(); tokenizer.end() != it; ++it) { + CheckIfNullTerminated(TStringBuf{it->Data(), it->Length()}); + UNIT_ASSERT_VALUES_EQUAL(0, it->Length()); + ++tokensCount; + } + UNIT_ASSERT_VALUES_EQUAL(dataSize, tokensCount); + } + + Y_UNIT_TEST(FirstTokenHasSizeOfTheBufferTest) { + const char data[] = "xxxxx\nxx"; + const auto dataSize = Y_ARRAY_SIZE(data) - 1; const TStringBuf tokens[] = {TStringBuf("xxxxx"), TStringBuf("xx")}; - const auto tokensSize = Y_ARRAY_SIZE(tokens); - auto&& input = TMemoryInput{data, dataSize}; - auto&& tokenizer = TStreamTokenizer<TEol>{&input, TEol{}, tokens[0].size()}; - auto tokensCount = size_t{}; - for (auto it = tokenizer.begin(); tokenizer.end() != it; ++it) { - const auto token = TStringBuf{it->Data(), it->Length()}; - CheckIfNullTerminated(token); - UNIT_ASSERT_VALUES_EQUAL(tokens[tokensCount], token); - ++tokensCount; - } - UNIT_ASSERT_VALUES_EQUAL(tokensSize, tokensCount); - } - - Y_UNIT_TEST(OnlyTokenHasSizeOfTheBufferTest) { - const char data[] = "xxxxx"; - const auto dataSize = Y_ARRAY_SIZE(data) - 1; - auto&& input = TMemoryInput{data, dataSize}; - auto&& tokenizer = TStreamTokenizer<TEol>{&input, TEol{}, dataSize}; - auto tokensCount = size_t{}; - for (auto it = tokenizer.begin(); tokenizer.end() != it; ++it) { - const auto token = TStringBuf{it->Data(), it->Length()}; - CheckIfNullTerminated(token); - UNIT_ASSERT_VALUES_EQUAL(data, token); - ++tokensCount; - } - UNIT_ASSERT_VALUES_EQUAL(1, tokensCount); - } - - Y_UNIT_TEST(BufferSizeInitialSizeSmallerThanTokenTest) { - const char data[] = "xxxxx\nxx"; - const auto dataSize = Y_ARRAY_SIZE(data) - 1; + const auto tokensSize = Y_ARRAY_SIZE(tokens); + auto&& input = TMemoryInput{data, dataSize}; + auto&& tokenizer = TStreamTokenizer<TEol>{&input, TEol{}, tokens[0].size()}; + auto tokensCount = size_t{}; + for (auto it = tokenizer.begin(); tokenizer.end() != it; ++it) { + const auto token = TStringBuf{it->Data(), it->Length()}; + CheckIfNullTerminated(token); + UNIT_ASSERT_VALUES_EQUAL(tokens[tokensCount], token); + ++tokensCount; + } + UNIT_ASSERT_VALUES_EQUAL(tokensSize, tokensCount); + } + + Y_UNIT_TEST(OnlyTokenHasSizeOfTheBufferTest) { + const char data[] = "xxxxx"; + const auto dataSize = Y_ARRAY_SIZE(data) - 1; + auto&& input = TMemoryInput{data, dataSize}; + auto&& tokenizer = TStreamTokenizer<TEol>{&input, TEol{}, dataSize}; + auto tokensCount = size_t{}; + for (auto it = tokenizer.begin(); tokenizer.end() != it; ++it) { + const auto token = TStringBuf{it->Data(), it->Length()}; + CheckIfNullTerminated(token); + UNIT_ASSERT_VALUES_EQUAL(data, token); + ++tokensCount; + } + UNIT_ASSERT_VALUES_EQUAL(1, tokensCount); + } + + Y_UNIT_TEST(BufferSizeInitialSizeSmallerThanTokenTest) { + const char data[] = "xxxxx\nxx"; + const auto dataSize = Y_ARRAY_SIZE(data) - 1; const TStringBuf tokens[] = {TStringBuf("xxxxx"), TStringBuf("xx")}; - const auto tokensSize = Y_ARRAY_SIZE(tokens); - auto&& input = TMemoryInput{data, dataSize}; - auto&& tokenizer = TStreamTokenizer<TEol>{&input, TEol{}, 1}; - auto tokensCount = size_t{}; - for (auto it = tokenizer.begin(); tokenizer.end() != it; ++it) { - const auto token = TStringBuf{it->Data(), it->Length()}; - CheckIfNullTerminated(token); - UNIT_ASSERT_VALUES_EQUAL(tokens[tokensCount], token); - ++tokensCount; - } - UNIT_ASSERT_VALUES_EQUAL(tokensSize, tokensCount); - } - - Y_UNIT_TEST(RangeBasedForTest) { - const char data[] = "abc\ndef\nxxxxxx"; - const auto dataSize = Y_ARRAY_SIZE(data) - 1; + const auto tokensSize = Y_ARRAY_SIZE(tokens); + auto&& input = TMemoryInput{data, dataSize}; + auto&& tokenizer = TStreamTokenizer<TEol>{&input, TEol{}, 1}; + auto tokensCount = size_t{}; + for (auto it = tokenizer.begin(); tokenizer.end() != it; ++it) { + const auto token = TStringBuf{it->Data(), it->Length()}; + CheckIfNullTerminated(token); + UNIT_ASSERT_VALUES_EQUAL(tokens[tokensCount], token); + ++tokensCount; + } + UNIT_ASSERT_VALUES_EQUAL(tokensSize, tokensCount); + } + + Y_UNIT_TEST(RangeBasedForTest) { + const char data[] = "abc\ndef\nxxxxxx"; + const auto dataSize = Y_ARRAY_SIZE(data) - 1; const TStringBuf tokens[] = {TStringBuf("abc"), TStringBuf("def"), TStringBuf("xxxxxx")}; - const auto tokensSize = Y_ARRAY_SIZE(tokens); - auto&& input = TMemoryInput{data, dataSize}; - auto&& tokenizer = TStreamTokenizer<TEol>{&input}; - auto tokensCount = size_t{}; - for (const auto& token : tokenizer) { - UNIT_ASSERT(tokensCount < tokensSize); - CheckIfNullTerminated(token); - UNIT_ASSERT_VALUES_EQUAL(tokens[tokensCount], token); - ++tokensCount; - } - UNIT_ASSERT_VALUES_EQUAL(tokensSize, tokensCount); - } -} + const auto tokensSize = Y_ARRAY_SIZE(tokens); + auto&& input = TMemoryInput{data, dataSize}; + auto&& tokenizer = TStreamTokenizer<TEol>{&input}; + auto tokensCount = size_t{}; + for (const auto& token : tokenizer) { + UNIT_ASSERT(tokensCount < tokensSize); + CheckIfNullTerminated(token); + UNIT_ASSERT_VALUES_EQUAL(tokens[tokensCount], token); + ++tokensCount; + } + UNIT_ASSERT_VALUES_EQUAL(tokensSize, tokensCount); + } +} diff --git a/util/stream/trace.h b/util/stream/trace.h index e74b6ecf3e..9674dc7481 100644 --- a/util/stream/trace.h +++ b/util/stream/trace.h @@ -15,21 +15,21 @@ enum ETraceLevel: ui8 { TRACE_VERBOSE = 7 }; -#if !defined(NDEBUG) && !defined(Y_ENABLE_TRACE) +#if !defined(NDEBUG) && !defined(Y_ENABLE_TRACE) #define Y_ENABLE_TRACE #endif -#ifdef Y_ENABLE_TRACE +#ifdef Y_ENABLE_TRACE /** * Writes the given data into standard debug stream if current debug level set * via `DBGOUT` environment variable permits it. * - * Does nothing in release builds unless `Y_ENABLE_TRACE` is defined. + * Does nothing in release builds unless `Y_ENABLE_TRACE` is defined. * * Example usage: * @code - * Y_DBGTRACE(DEBUG, "Advance from " << node1 << " to " << node2); + * Y_DBGTRACE(DEBUG, "Advance from " << node1 << " to " << node2); * @endcode * * @param elevel Debug level of this trace command, e.g. diff --git a/util/stream/walk.cpp b/util/stream/walk.cpp index 57dc9ab036..0243939398 100644 --- a/util/stream/walk.cpp +++ b/util/stream/walk.cpp @@ -1,13 +1,13 @@ #include "walk.h" #include <util/generic/string.h> - -void IWalkInput::DoUndo(size_t len) { + +void IWalkInput::DoUndo(size_t len) { Len_ += len; Buf_ = static_cast<const char*>(Buf_) - len; } -size_t IWalkInput::DoNext(const void** ptr, size_t len) { +size_t IWalkInput::DoNext(const void** ptr, size_t len) { if (!Len_) { Len_ = DoUnboundedNext(&Buf_); } diff --git a/util/stream/walk.h b/util/stream/walk.h index 7e62cb44dc..36b50727e7 100644 --- a/util/stream/walk.h +++ b/util/stream/walk.h @@ -7,10 +7,10 @@ * * Derived classes must implement `DoUnboundedNext` method. */ -class IWalkInput: public IZeroCopyInputFastReadTo { +class IWalkInput: public IZeroCopyInputFastReadTo { public: - IWalkInput() - : Buf_(nullptr) + IWalkInput() + : Buf_(nullptr) , Len_(0) { } diff --git a/util/stream/walk_ut.cpp b/util/stream/walk_ut.cpp index e0a783799f..b5a8057b1b 100644 --- a/util/stream/walk_ut.cpp +++ b/util/stream/walk_ut.cpp @@ -2,7 +2,7 @@ #include <library/cpp/testing/unittest/registar.h> -class TStringListInput: public IWalkInput { +class TStringListInput: public IWalkInput { public: TStringListInput(const TVector<TString>& data) : Data_(data) @@ -27,8 +27,8 @@ private: size_t Index_; }; -Y_UNIT_TEST_SUITE(TWalkTest) { - Y_UNIT_TEST(ReadTo) { +Y_UNIT_TEST_SUITE(TWalkTest) { + Y_UNIT_TEST(ReadTo) { TVector<TString> data; data.push_back("111a"); data.push_back("222b"); diff --git a/util/stream/zerocopy.cpp b/util/stream/zerocopy.cpp index dc2982ad55..b8b378014c 100644 --- a/util/stream/zerocopy.cpp +++ b/util/stream/zerocopy.cpp @@ -1,9 +1,9 @@ #include "zerocopy.h" #include "output.h" -IZeroCopyInput::~IZeroCopyInput() = default; +IZeroCopyInput::~IZeroCopyInput() = default; -size_t IZeroCopyInput::DoRead(void* buf, size_t len) { +size_t IZeroCopyInput::DoRead(void* buf, size_t len) { const void* ptr; size_t result = DoNext(&ptr, len); @@ -14,7 +14,7 @@ size_t IZeroCopyInput::DoRead(void* buf, size_t len) { return result; } -ui64 IZeroCopyInput::DoReadAll(IOutputStream& out) { +ui64 IZeroCopyInput::DoReadAll(IOutputStream& out) { ui64 result = 0; const void* ptr; @@ -26,15 +26,15 @@ ui64 IZeroCopyInput::DoReadAll(IOutputStream& out) { return result; } -size_t IZeroCopyInput::DoSkip(size_t len) { +size_t IZeroCopyInput::DoSkip(size_t len) { const void* ptr; return DoNext(&ptr, len); } -IZeroCopyInputFastReadTo::~IZeroCopyInputFastReadTo() = default; +IZeroCopyInputFastReadTo::~IZeroCopyInputFastReadTo() = default; -size_t IZeroCopyInputFastReadTo::DoReadTo(TString& st, char ch) { +size_t IZeroCopyInputFastReadTo::DoReadTo(TString& st, char ch) { const char* ptr; size_t len = Next(&ptr); if (!len) { diff --git a/util/stream/zerocopy.h b/util/stream/zerocopy.h index 3315aa3a51..9c99326d55 100644 --- a/util/stream/zerocopy.h +++ b/util/stream/zerocopy.h @@ -6,7 +6,7 @@ #include "input.h" -class IOutputStream; +class IOutputStream; /** * @addtogroup Streams @@ -18,13 +18,13 @@ class IOutputStream; * * Derived classes must implement `DoNext` method. */ -class IZeroCopyInput: public IInputStream { +class IZeroCopyInput: public IInputStream { public: - IZeroCopyInput() noexcept = default; - ~IZeroCopyInput() override; + IZeroCopyInput() noexcept = default; + ~IZeroCopyInput() override; - IZeroCopyInput(IZeroCopyInput&&) noexcept = default; - IZeroCopyInput& operator=(IZeroCopyInput&&) noexcept = default; + IZeroCopyInput(IZeroCopyInput&&) noexcept = default; + IZeroCopyInput& operator=(IZeroCopyInput&&) noexcept = default; /** * Returns the next data chunk from this input stream. @@ -39,7 +39,7 @@ public: */ template <class T> inline size_t Next(T** ptr, size_t len) { - Y_ASSERT(ptr); + Y_ASSERT(ptr); return DoNext((const void**)ptr, len); } @@ -52,7 +52,7 @@ public: protected: size_t DoRead(void* buf, size_t len) override; size_t DoSkip(size_t len) override; - ui64 DoReadAll(IOutputStream& out) override; + ui64 DoReadAll(IOutputStream& out) override; virtual size_t DoNext(const void** ptr, size_t len) = 0; }; @@ -61,13 +61,13 @@ protected: * * Derived classes must implement `DoUndo` method. */ -class IZeroCopyInputFastReadTo: public IZeroCopyInput { +class IZeroCopyInputFastReadTo: public IZeroCopyInput { public: - IZeroCopyInputFastReadTo() noexcept = default; - ~IZeroCopyInputFastReadTo() override; + IZeroCopyInputFastReadTo() noexcept = default; + ~IZeroCopyInputFastReadTo() override; - IZeroCopyInputFastReadTo(IZeroCopyInputFastReadTo&&) noexcept = default; - IZeroCopyInputFastReadTo& operator=(IZeroCopyInputFastReadTo&&) noexcept = default; + IZeroCopyInputFastReadTo(IZeroCopyInputFastReadTo&&) noexcept = default; + IZeroCopyInputFastReadTo& operator=(IZeroCopyInputFastReadTo&&) noexcept = default; protected: size_t DoReadTo(TString& st, char ch) override; diff --git a/util/stream/zlib.cpp b/util/stream/zlib.cpp index 60f4e9439f..2893cc044b 100644 --- a/util/stream/zlib.cpp +++ b/util/stream/zlib.cpp @@ -29,7 +29,7 @@ namespace { inline ~TZLibCommon() = default; inline const char* GetErrMsg() const noexcept { - return Z()->msg != nullptr ? Z()->msg : "unknown error"; + return Z()->msg != nullptr ? Z()->msg : "unknown error"; } inline z_stream* Z() const noexcept { @@ -45,9 +45,9 @@ namespace { } struct TChunkedZeroCopyInput { - inline TChunkedZeroCopyInput(IZeroCopyInput* in) + inline TChunkedZeroCopyInput(IZeroCopyInput* in) : In(in) - , Buf(nullptr) + , Buf(nullptr) , Len(0) { } @@ -72,7 +72,7 @@ namespace { return true; } - IZeroCopyInput* In; + IZeroCopyInput* In; const char* Buf; size_t Len; }; @@ -162,7 +162,7 @@ private: }; namespace { - class TDecompressStream: public IZeroCopyInput, public TZLibDecompress::TImpl, public TAdditionalStorage<TDecompressStream> { + class TDecompressStream: public IZeroCopyInput, public TZLibDecompress::TImpl, public TAdditionalStorage<TDecompressStream> { public: inline TDecompressStream(IInputStream* input, ZLib::StreamType type, TStringBuf dict) : TZLibDecompress::TImpl(this, type, dict) @@ -181,7 +181,7 @@ namespace { } private: - IInputStream* Stream_; + IInputStream* Stream_; }; using TZeroCopyDecompress = TZLibDecompress::TImpl; @@ -314,7 +314,7 @@ private: } private: - IOutputStream* Stream_; + IOutputStream* Stream_; THolder<gz_header> GZHeader_; }; diff --git a/util/stream/zlib.h b/util/stream/zlib.h index e7de7c81b7..8abf255b53 100644 --- a/util/stream/zlib.h +++ b/util/stream/zlib.h @@ -1,6 +1,6 @@ #pragma once -#include "fwd.h" +#include "fwd.h" #include "input.h" #include "output.h" #include "buffered.h" @@ -45,7 +45,7 @@ namespace ZLib { * benchmark). For fast buffered ZLib stream reading use `TBufferedZLibDecompress` * aka `TZDecompress`. */ -class TZLibDecompress: public IInputStream { +class TZLibDecompress: public IInputStream { public: TZLibDecompress(IZeroCopyInput* input, ZLib::StreamType type = ZLib::Auto, TStringBuf dict = {}); TZLibDecompress(IInputStream* input, ZLib::StreamType type = ZLib::Auto, size_t buflen = ZLib::ZLIB_BUF_LEN, @@ -56,7 +56,7 @@ public: * * If multiple streams are allowed, their decompressed content will be concatenated. * If multiple streams are disabled, then only first stream is decompressed. After that end - * of IInputStream will have happen, i.e. method Read() will return 0. + * of IInputStream will have happen, i.e. method Read() will return 0. * * @param allowMultipleStreams - flag to allow (true) or disable (false) multiple streams. */ @@ -75,10 +75,10 @@ public: /** * Non-buffered ZLib compressing stream. */ -class TZLibCompress: public IOutputStream { +class TZLibCompress: public IOutputStream { public: struct TParams { - inline TParams(IOutputStream* out) + inline TParams(IOutputStream* out) : Out(out) , Type(ZLib::ZLib) , CompressionLevel(6) @@ -104,13 +104,13 @@ public: return *this; } - inline TParams& SetDict(const TStringBuf dict) noexcept { + inline TParams& SetDict(const TStringBuf dict) noexcept { Dict = dict; return *this; } - IOutputStream* Out; + IOutputStream* Out; ZLib::StreamType Type; size_t CompressionLevel; size_t BufLen; @@ -121,15 +121,15 @@ public: Init(params); } - inline TZLibCompress(IOutputStream* out, ZLib::StreamType type) { + inline TZLibCompress(IOutputStream* out, ZLib::StreamType type) { Init(TParams(out).SetType(type)); } - inline TZLibCompress(IOutputStream* out, ZLib::StreamType type, size_t compression_level) { + inline TZLibCompress(IOutputStream* out, ZLib::StreamType type, size_t compression_level) { Init(TParams(out).SetType(type).SetCompressionLevel(compression_level)); } - inline TZLibCompress(IOutputStream* out, ZLib::StreamType type, size_t compression_level, size_t buflen) { + inline TZLibCompress(IOutputStream* out, ZLib::StreamType type, size_t compression_level, size_t buflen) { Init(TParams(out).SetType(type).SetCompressionLevel(compression_level).SetBufLen(buflen)); } diff --git a/util/stream/zlib_ut.cpp b/util/stream/zlib_ut.cpp index 2290b4a9de..b145da317f 100644 --- a/util/stream/zlib_ut.cpp +++ b/util/stream/zlib_ut.cpp @@ -51,11 +51,11 @@ private: int Limit_; }; -Y_UNIT_TEST_SUITE(TZLibTest) { +Y_UNIT_TEST_SUITE(TZLibTest) { static const TString DATA = "8s7d5vc6s5vc67sa4c65ascx6asd4xcv76adsfxv76s"; static const TString DATA2 = "cn8wk2bd9vb3vdfif83g1ks94bfiovtwv"; - Y_UNIT_TEST(Compress) { + Y_UNIT_TEST(Compress) { TUnbufferedFileOutput o(ZDATA); TZLibCompress c(&o, ZLib::ZLib); @@ -64,7 +64,7 @@ Y_UNIT_TEST_SUITE(TZLibTest) { o.Finish(); } - Y_UNIT_TEST(Decompress) { + Y_UNIT_TEST(Decompress) { TTempFile tmpFile(ZDATA); { @@ -90,7 +90,7 @@ Y_UNIT_TEST_SUITE(TZLibTest) { } } - Y_UNIT_TEST(DecompressTwoStreams) { + Y_UNIT_TEST(DecompressTwoStreams) { // Check that Decompress(Compress(X) + Compress(Y)) == X + Y TTempFile tmpFile(ZDATA); { @@ -126,7 +126,7 @@ Y_UNIT_TEST_SUITE(TZLibTest) { TVector<char>().swap(buf); } - Y_UNIT_TEST(DecompressFirstOfTwoStreams) { + Y_UNIT_TEST(DecompressFirstOfTwoStreams) { // Check that Decompress(Compress(X) + Compress(Y)) == X when single stream is allowed TTempFile tmpFile(ZDATA); { |