From 681bfc71edf6c3721109bd0f263b33c92ec3ba2e Mon Sep 17 00:00:00 2001 From: Denis Demidov Date: Sat, 17 Jul 2021 08:01:15 +0300 Subject: [PATCH] Make sure mm_reader works on windows --- amgcl/io/mm.hpp | 17 +++++------------ 1 file changed, 5 insertions(+), 12 deletions(-) diff --git a/amgcl/io/mm.hpp b/amgcl/io/mm.hpp index 84fc709d..d97af284 100644 --- a/amgcl/io/mm.hpp +++ b/amgcl/io/mm.hpp @@ -52,11 +52,10 @@ namespace io { class mm_reader { public: /// Open the file by name - mm_reader(const std::string &fname) : f(fname.c_str()) { + mm_reader(const std::string &fname) : f(fname) { precondition(f, "Failed to open file \"" + fname + "\""); // Read banner. - std::string line; precondition(std::getline(f, line), format_error()); std::istringstream is(line); @@ -99,16 +98,11 @@ class mm_reader { } // Skip comments. - std::streampos pos; do { - pos = f.tellg(); precondition(std::getline(f, line), format_error("unexpected eof")); } while (line[0] == '%'); - // Get back to the first non-comment line. - f.seekg(pos); - - // Read matrix size + // The last line is comment-free and holds the matrix sizes is.clear(); is.str(line); precondition(is >> nrows >> ncols, format_error()); } @@ -156,10 +150,9 @@ class mm_reader { // Read sizes ptrdiff_t n, m; size_t nnz; - std::string line; std::istringstream is; { - precondition(std::getline(f, line), format_error("unexpected eof")); + // line already holds the matrix sizes is.clear(); is.str(line); precondition(is >> n >> m >> nnz, format_error()); } @@ -265,10 +258,9 @@ class mm_reader { // Read sizes ptrdiff_t n, m; - std::string line; std::istringstream is; { - precondition(std::getline(f, line), format_error("unexpected eof")); + // line already holds the matrix sizes is.clear(); is.str(line); precondition(is >> n >> m, format_error()); } @@ -295,6 +287,7 @@ class mm_reader { } private: std::ifstream f; + std::string line; bool _sparse; bool _symmetric;