21 using std::streamsize;
23 static const size_t substream_buffer_size = 4096;
50 _buffer = (
char *)PANDA_MALLOC_ARRAY(substream_buffer_size * 2);
51 char *ebuf = _buffer + substream_buffer_size * 2;
52 char *mbuf = _buffer + substream_buffer_size;
53 setg(_buffer, mbuf, mbuf);
62 char *m = b + (t - b) / 2;
75 PANDA_FREE_ARRAY(_buffer);
92 if (source !=
nullptr) {
95 if (dest !=
nullptr) {
108 if (_source !=
nullptr && !_source->
unref()) {
111 if (_dest !=
nullptr && !_dest->
unref()) {
122 pbump(pbase() - pptr());
123 gbump(egptr() - gptr());
130 seekoff(streamoff off, ios_seekdir dir, ios_openmode which) {
131 streampos result = -1;
136 if (which & ios::in) {
138 size_t n = egptr() - gptr();
141 nassertr(_gpos >= 0, EOF);
142 streampos cur_pos = _gpos;
143 streampos new_pos = cur_pos;
148 new_pos = (streampos)off + _start;
152 new_pos = (streampos)((streamoff)cur_pos + off);
156 if (_end == (streampos)0) {
161 new_pos = _end + off;
170 if (new_pos < _start) {
175 if (_end != (streampos)0 && new_pos > _end) {
181 nassertr(_gpos >= 0, EOF);
182 result = new_pos - _start;
185 if (which & ios::out) {
187 size_t n = pptr() - pbase();
188 streampos cur_pos = _ppos + (streamoff)n;
189 streampos new_pos = cur_pos;
194 new_pos = (streampos)off + _start;
198 new_pos = (streampos)((streamoff)cur_pos + off);
202 if (_end == (streampos)0) {
207 new_pos = _end + off;
216 if (new_pos < _start) {
221 if (_end != (streampos)0 && new_pos > _end) {
227 nassertr(_ppos >= 0, EOF);
228 result = new_pos - _start;
245 return seekoff(pos, ios::beg, which);
256 size_t n = pptr() - pbase();
258 if (_end != (streampos)0 && _ppos + (streampos)n > _end) {
260 n = (size_t)(_end - _ppos);
267 nassertr(_dest !=
nullptr, EOF);
281 if (okflag && ch != EOF) {
282 if (pptr() != epptr()) {
304 size_t n = pptr() - pbase();
307 nassertr(_dest !=
nullptr, EOF);
332 if (gptr() >= egptr()) {
336 size_t buffer_size = egptr() - eback();
337 gbump(-(
int)buffer_size);
339 streamsize num_bytes = buffer_size;
340 if (_end != (streampos)0 && _gpos + (streampos)num_bytes > _end) {
342 streamsize new_num_bytes = _end - _gpos;
343 if (new_num_bytes == 0) {
350 size_t delta = num_bytes - new_num_bytes;
352 num_bytes = new_num_bytes;
353 nassertr(egptr() - gptr() == num_bytes, EOF);
356 nassertr(_source !=
nullptr, EOF);
357 streamsize read_count;
359 _source->
seek_read(_gpos, gptr(), num_bytes, read_count, eof);
362 if (read_count != num_bytes) {
364 if (read_count == 0) {
370 nassertr(read_count < num_bytes, EOF);
371 size_t delta = num_bytes - read_count;
372 memmove(gptr() + delta, gptr(), read_count);
377 return (
unsigned char)*gptr();
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
virtual std::streampos seekoff(std::streamoff off, ios_seekdir dir, ios_openmode which)
Implements seeking within the stream.
void seek_eof_write(const char *buffer, std::streamsize num_bytes, bool &fail)
Atomically seeks to the end of the file, and writes a number of bytes to the stream.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
std::streamsize seek_gpos_eof()
Atomically seeks to EOF and returns the gpos there; that is, returns the file size.
This class provides a locking wrapper around an arbitrary istream pointer.
std::streamsize seek_ppos_eof()
Atomically seeks to EOF and returns the ppos there; that is, returns the file size.
void seek_write(std::streamsize pos, const char *buffer, std::streamsize num_bytes, bool &fail)
Atomically seeks to a particular offset from the beginning of the file, and writes a number of bytes ...
virtual std::streampos seekpos(std::streampos pos, ios_openmode which)
A variant on seekoff() to implement seeking within a stream.
void ref() const
Increments the reference count.
This class provides a locking wrapper around an arbitrary ostream pointer.
void seek_read(std::streamsize pos, char *buffer, std::streamsize num_bytes, std::streamsize &read_bytes, bool &eof)
Atomically seeks to a particular offset from the beginning of the file, and reads a number of bytes f...
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
bool unref() const
Decrements the reference count.