-
Notifications
You must be signed in to change notification settings - Fork 73
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rename to BoundedReader, rename to m_curr_pos, only update curr_pos o…
…n error if EOF
- Loading branch information
1 parent
2ab88fd
commit 8977dc4
Showing
5 changed files
with
84 additions
and
82 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
#include "BoundedReader.hpp" | ||
|
||
namespace clp { | ||
auto BoundedReader::try_seek_from_begin(size_t pos) -> ErrorCode { | ||
auto next_pos = pos > m_bound ? m_bound : pos; | ||
if (auto const rc = m_reader->try_seek_from_begin(next_pos); ErrorCode_Success != rc) { | ||
m_curr_pos = ErrorCode_EndOfFile == rc ? next_pos : m_curr_pos; | ||
return rc; | ||
} | ||
m_curr_pos = next_pos; | ||
if (m_curr_pos >= m_bound) { | ||
return ErrorCode_EndOfFile; | ||
} | ||
return ErrorCode_Success; | ||
} | ||
|
||
auto BoundedReader::try_read(char* buf, size_t num_bytes_to_read, size_t& num_bytes_read) | ||
-> ErrorCode { | ||
if (m_curr_pos == m_bound) { | ||
num_bytes_read = 0; | ||
return ErrorCode_EndOfFile; | ||
} | ||
|
||
if ((m_curr_pos + num_bytes_to_read) > m_bound) { | ||
num_bytes_to_read = m_bound - m_curr_pos; | ||
} | ||
|
||
auto const rc = m_reader->try_read(buf, num_bytes_to_read, num_bytes_read); | ||
m_curr_pos += num_bytes_read; | ||
if (ErrorCode_EndOfFile == rc) { | ||
if (0 == num_bytes_read) { | ||
return ErrorCode_EndOfFile; | ||
} | ||
} else if (ErrorCode_Success != rc) { | ||
return rc; | ||
} | ||
return ErrorCode_Success; | ||
} | ||
} // namespace clp |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters