MCPcopy Create free account
hub / github.com/avast/retdec / readJsonFile

Method readJsonFile

src/config/config.cpp:80–99  ·  view source on GitHub ↗

* 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. */

Source from the content-addressed store, hash-verified

78 * @param input Path to input JSON file.
79 */
80void 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.

Callers 5

fromFileMethod · 0.80
mainFunction · 0.80
ConfigPresentationMethod · 0.80
fromFileMethod · 0.80
TEST_FFunction · 0.80

Calls 5

tellgMethod · 0.80
resizeMethod · 0.45
readMethod · 0.45
sizeMethod · 0.45

Tested by 1

TEST_FFunction · 0.64