| 38 | namespace arm_compute |
| 39 | { |
| 40 | std::string read_file(const std::string &filename, bool binary) |
| 41 | { |
| 42 | std::string out; |
| 43 | std::ifstream fs; |
| 44 | |
| 45 | #ifndef ARM_COMPUTE_EXCEPTIONS_DISABLED |
| 46 | try |
| 47 | { |
| 48 | #endif /* ARM_COMPUTE_EXCEPTIONS_DISABLED */ |
| 49 | fs.exceptions(std::ifstream::failbit | std::ifstream::badbit); |
| 50 | std::ios_base::openmode mode = std::ios::in; |
| 51 | |
| 52 | if (binary) |
| 53 | { |
| 54 | mode |= std::ios::binary; |
| 55 | } |
| 56 | |
| 57 | fs.open(filename, mode); |
| 58 | |
| 59 | // Go to the end of the file |
| 60 | fs.seekg(0, std::ios::end); |
| 61 | // Reserve the memory required to store the file's content |
| 62 | out.reserve(fs.tellg()); |
| 63 | // Go back to the beginning of the file |
| 64 | fs.seekg(0, std::ios::beg); |
| 65 | // Copy the content of the file |
| 66 | out.assign(std::istreambuf_iterator<char>(fs), std::istreambuf_iterator<char>()); |
| 67 | #ifndef ARM_COMPUTE_EXCEPTIONS_DISABLED |
| 68 | } |
| 69 | catch (const std::ifstream::failure &e) |
| 70 | { |
| 71 | ARM_COMPUTE_ERROR_VAR("Accessing %s: %s", filename.c_str(), e.what()); |
| 72 | } |
| 73 | #endif /* ARM_COMPUTE_EXCEPTIONS_DISABLED */ |
| 74 | |
| 75 | return out; |
| 76 | } |
| 77 | |
| 78 | const std::string &string_from_channel(Channel channel) |
| 79 | { |