16 #if defined(unix) || defined(__unix) || defined(__unix__) || defined(__APPLE__)
18 #elif defined(_WIN32) || defined(_WIN64)
31 #if defined(unix) || defined(__unix) || defined(__unix__) || defined(__APPLE__)
33 if (_stream ==
nullptr)
34 throwex SystemException(
"Failed to get a valid standard input stream!");
35 #elif defined(_WIN32) || defined(_WIN64)
36 _stream = GetStdHandle(STD_INPUT_HANDLE);
37 if (_stream == INVALID_HANDLE_VALUE)
38 throwex SystemException(
"Failed to get a valid standard input stream!");
44 void*
stream() const noexcept
51 #if defined(unix) || defined(__unix) || defined(__unix__) || defined(__APPLE__)
52 return (_stream !=
nullptr);
53 #elif defined(_WIN32) || defined(_WIN64)
54 return (_stream != INVALID_HANDLE_VALUE);
58 size_t Read(
void* buffer,
size_t size)
60 if ((buffer ==
nullptr) || (size == 0))
63 assert(
IsValid() &&
"Standard input stream is not valid!");
65 throwex SystemException(
"Cannot read from the invalid standard input stream!");
66 #if defined(unix) || defined(__unix) || defined(__unix__) || defined(__APPLE__)
67 size_t result = fread(buffer, 1, size, _stream);
68 if (ferror(_stream) != 0)
69 throwex SystemException(
"Cannot read from the standard input stream!");
71 #elif defined(_WIN32) || defined(_WIN64)
73 if (!ReadFile(_stream, buffer, (DWORD)size, &result,
nullptr))
74 throwex SystemException(
"Cannot read from the standard input stream!");
75 return (
size_t)result;
80 #if defined(unix) || defined(__unix) || defined(__unix__) || defined(__APPLE__)
82 #elif defined(_WIN32) || defined(_WIN64)
92 #if defined(unix) || defined(__unix) || defined(__unix__) || defined(__APPLE__)
94 if (_stream ==
nullptr)
95 throwex SystemException(
"Failed to get a valid standard output stream!");
96 #elif defined(_WIN32) || defined(_WIN64)
97 _stream = GetStdHandle(STD_OUTPUT_HANDLE);
98 if (_stream == INVALID_HANDLE_VALUE)
99 throwex SystemException(
"Failed to get a valid standard output stream!");
105 void*
stream() const noexcept
112 #if defined(unix) || defined(__unix) || defined(__unix__) || defined(__APPLE__)
113 return (_stream !=
nullptr);
114 #elif defined(_WIN32) || defined(_WIN64)
115 return (_stream != INVALID_HANDLE_VALUE);
119 size_t Write(
const void* buffer,
size_t size)
121 if ((buffer ==
nullptr) || (size == 0))
124 assert(
IsValid() &&
"Standard output stream is not valid!");
126 throwex SystemException(
"Cannot write into the invalid standard output stream!");
127 #if defined(unix) || defined(__unix) || defined(__unix__) || defined(__APPLE__)
128 size_t result = fwrite(buffer, 1, size, _stream);
129 if (ferror(_stream) != 0)
130 throwex SystemException(
"Cannot write into the standard output stream!");
132 #elif defined(_WIN32) || defined(_WIN64)
134 if (!WriteFile(_stream, buffer, (DWORD)size, &result,
nullptr))
135 throwex SystemException(
"Cannot write into the standard output stream!");
136 return (
size_t)result;
142 #if defined(unix) || defined(__unix) || defined(__unix__) || defined(__APPLE__)
143 int result = fflush(_stream);
145 throwex SystemException(
"Cannot flush the standard output stream!");
146 #elif defined(_WIN32) || defined(_WIN64)
147 if (!FlushFileBuffers(_stream))
148 throwex SystemException(
"Cannot flush the standard output stream!");
153 #if defined(unix) || defined(__unix) || defined(__unix__) || defined(__APPLE__)
155 #elif defined(_WIN32) || defined(_WIN64)
165 #if defined(unix) || defined(__unix) || defined(__unix__) || defined(__APPLE__)
167 if (_stream ==
nullptr)
168 throwex SystemException(
"Failed to get a valid standard error stream!");
169 #elif defined(_WIN32) || defined(_WIN64)
170 _stream = GetStdHandle(STD_ERROR_HANDLE);
171 if (_stream == INVALID_HANDLE_VALUE)
172 throwex SystemException(
"Failed to get a valid standard error stream!");
178 void*
stream() const noexcept
185 #if defined(unix) || defined(__unix) || defined(__unix__) || defined(__APPLE__)
186 return (_stream !=
nullptr);
187 #elif defined(_WIN32) || defined(_WIN64)
188 return (_stream != INVALID_HANDLE_VALUE);
192 size_t Write(
const void* buffer,
size_t size)
194 if ((buffer ==
nullptr) || (size == 0))
197 assert(
IsValid() &&
"Standard error stream is not valid!");
199 throwex SystemException(
"Cannot write into the invalid standard error stream!");
200 #if defined(unix) || defined(__unix) || defined(__unix__) || defined(__APPLE__)
201 size_t result = fwrite(buffer, 1, size, _stream);
202 if (ferror(_stream) != 0)
203 throwex SystemException(
"Cannot write into the standard error stream!");
205 #elif defined(_WIN32) || defined(_WIN64)
207 if (!WriteFile(_stream, buffer, (DWORD)size, &result,
nullptr))
208 throwex SystemException(
"Cannot write into the standard error stream!");
209 return (
size_t)result;
215 #if defined(unix) || defined(__unix) || defined(__unix__) || defined(__APPLE__)
216 int result = fflush(_stream);
218 throwex SystemException(
"Cannot flush the standard error stream!");
219 #elif defined(_WIN32) || defined(_WIN64)
220 if (!FlushFileBuffers(_stream))
221 throwex SystemException(
"Cannot flush the standard error stream!");
226 #if defined(unix) || defined(__unix) || defined(__unix__) || defined(__APPLE__)
228 #elif defined(_WIN32) || defined(_WIN64)
239 static_assert((StorageSize >=
sizeof(Impl)),
"StdInput::StorageSize must be increased!");
240 static_assert(((StorageAlign %
alignof(Impl)) == 0),
"StdInput::StorageAlign must be adjusted!");
243 new(&_storage)Impl();
249 reinterpret_cast<Impl*
>(&_storage)->~Impl();
254 size_t StdInput::Read(
void* buffer,
size_t size) {
return impl().Read(buffer, size); }
259 swap(_storage, stream._storage);
266 static_assert((StorageSize >=
sizeof(Impl)),
"StdOutput::StorageSize must be increased!");
267 static_assert(((StorageAlign %
alignof(Impl)) == 0),
"StdOutput::StorageAlign must be adjusted!");
270 new(&_storage)Impl();
276 reinterpret_cast<Impl*
>(&_storage)->~Impl();
281 size_t StdOutput::Write(
const void* buffer,
size_t size) {
return impl().Write(buffer, size); }
287 swap(_storage, stream._storage);
294 static_assert((StorageSize >=
sizeof(Impl)),
"StdError::StorageSize must be increased!");
295 static_assert(((StorageAlign %
alignof(Impl)) == 0),
"StdError::StorageAlign must be adjusted!");
298 new(&_storage)Impl();
304 reinterpret_cast<Impl*
>(&_storage)->~Impl();
309 size_t StdError::Write(
const void* buffer,
size_t size) {
return impl().Write(buffer, size); }
315 swap(_storage, stream._storage);
void * stream() const noexcept
Get the native stream handler.
virtual size_t Write(const void *buffer, size_t size)=0
Write a byte buffer base method.
void Flush() override
Flush the stream.
void swap(StdError &stream) noexcept
Swap two instances.
bool IsValid() const noexcept
Is stream valid?
void swap(StdOutput &stream) noexcept
Swap two instances.
virtual size_t Write(const void *buffer, size_t size)=0
Write a byte buffer base method.
void * stream() const noexcept
Get the native stream handler.
void Flush() override
Flush the stream.
bool IsValid() const noexcept
Is stream valid?
Aligned storage validator.
#define throwex
Throw extended exception macro.
Fatal abort execution definition.
C++ Common project definitions.
void swap(FileCache &cache1, FileCache &cache2) noexcept
Standard input/output/error stream definition.
Aligned storage validator definition.