aboutsummaryrefslogtreecommitdiffstats
path: root/util/stream/output.h
diff options
context:
space:
mode:
authorAnton Samokhvalov <pg83@yandex.ru>2022-02-10 16:45:17 +0300
committerDaniil Cherednik <dcherednik@yandex-team.ru>2022-02-10 16:45:17 +0300
commitd3a398281c6fd1d3672036cb2d63f842d2cb28c5 (patch)
treedd4bd3ca0f36b817e96812825ffaf10d645803f2 /util/stream/output.h
parent72cb13b4aff9bc9cf22e49251bc8fd143f82538f (diff)
downloadydb-d3a398281c6fd1d3672036cb2d63f842d2cb28c5.tar.gz
Restoring authorship annotation for Anton Samokhvalov <pg83@yandex.ru>. Commit 2 of 2.
Diffstat (limited to 'util/stream/output.h')
-rw-r--r--util/stream/output.h224
1 files changed, 112 insertions, 112 deletions
diff --git a/util/stream/output.h b/util/stream/output.h
index 121208df78..00eef50b95 100644
--- a/util/stream/output.h
+++ b/util/stream/output.h
@@ -1,15 +1,15 @@
#pragma once
-
+
#include "fwd.h"
#include "labeled.h"
#include <util/generic/noncopyable.h>
#include <util/generic/string.h>
-#include <util/generic/strbuf.h>
-#include <util/generic/typetraits.h>
-
-#include <type_traits>
-
+#include <util/generic/strbuf.h>
+#include <util/generic/typetraits.h>
+
+#include <type_traits>
+
/**
* @addtogroup Streams_Base
* @{
@@ -19,44 +19,44 @@
* Abstract output stream.
*/
class IOutputStream: public TNonCopyable {
-public:
+public:
/**
* Data block for output.
*/
- struct TPart {
+ struct TPart {
inline TPart(const void* Buf, size_t Len) noexcept
- : buf(Buf)
- , len(Len)
- {
- }
-
+ : buf(Buf)
+ , len(Len)
+ {
+ }
+
inline TPart(const TStringBuf s) noexcept
: buf(s.data())
, len(s.size())
- {
- }
-
+ {
+ }
+
inline TPart() noexcept
- : buf(nullptr)
- , len(0)
- {
- }
-
+ : buf(nullptr)
+ , len(0)
+ {
+ }
+
inline ~TPart() = default;
-
+
static inline TPart CrLf() noexcept {
return TPart("\r\n", 2);
- }
-
- const void* buf;
- size_t len;
- };
-
+ }
+
+ const void* buf;
+ size_t len;
+ };
+
IOutputStream() noexcept;
virtual ~IOutputStream();
-
+
IOutputStream(IOutputStream&&) noexcept {
- }
+ }
IOutputStream& operator=(IOutputStream&&) noexcept {
return *this;
@@ -68,12 +68,12 @@ public:
* @param buf Data to write.
* @param len Number of bytes to write.
*/
- inline void Write(const void* buf, size_t len) {
- if (len) {
- DoWrite(buf, len);
- }
- }
-
+ inline void Write(const void* buf, size_t len) {
+ if (len) {
+ DoWrite(buf, len);
+ }
+ }
+
/**
* Writes a string into this stream.
*
@@ -81,7 +81,7 @@ public:
*/
inline void Write(const TStringBuf st) {
Write(st.data(), st.size());
- }
+ }
/**
* Writes several data blocks into this stream.
@@ -90,23 +90,23 @@ public:
* array.
* @param count Number of data blocks to write.
*/
- inline void Write(const TPart* parts, size_t count) {
- if (count > 1) {
- DoWriteV(parts, count);
- } else if (count) {
- DoWrite(parts->buf, parts->len);
- }
- }
-
+ inline void Write(const TPart* parts, size_t count) {
+ if (count > 1) {
+ DoWriteV(parts, count);
+ } else if (count) {
+ DoWrite(parts->buf, parts->len);
+ }
+ }
+
/**
* Writes a single character into this stream.
*
* @param ch Character to write.
*/
- inline void Write(char ch) {
+ inline void Write(char ch) {
DoWriteC(ch);
- }
-
+ }
+
/**
* Flushes this stream's buffer, if any.
*
@@ -115,19 +115,19 @@ public:
* stream << "some string" << Flush;
* @endcode
*/
- inline void Flush() {
- DoFlush();
- }
-
+ inline void Flush() {
+ DoFlush();
+ }
+
/**
* Flushes and closes this stream. No more data can be written into a stream
* once it's closed.
*/
- inline void Finish() {
- DoFinish();
- }
-
-protected:
+ inline void Finish() {
+ DoFinish();
+ }
+
+protected:
/**
* Writes into this stream.
*
@@ -135,7 +135,7 @@ protected:
* @param len Number of bytes to write.
* @throws yexception If IO error occurs.
*/
- virtual void DoWrite(const void* buf, size_t len) = 0;
+ virtual void DoWrite(const void* buf, size_t len) = 0;
/**
* Writes several data blocks into this stream.
@@ -145,7 +145,7 @@ protected:
* @param count Number of data blocks to write.
* @throws yexception If IO error occurs.
*/
- virtual void DoWriteV(const TPart* parts, size_t count);
+ virtual void DoWriteV(const TPart* parts, size_t count);
/**
* Writes a single character into this stream. Can be overridden with a faster implementation.
@@ -159,7 +159,7 @@ protected:
*
* @throws yexception If IO error occurs.
*/
- virtual void DoFlush();
+ virtual void DoFlush();
/**
* Flushes and closes this stream. No more data can be written into a stream
@@ -167,9 +167,9 @@ protected:
*
* @throws yexception If IO error occurs.
*/
- virtual void DoFinish();
-};
-
+ virtual void DoFinish();
+};
+
/**
* `operator<<` for `IOutputStream` by default delegates to this function.
*
@@ -185,60 +185,60 @@ protected:
* @param out Output stream to write into.
* @param value Value to write.
*/
-template <class T>
+template <class T>
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)
-template <>
+template <>
inline void Out<const char*>(IOutputStream& o, const char* t) {
- if (t) {
- o.Write(t);
- } else {
- o.Write("(null)");
- }
-}
-
-template <>
+ if (t) {
+ o.Write(t);
+ } else {
+ o.Write("(null)");
+ }
+}
+
+template <>
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) {
- m(o);
-
- return o;
-}
-
+ m(o);
+
+ return o;
+}
+
static inline IOutputStream& operator<<(IOutputStream& o, const char* t) {
- Out<const char*>(o, t);
-
- return o;
-}
-
+ Out<const char*>(o, t);
+
+ return o;
+}
+
static inline IOutputStream& operator<<(IOutputStream& o, char* t) {
- Out<const char*>(o, t);
-
- return o;
-}
-
-template <class T>
-static inline std::enable_if_t<std::is_scalar<T>::value, IOutputStream&> operator<<(IOutputStream& o, T t) {
- Out<T>(o, t);
-
- return o;
-}
-
-template <class T>
-static inline std::enable_if_t<!std::is_scalar<T>::value, IOutputStream&> operator<<(IOutputStream& o, const T& t) {
- Out<T>(o, t);
-
- return o;
-}
-
+ Out<const char*>(o, t);
+
+ return o;
+}
+
+template <class T>
+static inline std::enable_if_t<std::is_scalar<T>::value, IOutputStream&> operator<<(IOutputStream& o, T t) {
+ Out<T>(o, t);
+
+ return o;
+}
+
+template <class T>
+static inline std::enable_if_t<!std::is_scalar<T>::value, IOutputStream&> operator<<(IOutputStream& o, const T& t) {
+ Out<T>(o, t);
+
+ return o;
+}
+
static inline IOutputStream& operator<<(IOutputStream& o, const wchar16* t) {
Out<const wchar16*>(o, t);
return o;
@@ -277,15 +277,15 @@ namespace NPrivate {
/**
* Standard log stream.
*/
-#define Clog Cerr
-
+#define Clog Cerr
+
/**
* End-of-line output manipulator, basically the same as `std::endl`.
- */
+ */
static inline void Endl(IOutputStream& o) {
(o << '\n').Flush();
-}
-
+}
+
/**
* Flushing stream manipulator, basically the same as `std::flush`.
*/
@@ -293,12 +293,12 @@ static inline void Flush(IOutputStream& o) {
o.Flush();
}
-/*
+/*
* Also see format.h for additional manipulators.
*/
-#include "debug.h"
-
+#include "debug.h"
+
void RedirectStdioToAndroidLog(bool redirect);
/** @} */