MCPcopy Create free account
hub / github.com/KhronosGroup/glslang / ReadSpvBinaryFile

Function ReadSpvBinaryFile

gtests/TestFixture.cpp:139–163  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

137}
138
139std::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
165bool WriteFile(const std::string& path, const std::string& contents)
166{

Callers 1

tryLoadSpvFileMethod · 0.85

Calls 1

push_backMethod · 0.45

Tested by

no test coverage detected