| 21 | struct file_wrapper |
| 22 | { |
| 23 | file_wrapper(std::string const& name, std::ios_base::openmode mode) |
| 24 | : stream_(name.c_str(), mode) |
| 25 | , mode_(mode) |
| 26 | { |
| 27 | if (!stream_.is_open()) |
| 28 | throw std::runtime_error("Couldn't open file: " + name); |
| 29 | |
| 30 | std::fstream::pos_type fsize = stream_.tellg(); |
| 31 | stream_.seekg(0, std::ios::end); |
| 32 | data_.resize(stream_.tellg() - fsize); |
| 33 | stream_.seekg(fsize, std::ios::beg); |
| 34 | |
| 35 | if (mode & std::ios_base::in) |
| 36 | { |
| 37 | stream_.read(data_.data(), data_.size()); |
| 38 | } |
| 39 | } |
| 40 | |
| 41 | ~file_wrapper() |
| 42 | { |