diff --git a/libpwrutils/pathsearch.cpp b/libpwrutils/pathsearch.cpp index 15f4e998c827d1df2ef1692f9fde71ff14869cbe..1584d79a14af76d3011954dbd30ca505260a00c9 100644 --- a/libpwrutils/pathsearch.cpp +++ b/libpwrutils/pathsearch.cpp @@ -72,7 +72,7 @@ const std::string& PathSearcherBase::get_path_separator() const } std::string PathSearcherBase::find_file(const std::string& filename, - const std::string& info) + const std::string& info) const { boost::filesystem::path i(filename); if (i.is_complete()) { @@ -101,7 +101,7 @@ std::string PathSearcherBase::find_file(const std::string& filename, } bool PathSearcherBase::open_stream(const std::string& filename, - std::ifstream& ifs, const std::string& info) + std::ifstream& ifs, const std::string& info) const { std::string f = find_file(filename, info); if (!f.empty()) { diff --git a/libpwrutils/pathsearch.h b/libpwrutils/pathsearch.h index 956f68deab9b0282b4b33d5a72c408495a9626a0..c33aaa7e677b5d84bd2f12bfeb71295b90a5b4a7 100644 --- a/libpwrutils/pathsearch.h +++ b/libpwrutils/pathsearch.h @@ -73,7 +73,7 @@ public: * is on. Empty info string suppreses loading info. */ std::string find_file(const std::string& filename, - const std::string& info = ""); + const std::string& info = "") const; /** * Open a file stream for a file in the library search path @@ -83,7 +83,22 @@ public: * is on. Empty info string suppreses loading info. */ bool open_stream(const std::string& filename, std::ifstream& ifs, - const std::string& info = ""); + const std::string& info = "") const; + + /** + * Convenience wrapper around find_file to throw an exception + * when the file is not found. + * Virtual, as it throws the exception defined by the child class. + */ + virtual std::string find_file_or_throw(const std::string& filename, + const std::string& where) const = 0; + + /** + * Wrapper around open_stream to throw an exception when the file is not + * found. Virtual, as it throws the exception defined by the child class. + */ + virtual void open_stream_or_throw(const std::string& filename, + std::ifstream& ifs, const std::string& where) const = 0; /** * Look for files matching a condition. @@ -122,14 +137,14 @@ public: * when the file is not found. */ std::string find_file_or_throw(const std::string& filename, - const std::string& where); + const std::string& where) const; /** * Convenience template wrapper around open_stream to throw an * exception when the file is not found. */ void open_stream_or_throw(const std::string& filename, - std::ifstream& ifs, const std::string& where); + std::ifstream& ifs, const std::string& where) const; }; @@ -158,7 +173,7 @@ private: template<class E> std::string PathSearcher<E>::find_file_or_throw( - const std::string& filename, const std::string& info) + const std::string& filename, const std::string& info) const { std::string fn = find_file(filename, info); if (fn.empty()) { @@ -169,7 +184,7 @@ std::string PathSearcher<E>::find_file_or_throw( template<class E> void PathSearcher<E>::open_stream_or_throw(const std::string& filename, - std::ifstream& ifs, const std::string& info) + std::ifstream& ifs, const std::string& info) const { if (!open_stream(filename, ifs, info)) { throw E(filename, get_search_path_string(), info);