From: Wolfgang Bangerth Date: Wed, 15 Apr 2020 14:50:12 +0000 (-0600) Subject: Use std::ifstream instead of the detour via std::filebuf. X-Git-Tag: v9.2.0-rc1~228^2 X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=788156f3656e9e387bb66bff26f8e996a76d1a04;p=dealii.git Use std::ifstream instead of the detour via std::filebuf. While there also move an assertion. --- diff --git a/source/base/parameter_handler.cc b/source/base/parameter_handler.cc index d25e890220..4fc7deca58 100644 --- a/source/base/parameter_handler.cc +++ b/source/base/parameter_handler.cc @@ -513,32 +513,24 @@ ParameterHandler::parse_input(const std::string &filename, const bool skip_undefined, const bool assert_mandatory_entries_are_found) { - std::filebuf fb; - if (fb.open(filename, std::ios::in)) - { - std::istream is(&fb); - std::string file_ending = filename.substr(filename.find_last_of('.') + 1); - boost::algorithm::to_lower(file_ending); - if (file_ending == "prm") - parse_input(is, filename, last_line, skip_undefined); - else if (file_ending == "xml") - parse_input_from_xml(is, skip_undefined); - else if (file_ending == "json") - parse_input_from_json(is, skip_undefined); - else - AssertThrow( - false, - ExcMessage( - "Unknown input file. Supported types are .prm, .xml, and .json.")); - - fb.close(); - } + std::ifstream is(filename); + AssertThrow(is, + ExcMessage("Invalid filename " + filename + + " provided. File does not exist or " + "can not be read from.")); + + std::string file_ending = filename.substr(filename.find_last_of('.') + 1); + boost::algorithm::to_lower(file_ending); + if (file_ending == "prm") + parse_input(is, filename, last_line, skip_undefined); + else if (file_ending == "xml") + parse_input_from_xml(is, skip_undefined); + else if (file_ending == "json") + parse_input_from_json(is, skip_undefined); else - { - AssertThrow(false, - ExcMessage("Invalid filename " + filename + - " provided. File does not exist.")); - } + AssertThrow(false, + ExcMessage("Unknown input file name extension. Supported types " + "are .prm, .xml, and .json.")); if (assert_mandatory_entries_are_found) assert_that_entries_have_been_set();