* Reads JSON file into internal representation. * If file can not be opened, an instance of @c FileNotFoundException is thrown. * If file can not be parsed, an instance of @c ParseException is thrown. * @param input Path to input JSON file. */
| 78 | * @param input Path to input JSON file. |
| 79 | */ |
| 80 | void Config::readJsonFile(const std::string& input) |
| 81 | { |
| 82 | // The reading of the input file is based on |
| 83 | // http://insanecoding.blogspot.cz/2011/11/how-to-read-in-file-in-c.html |
| 84 | std::ifstream jsonFile(input, std::ios::in | std::ios::binary); |
| 85 | if (!jsonFile) |
| 86 | { |
| 87 | std::string msg = "Input file \"" + input + "\" can not be opened."; |
| 88 | throw FileNotFoundException(msg); |
| 89 | } |
| 90 | |
| 91 | std::string jsonContent; |
| 92 | jsonFile.seekg(0, std::ios::end); |
| 93 | jsonContent.resize(jsonFile.tellg()); |
| 94 | jsonFile.seekg(0, std::ios::beg); |
| 95 | jsonFile.read(&jsonContent[0], jsonContent.size()); |
| 96 | jsonFile.close(); |
| 97 | |
| 98 | readJsonString(jsonContent); |
| 99 | } |
| 100 | |
| 101 | /** |
| 102 | * Generates JSON configuration file. |