MCPcopy Create free account
hub / github.com/arrayfire/arrayfire / checkVersionAndRead

Function checkVersionAndRead

src/api/c/stream.cpp:258–282  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

256}
257
258static af_array checkVersionAndRead(const char *filename,
259 const unsigned index) {
260 char version = 0;
261
262 std::string filenameStr = std::string(filename);
263 std::fstream fs(filenameStr, std::fstream::in | std::fstream::binary);
264 // Throw exception if file is not open
265 if (!fs.is_open()) {
266 std::string errStr = "Failed to open: " + filenameStr;
267 AF_ERROR(errStr.c_str(), AF_ERR_ARG);
268 }
269
270 if (fs.peek() == std::fstream::traits_type::eof()) {
271 std::string errStr = filenameStr + " is empty";
272 AF_ERROR(errStr.c_str(), AF_ERR_ARG);
273 } else {
274 fs.read(&version, sizeof(char));
275 }
276 fs.close();
277
278 switch (version) { // NOLINT(hicpp-multiway-paths-covered)
279 case 1: return readArrayV1(filename, index);
280 default: AF_ERROR("Invalid version", AF_ERR_ARG);
281 }
282}
283
284int checkVersionAndFindIndex(const char *filename, const char *k) {
285 char version = 0;

Callers 2

af_read_array_indexFunction · 0.85
af_read_array_keyFunction · 0.85

Calls 2

readArrayV1Function · 0.85
closeMethod · 0.80

Tested by

no test coverage detected