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
Defines noexcept geared to the environment, or the equivalent.
bool Flush() noexcept
Flushes the stream.
#define NLIB_FINAL
Defines final if it is available for use. If not, holds an empty string.
#define NLIB_DISALLOW_COPY_AND_ASSIGN(TypeName)
Prohibits use of the copy constructor and assignment operator for the class specified by TypeName...
#define NLIB_SAFE_BOOL(class_name, exp)
Defines a safe operator bool function in the class. Uses the C++11 explicit bool if it is available f...
bool IsOk() const noexcept
Checks that no error has occurred.
#define NLIB_OVERRIDE
Defines override if it is available for use. If not, holds an empty string.
BufferingMode GetBufferingMode() const noexcept
Gets the buffering mode.
uint64_t Pos64() const noexcept
Returns the current position in the stream as a 64-bit integer.
constexpr OutputStream() noexcept
Instantiates the object with default parameters (default constructor).
The class for OutputStream objects for which no actual writing takes place.
bool Write(int b) noexcept
Writes one byte of data to the stream.
#define NLIB_CEXPR
Defines constexpr if it is available for use. If not, holds an empty string.
size_t Pos() const noexcept
Returns the current position in the stream.
void SetError(errno_t e) const noexcept
Sets an error to OutputStream.
virtual ~OutputStream() noexcept
Destructor. Does not do anything.
A file that contains the configuration information for each development environment.
The output is line buffered. This mode is set when data is output to the console. ...
bool Write(const void *p, size_t n) noexcept
Writes n bytes of data to the stream.
BufferingMode
The buffering mode for OutputStream.
The base class for output streams. This class cannot be instantiated.
bool WriteGather(const nlib_fd_iovec *iov, int iovcnt) noexcept
Writes data from multiple non-continuous buffers to a stream.