3 #ifndef INCLUDE_NN_NLIB_OUTPUTSTREAM_H_
4 #define INCLUDE_NN_NLIB_OUTPUTSTREAM_H_
20 BUFFERINGMODE_BLOCKBUFFERED = 0,
22 BUFFERINGMODE_UNBUFFERED
31 m_BufferingMode(BUFFERINGMODE_BLOCKBUFFERED) {}
51 m_Buf[m_Cur++] =
static_cast<unsigned char>(b & 0xff);
55 #ifndef NLIB_NONNULL_ENABLED
57 this->SetError(EINVAL);
62 this->SetError(EINVAL);
65 if (m_Cur + n <= m_BufSize) {
70 return this->Write_(p, n);
73 #ifndef NLIB_NONNULL_ENABLED
75 this->SetError(EINVAL);
80 this->SetError(EINVAL);
83 return this->WriteGather_(iov, iovcnt);
96 m_Buf =
reinterpret_cast<unsigned char*
>(p);
97 m_BufSize =
static_cast<int>(nBytes);
100 if (m_ErrorId == 0) m_ErrorId = e;
104 virtual bool PushBuffer_(
const void* p,
size_t nBytes,
bool doFlush)
NLIB_NOEXCEPT = 0;
105 virtual bool Close_() NLIB_NOEXCEPT = 0;
106 virtual
void* GetWorkBuffer_(
size_t* nBytes) NLIB_NOEXCEPT;
107 virtual
bool WriteGather_(const nlib_fd_iovec* iov,
int iovcnt) NLIB_NOEXCEPT;
108 bool Write_(const
void* p,
size_t n) NLIB_NOEXCEPT;
111 bool Flush_(
bool flushDevice) NLIB_NOEXCEPT;
112 bool GetWorkBuffer_() NLIB_NOEXCEPT;
117 unsigned char* m_Buf;
139 unsigned char m_DummyBuf[256];
140 virtual bool PushBuffer_(
const void* p,
size_t,
bool doFlush) NLIB_NOEXCEPT
NLIB_OVERRIDE;
141 virtual bool Close_() NLIB_NOEXCEPT NLIB_OVERRIDE {
return true; }
146 #endif // INCLUDE_NN_NLIB_OUTPUTSTREAM_H_
#define NLIB_NOEXCEPT
環境に合わせてnoexcept 又は同等の定義がされます。
bool Flush() noexcept
ストリームをフラッシュします。
#define NLIB_FINAL
利用可能であればfinalが定義されます。そうでない場合は空文字列です。
#define NLIB_DISALLOW_COPY_AND_ASSIGN(TypeName)
TypeName で指定されたクラスのコピーコンストラクタと代入演算子を禁止します。
#define NLIB_SAFE_BOOL(class_name, exp)
クラス内に安全なoperator bool()を定義します。 可能であればC++11のexplicit boolを利用します。 ...
bool IsOk() const noexcept
エラーが発生していないかどうかを調べます。
#define NLIB_OVERRIDE
利用可能であればoverrideが定義されます。そうでない場合は空文字列です。
BufferingMode GetBufferingMode() const noexcept
バッファリングモードを取得します。
uint64_t Pos64() const noexcept
ストリーム上の現在位置を64bit整数で返します。
constexpr OutputStream() noexcept
デフォルトコンストラクタです。
実際の書き込み動作を行わないOutputStreamです。
bool Write(int b) noexcept
ストリームに1バイトのデータを書き込みます。
#define NLIB_CEXPR
利用可能であればconstexprが定義されます。そうでない場合は空文字列です。
size_t Pos() const noexcept
ストリーム上の現在位置を返します。
void SetError(errno_t e) const noexcept
OutputStreamにエラーを設定します。
virtual ~OutputStream() noexcept
デストラクタです。何もしません。
出力をラインバッファします。コンソールに出力する場合に設定されます。
bool Write(const void *p, size_t n) noexcept
ストリームにn バイトのデータを書き込みます。
BufferingMode
OutputStreamのバッファリングモードです。
出力ストリームの基底クラスです。このクラスを実体化することはできません。
bool WriteGather(const nlib_fd_iovec *iov, int iovcnt) noexcept
複数の非連続のバッファからデータをストリームに書き出します。