]> https://gitweb.dealii.org/ - dealii-svn.git/commitdiff
A simpler way to deal with testing a file's existence.
authorbangerth <bangerth@0785d39b-7218-0410-832d-ea1e28bc413d>
Thu, 19 Nov 2009 04:19:56 +0000 (04:19 +0000)
committerbangerth <bangerth@0785d39b-7218-0410-832d-ea1e28bc413d>
Thu, 19 Nov 2009 04:19:56 +0000 (04:19 +0000)
git-svn-id: https://svn.dealii.org/trunk@20135 0785d39b-7218-0410-832d-ea1e28bc413d

deal.II/base/source/path_search.cc

index 60d1ff69c0e7f9a0b3cb3c4df6d377a1ba3592f1..5c3ff7ef591087dfeef2d5bd986db35909113ecd 100644 (file)
@@ -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 <base/utilities.h>
 
 #include <iostream>
-#include <cstdio>
 #include <algorithm>
 
 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<std::string>&
 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<std::string>::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("");

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.