From: luca Date: Fri, 29 Jul 2005 20:59:30 +0000 (+0000) Subject: Added close() method. Modified construction such that now a new class is X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=5da0491fbdd0c1e9e519bb9adfc56933c42ffdfc;p=dealii-svn.git Added close() method. Modified construction such that now a new class is added if the constructor is called with an unknown class. git-svn-id: https://svn.dealii.org/trunk@11220 0785d39b-7218-0410-832d-ea1e28bc413d --- diff --git a/deal.II/base/include/base/path_search.h b/deal.II/base/include/base/path_search.h index cc7b26f8f7..3d3ca556b4 100644 --- a/deal.II/base/include/base/path_search.h +++ b/deal.II/base/include/base/path_search.h @@ -70,10 +70,14 @@ * trailing "/", while suffixes should always start with a * dot. These characters are not added automatically (allowing you to * do some real file name editing). + * + * If you want to open another file with the same object, the previous + * one is automatically closed for you. The close() method is needed + * only if you need to open the same file externally. * * @todo Add support for environment variables like in kpathsea. * - * @author Guido Kanschat, 2005 + * @author Guido Kanschat, Luca Heltai 2005 */ class PathSearch { @@ -117,6 +121,18 @@ class PathSearch */ std::istream& open (const std::string& filename, const std::string& suffix); + + /** Explicitly close the file + opened by the previous call + to one of the open() + functions. This is needed + only if you need to open the + same file externally. Opening + another file with the same + PathSearch object + automatically closes the old + one. */ + void close(); /** * Return the actual name of the diff --git a/deal.II/base/source/path_search.cc b/deal.II/base/source/path_search.cc index a7998c8659..95768ae65e 100644 --- a/deal.II/base/source/path_search.cc +++ b/deal.II/base/source/path_search.cc @@ -52,8 +52,12 @@ PathSearch::get_path_list(const std::string& cls) { if (path_lists.empty()) initialize_classes(); - - Assert(path_lists.count(cls) != 0, ExcNoClass(cls)); + + // Modified by Luca Heltai. If a class is not there, add it + if(path_lists.count(cls) == 0) add_class(cls); + + // Assert(path_lists.count(cls) != 0, ExcNoClass(cls)); + Assert(path_lists.count(cls) != 0, ExcInternalError()); return path_lists.find(cls)->second; } @@ -61,8 +65,15 @@ PathSearch::get_path_list(const std::string& cls) std::vector& PathSearch::get_suffix_list(const std::string& cls) -{ - Assert(suffix_lists.count(cls) != 0, ExcNoClass(cls)); +{ + // This is redundant. The constructor should have already called the + // add_path function with the path_list bit... + + // Modified by Luca Heltai. If a class is not there, add it + if(suffix_lists.count(cls) == 0) add_class(cls); + + // Assert(suffix_lists.count(cls) != 0, ExcNoClass(cls)); + Assert(suffix_lists.count(cls) != 0, ExcInternalError()); return suffix_lists.find(cls)->second; } @@ -127,6 +138,20 @@ PathSearch::open (const std::string& filename, return *stream; } +void +PathSearch::close() +{ + if(stream->is_open()) { + stream->close(); + if (debug > 0) + deallog << "PathSearch[" << cls << "] closed " + << real_name << std::endl; + } else { + if (debug > 0) + deallog << "PathSearch[" << cls + << "] nothing opened" << std::endl; + } +} std::istream& PathSearch::open (const std::string& filename)