28 : buffer_(read_buffer_size), read_buffer_size_(read_buffer_size)
35 if (file_ !=
nullptr) {
42 is_binary_ = is_binary;
53 throw std::runtime_error(
"PLY read_line should not be used in binary mode");
55 if (pos_ >= last_newline_) {
59 while (pos_ >= buf_used_) {
60 if (!refill_buffer()) {
66 while (pos_ < last_newline_ && !
is_newline(buffer_[pos_])) {
71 if (res_end > res_begin && buffer_[res_end - 1] ==
'\r') {
75 if (pos_ < buf_used_ &&
is_newline(buffer_[pos_])) {
78 return Span<char>(buffer_.data() + res_begin, res_end - res_begin);
84 if (pos_ + size > buf_used_) {
85 if (!refill_buffer()) {
89 const size_t to_copy = std::min(size,
size_t(buf_used_));
90 memcpy(dst, buffer_.data() + pos_, to_copy);
92 dst =
static_cast<char *
>(dst) + to_copy;
98bool PlyReadBuffer::refill_buffer()
104 if (file_ ==
nullptr || at_eof_) {
109 const bool is_file_start = buf_used_ == 0;
112 int keep = buf_used_ - pos_;
114 memmove(buffer_.
data(), buffer_.
data() + pos_, keep);
117 size_t read = fread(buffer_.
data() + keep, 1, read_buffer_size_ - keep, file_) + keep;
118 at_eof_ = read < read_buffer_size_;
120 buf_used_ = int(read);
126 while (pos_ < buf_used_ &&
is_newline(buffer_[pos_])) {
131 int last_nl = buf_used_;
133 while (last_nl > 0) {
141 throw std::runtime_error(
"PLY text line did not fit into the read buffer");
144 last_newline_ = last_nl;
File and directory operations.
PlyReadBuffer(const char *file_path, size_t read_buffer_size=64 *1024)
void after_header(bool is_binary)
std::optional< Span< char > > try_read_line()
bool read_bytes(void *dst, size_t size)
BLI_assert(slot->slot_subtype.map==BMO_OP_SLOT_SUBTYPE_MAP_FLT)
static bool is_newline(char ch)
FILE * BLI_fopen(const char *filepath, const char *mode) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL()