* 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
{
*/
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
{
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;
}
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;
}
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)