From 788156f3656e9e387bb66bff26f8e996a76d1a04 Mon Sep 17 00:00:00 2001 From: Wolfgang Bangerth Date: Wed, 15 Apr 2020 08:50:12 -0600 Subject: [PATCH] Use std::ifstream instead of the detour via std::filebuf. While there also move an assertion. --- source/base/parameter_handler.cc | 42 +++++++++++++------------------- 1 file changed, 17 insertions(+), 25 deletions(-) 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(); -- 2.39.5