| 256 | } |
| 257 | |
| 258 | static 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 | |
| 284 | int checkVersionAndFindIndex(const char *filename, const char *k) { |
| 285 | char version = 0; |
no test coverage detected