| 137 | } |
| 138 | |
| 139 | std::pair<bool, std::vector<std::uint32_t> > ReadSpvBinaryFile(const std::string& path) |
| 140 | { |
| 141 | std::ifstream fstream(path, std::fstream::in | std::fstream::binary); |
| 142 | |
| 143 | if (!fstream) |
| 144 | return std::make_pair(false, std::vector<std::uint32_t>()); |
| 145 | |
| 146 | std::vector<std::uint32_t> contents; |
| 147 | |
| 148 | // Reserve space (for efficiency, not for correctness) |
| 149 | fstream.seekg(0, fstream.end); |
| 150 | contents.reserve(size_t(fstream.tellg()) / sizeof(std::uint32_t)); |
| 151 | fstream.seekg(0, fstream.beg); |
| 152 | |
| 153 | // There is no istream iterator traversing by uint32_t, so we must loop. |
| 154 | while (!fstream.eof()) { |
| 155 | std::uint32_t inWord; |
| 156 | fstream.read((char *)&inWord, sizeof(inWord)); |
| 157 | |
| 158 | if (!fstream.eof()) |
| 159 | contents.push_back(inWord); |
| 160 | } |
| 161 | |
| 162 | return std::make_pair(true, contents); // hopefully, c++11 move semantics optimizes the copy away. |
| 163 | } |
| 164 | |
| 165 | bool WriteFile(const std::string& path, const std::string& contents) |
| 166 | { |
no test coverage detected