| 55 | } |
| 56 | |
| 57 | void File::loadFileContent() const |
| 58 | { |
| 59 | std::ios::openmode mode = std::ios::in | std::ios::ate; |
| 60 | if (m_binary) { |
| 61 | mode |= std::ios::binary; |
| 62 | } |
| 63 | |
| 64 | std::ifstream ifs(m_filePath, mode); |
| 65 | |
| 66 | if (ifs) |
| 67 | { |
| 68 | const std::streamsize size = static_cast<const std::streamsize>(ifs.tellg()); |
| 69 | |
| 70 | ifs.seekg(0, std::ios::beg); |
| 71 | |
| 72 | m_source.resize(size); |
| 73 | |
| 74 | ifs.read(const_cast<char*>(m_source.data()), size); |
| 75 | m_source.resize(ifs.gcount()); |
| 76 | ifs.close(); |
| 77 | |
| 78 | m_valid = true; |
| 79 | } |
| 80 | else |
| 81 | { |
| 82 | globjects::warning() << "Reading from file \"" << m_filePath << "\" failed."; |
| 83 | |
| 84 | m_source = ""; |
| 85 | |
| 86 | m_valid = false; |
| 87 | } |
| 88 | } |
| 89 | |
| 90 | |
| 91 | } // namespace globjects |