22 : buffer_(read_buffer_size), read_buffer_size_(read_buffer_size)
29 if (file_ !=
nullptr) {
36 is_binary_ = is_binary;
42 throw std::runtime_error(
"PLY read_line should not be used in binary mode");
44 if (pos_ >= last_newline_) {
49 while (pos_ < last_newline_ && !
is_newline(buffer_[pos_])) {
54 if (res_end > res_begin && buffer_[res_end - 1] ==
'\r') {
58 if (pos_ < buf_used_ &&
is_newline(buffer_[pos_])) {
61 return Span<char>(buffer_.data() + res_begin, res_end - res_begin);
67 if (pos_ +
size > buf_used_) {
68 if (!refill_buffer()) {
72 int to_copy = int(
size);
73 to_copy = std::min(to_copy, buf_used_);
74 memcpy(dst, buffer_.data() + pos_, to_copy);
76 dst = (
char *)dst + to_copy;
82bool PlyReadBuffer::refill_buffer()
88 if (file_ ==
nullptr || at_eof_) {
93 int keep = buf_used_ - pos_;
95 memmove(buffer_.
data(), buffer_.
data() + pos_, keep);
98 size_t read = fread(buffer_.
data() + keep, 1, read_buffer_size_ - keep, file_) + keep;
99 at_eof_ =
read < read_buffer_size_;
101 buf_used_ = int(
read);
105 while (pos_ < buf_used_ &&
is_newline(buffer_[pos_])) {
109 int last_nl = buf_used_;
111 while (last_nl > 0) {
119 throw std::runtime_error(
"PLY text line did not fit into the read buffer");
122 last_newline_ = last_nl;
File and directory operations.
FILE * BLI_fopen(const char *filepath, const char *mode) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL()
static DBVT_INLINE btScalar size(const btDbvtVolume &a)
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)
static bool is_newline(char ch)