]> https://gitweb.dealii.org/ - dealii.git/commitdiff
Use std::ifstream instead of the detour via std::filebuf. 9894/head
authorWolfgang Bangerth <bangerth@colostate.edu>
Wed, 15 Apr 2020 14:50:12 +0000 (08:50 -0600)
committerWolfgang Bangerth <bangerth@colostate.edu>
Wed, 15 Apr 2020 14:50:12 +0000 (08:50 -0600)
While there also move an assertion.

source/base/parameter_handler.cc

index d25e89022079ae134f0d2787c66b4acae793940a..4fc7deca58ef5b1189f52e9a53a3fe7bb268271f 100644 (file)
@@ -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();

In the beginning the Universe was created. This has made a lot of people very angry and has been widely regarded as a bad move.

Douglas Adams


Typeset in Trocchi and Trocchi Bold Sans Serif.