21 : buffer_(read_buffer_size), read_buffer_size_(read_buffer_size)
28 if (file_ !=
nullptr) {
35 is_binary_ = is_binary;
41 throw std::runtime_error(
"PLY read_line should not be used in binary mode");
43 if (pos_ >= last_newline_) {
48 while (pos_ < last_newline_ && !
is_newline(buffer_[pos_])) {
53 if (res_end > res_begin && buffer_[res_end - 1] ==
'\r') {
57 if (pos_ < buf_used_ &&
is_newline(buffer_[pos_])) {
60 return Span<char>(buffer_.
data() + res_begin, res_end - res_begin);
66 if (pos_ + size > buf_used_) {
67 if (!refill_buffer()) {
71 int to_copy =
int(size);
72 if (to_copy > buf_used_) {
75 memcpy(dst, buffer_.
data() + pos_, to_copy);
77 dst = (
char *)dst + to_copy;
83bool PlyReadBuffer::refill_buffer()
89 if (file_ ==
nullptr || at_eof_) {
94 int keep = buf_used_ - pos_;
96 memmove(buffer_.
data(), buffer_.
data() + pos_, keep);
99 size_t read = fread(buffer_.
data() + keep, 1, read_buffer_size_ - keep, file_) + keep;
100 at_eof_ =
read < read_buffer_size_;
106 while (pos_ < buf_used_ &&
is_newline(buffer_[pos_])) {
110 int last_nl = buf_used_;
112 while (last_nl > 0) {
120 throw std::runtime_error(
"PLY text line did not fit into the read buffer");
123 last_newline_ = last_nl;
File and directory operations.
FILE * BLI_fopen(const char *filepath, const char *mode) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL()
PlyReadBuffer(const char *file_path, size_t read_buffer_size=64 *1024)
void after_header(bool is_binary)
bool read_bytes(void *dst, size_t size)
draw_view push_constant(Type::INT, "radiance_src") .push_constant(Type capture_info_buf storage_buf(1, Qualifier::READ, "ObjectBounds", "bounds_buf[]") .push_constant(Type draw_view int
static char read(std::ifstream &file)
static bool is_newline(char ch)