From 160e96369b0deb012ce310c311599281077cc27b Mon Sep 17 00:00:00 2001 From: bangerth Date: Thu, 19 Nov 2009 04:19:56 +0000 Subject: [PATCH] A simpler way to deal with testing a file's existence. git-svn-id: https://svn.dealii.org/trunk@20135 0785d39b-7218-0410-832d-ea1e28bc413d --- deal.II/base/source/path_search.cc | 32 ++++++++++++++---------------- 1 file changed, 15 insertions(+), 17 deletions(-) diff --git a/deal.II/base/source/path_search.cc b/deal.II/base/source/path_search.cc index 60d1ff69c0..5c3ff7ef59 100644 --- a/deal.II/base/source/path_search.cc +++ b/deal.II/base/source/path_search.cc @@ -1,8 +1,8 @@ //--------------------------------------------------------------------------- -// $Id$ +// $Id$ // Version: $Name$ // -// Copyright (C) 2005, 2006, 2007, 2008 by the deal.II authors +// Copyright (C) 2005, 2006, 2007, 2008, 2009 by the deal.II authors // // This file is subject to QPL and may not be distributed // without copyright and license information. Please refer @@ -16,7 +16,6 @@ #include #include -#include #include DEAL_II_NAMESPACE_OPEN @@ -40,7 +39,7 @@ PathSearch::initialize_classes() v.push_back(empty); v.push_back(std::string(".prm")); suffix_lists.insert(map_type(std::string("PARAMETER"), v)); - + // We cannot use the GridIn class // to query the formats, since this // would require linking with the @@ -62,29 +61,29 @@ PathSearch::get_path_list(const std::string& cls) { if (path_lists.empty()) initialize_classes(); - + // 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; } std::vector& PathSearch::get_suffix_list(const std::string& 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; } @@ -108,12 +107,12 @@ PathSearch::find (const std::string& filename, const std::vector::const_iterator endp = my_path_list.end(); std::string real_name; - + if (debug > 2) deallog << "PathSearch[" << cls << "] " << my_path_list.size() << " directories " << std::endl; - + // Try to open file for (path = my_path_list.begin(); path != endp; ++path) { @@ -121,13 +120,12 @@ PathSearch::find (const std::string& filename, if (debug > 1) deallog << "PathSearch[" << cls << "] trying " << real_name << std::endl; - FILE* fp = fopen(real_name.c_str(), open_mode); - if (fp != 0) + std::ifstream in (real_name.c_str()); + if (in) { if (debug > 0) deallog << "PathSearch[" << cls << "] opened " << real_name << std::endl; - fclose(fp); return real_name; } } @@ -147,7 +145,7 @@ PathSearch::find (const std::string& filename, << my_path_list.size() << " directories " << my_suffix_list.size() << " suffixes" << std::endl; - + for (suffix = my_suffix_list.begin(); suffix != ends; ++suffix) { try @@ -158,7 +156,7 @@ PathSearch::find (const std::string& filename, { continue; } - + } AssertThrow(false, ExcFileNotFound(filename, cls)); return std::string(""); -- 2.39.5