diff options
| author | Vasile Vilvoiu <vasi@vilvoiu.ro> | 2021-07-21 18:33:51 +0300 |
|---|---|---|
| committer | Vasile Vilvoiu <vasi@vilvoiu.ro> | 2021-07-21 18:33:51 +0300 |
| commit | 270dfd60cde3a7b65a2654eef0f299f32ca704c4 (patch) | |
| tree | c0afad3642995e6c29e3788e94098cbf73eb3211 /src/input-reader.cpp | |
| parent | 1f59802058d1b8fbd51b9f01bd400625773e714f (diff) | |
Checks in base InputReader class.
Make InputReader::GetBuffer() a protected member.
Diffstat (limited to 'src/input-reader.cpp')
| -rw-r--r-- | src/input-reader.cpp | 11 |
1 files changed, 7 insertions, 4 deletions
diff --git a/src/input-reader.cpp b/src/input-reader.cpp index 2f10530..f1df3bf 100644 --- a/src/input-reader.cpp +++ b/src/input-reader.cpp @@ -13,6 +13,12 @@ InputReader::InputReader(std::istream * stream, std::size_t block_size_bytes) : stream_(stream), block_size_bytes_(block_size_bytes) { + if (stream == nullptr) { + throw std::runtime_error("valid stream is required"); + } + if (block_size_bytes == 0) { + throw std::runtime_error("block size in bytes must be positive"); + } } SyncInputReader::SyncInputReader(std::istream * stream, std::size_t block_size_bytes) @@ -54,9 +60,6 @@ SyncInputReader::GetBuffer() AsyncInputReader::AsyncInputReader(std::istream * stream, std::size_t block_size_bytes) : InputReader(stream, block_size_bytes) { - if (block_size_bytes == 0) { - throw std::runtime_error("block size in bytes must be positive"); - } this->buffer_ = new char[block_size_bytes]; assert(this->buffer_ != nullptr); this->bytes_in_buffer_ = 0; @@ -161,4 +164,4 @@ AsyncInputReader::GetBuffer() std::vector<char> wrapper(this->buffer_, this->buffer_ + this->bytes_in_buffer_); this->bytes_in_buffer_ = 0; return wrapper; -}
\ No newline at end of file +} |
