44 std::ios::openmode mode = std::ios::binary;
50 mode |= std::ios::out;
53 mode |= std::ios::in | std::ios::out;
56 mode |= std::ios::in | std::ios::out | std::ios::trunc;
91 for (
int ch = sgetc(); ch != EOF; ch = snextc()) {
101 *str++ =
static_cast<char>(ch);
136 int_type ch = sputc(static_cast<char_type>(value));
137 return (ch != traits_type::eof()) ? 1 : 0;
169 template <
int nBytes> uint32_t read() {
185 std::streamoff fileSz_;
186 std::streamoff filePos_;
201 fileSz_ = pubseekoff(0, std::ios::end);
210 unsigned long long size()
const {
return fileSz_; }
226 if (filePos_ != -2) {
227 filePos_ = seekpos(fileSz_);
233 std::streamsize n = xsputn(s, count);
241 std::streamsize
sgetn(char_type* s, std::streamsize count) {
242 std::streamsize res = xsgetn(s, count);
253 if (filePos_ < 0 || pos < filePos_)
254 return filePos_ = seekpos(pos);
256 if (filePos_ != pos) {
257 const std::streamsize avail = egptr() - gptr();
258 if (avail >= pos - filePos_) {
259 ASSERT(pos - filePos_ <= INT_MAX);
260 gbump(static_cast<int>(pos - filePos_));
263 filePos_ = seekpos(pos);
errorT append(const char_type *s, std::streamsize count)
Writes, at the end of the file, count characters from the character array whose first element is poin...
int WriteFourBytes(uint32_t value)
Writes a 32-bit unsigned integer.
std::streamoff pubseekpos(std::streamoff pos)
Repositions the internal buffer or invoke filebuf::seekpos().
const errorT ERROR_FileWrite
int WriteOneByte(byte value)
Writes a 8-bit unsigned integer.
errorT open(const std::string &filename, fileModeT fmode)
Opens a file and store its size.
uint16_t ReadTwoBytes()
Reads a 16-bit unsigned integer.
int WriteThreeBytes(uint32_t value)
Writes a 24-bit unsigned integer.
unsigned long long size() const
Returns the size of the file.
int WriteTwoBytes(uint32_t value)
Writes a 16-bit unsigned integer.
uint32_t ReadThreeBytes()
Reads a 24-bit unsigned integer.
int pubsync()
Invokes std::filebuf::sync() to write all pending output to the file.
errorT Open(const char *filename, fileModeT fmode)
Opens a file.
byte ReadOneByte()
Reads a 8-bit unsigned integer.
const errorT ERROR_FileSeek
Optimizes std::filebuf for random-access reading.
std::streamsize sgetn(char_type *s, std::streamsize count)
Invoke filebuf::xsgetn() and update filePos_.
Adds some helper functions to std::filebuf:
uint32_t ReadFourBytes()
Reads a 32-bit unsigned integer.
const errorT ERROR_FileMode
const errorT ERROR_FileOpen
size_t getline(char *str, size_t count)
Equivalent to std::fstream::getline, but faster (no sentry [27.7.2.1.3]).