]> https://gitweb.dealii.org/ - dealii-svn.git/commitdiff
Added close() method. Modified construction such that now a new class is
authorluca <luca@0785d39b-7218-0410-832d-ea1e28bc413d>
Fri, 29 Jul 2005 20:59:30 +0000 (20:59 +0000)
committerluca <luca@0785d39b-7218-0410-832d-ea1e28bc413d>
Fri, 29 Jul 2005 20:59:30 +0000 (20:59 +0000)
added if the constructor is called with an unknown class.

git-svn-id: https://svn.dealii.org/trunk@11220 0785d39b-7218-0410-832d-ea1e28bc413d

deal.II/base/include/base/path_search.h
deal.II/base/source/path_search.cc

index cc7b26f8f74f906718711fe0ef6a7e58c4bae151..3d3ca556b447bc037b3f2e380c1a814b7efd0fac 100644 (file)
  * trailing <tt>"/"</tt>, 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
index a7998c865950e68d3b27776647cf1c47cb20fc8f..95768ae65e36c57bf831c4ca6dff8d48b7662f74 100644 (file)
@@ -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<std::string>&
 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)

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.