From 33a2d946d4f39d84a62fc4a5218a8fafa3adcc6d Mon Sep 17 00:00:00 2001
From: Norihiro Watanabe <norihiro.watanabe@ufz.de>
Date: Wed, 22 Jun 2016 13:08:30 +0200
Subject: [PATCH] add FileFinder constructor taking a path and move definitions
 to cpp

---
 BaseLib/FileFinder.cpp | 66 ++++++++++++++++++++++++++++++++++++++++++
 BaseLib/FileFinder.h   | 49 +++++++------------------------
 2 files changed, 77 insertions(+), 38 deletions(-)
 create mode 100644 BaseLib/FileFinder.cpp

diff --git a/BaseLib/FileFinder.cpp b/BaseLib/FileFinder.cpp
new file mode 100644
index 00000000000..46aca453f5d
--- /dev/null
+++ b/BaseLib/FileFinder.cpp
@@ -0,0 +1,66 @@
+/**
+ * \file
+ * \author Karsten Rink
+ * \date   2010-10-26
+ * \brief  Definition of the FileFinder class.
+ *
+ * \copyright
+ * Copyright (c) 2012-2016, OpenGeoSys Community (http://www.opengeosys.org)
+ *            Distributed under a Modified BSD License.
+ *              See accompanying file LICENSE.txt or
+ *              http://www.opengeosys.org/project/license
+ *
+ */
+
+#include "FileFinder.h"
+
+#include <fstream>
+
+#include <logog/include/logog.hpp>
+
+
+namespace BaseLib
+{
+
+FileFinder::FileFinder()
+{
+    addDirectory(".");
+}
+
+FileFinder::FileFinder(std::string const& dir)
+{
+    addDirectory(".");
+    addDirectory(dir);
+}
+
+void FileFinder::addDirectory(std::string const& dir)
+{
+    if (dir.empty())
+        return;
+
+    if (dir[dir.size() - 1] != '/')
+        _directories.push_back(std::string(dir + "/"));
+    else
+        _directories.push_back(dir);
+}
+
+std::string FileFinder::getPath(std::string const& filename) const
+{
+    if (_directories.empty())
+        ERR("FileFinder::getPath(): No directories set.");
+
+    for (auto const& dir : _directories)
+    {
+        std::string testDir(dir);
+        std::ifstream is(testDir.append(filename).c_str());
+        if (is.good())
+        {
+            is.close();
+            return testDir;
+        }
+    }
+    ERR("FileFinder::getPath(): File not found.");
+    return filename;
+}
+
+} // end namespace BaseLib
diff --git a/BaseLib/FileFinder.h b/BaseLib/FileFinder.h
index e4e3af4b034..23ede19833e 100644
--- a/BaseLib/FileFinder.h
+++ b/BaseLib/FileFinder.h
@@ -15,12 +15,9 @@
 #ifndef FILEFINDER_H
 #define FILEFINDER_H
 
-#include <fstream>
 #include <string>
 #include <vector>
 
-#include "BuildInfo.h"
-#include <logog/include/logog.hpp>
 
 namespace BaseLib
 {
@@ -32,52 +29,28 @@ namespace BaseLib
 class FileFinder
 {
 public:
-    /// Constructor
-    FileFinder()
-    {
-        addDirectory(".");
-        addDirectory(BuildInfo::source_path + "/GeoLib/IO/XmlIO");
-        addDirectory(BuildInfo::source_path + "/Applications/FileIO/XmlIO");
-    }
+    /// Constructor having current directory as the search-space
+    FileFinder();
+
+    /**
+     * Construct with the given directory paths in addition to current directory
+     *
+     * @param dirs   a vector of directory paths to the search-space
+     */
+    explicit FileFinder(std::string const& dir);
 
     /**
      * \brief Adds another directory to the search-space.
      * If the given directory does not end with a slash one will be appended.
      */
-    void addDirectory(std::string const& dir)
-    {
-        if (dir.empty())
-            return;
-
-        if (dir[dir.size() - 1] != '/')
-            _directories.push_back(std::string(dir + "/"));
-        else
-            _directories.push_back(dir);
-    }
+    void addDirectory(std::string const& dir);
 
     /**
      * Given a filename, this method will return the complete path where this file can be found.
      * If the file is located in more than one of the directories in the search list, only the
      * first location will be returned.
      */
-    std::string getPath(std::string const& filename) const
-    {
-        if (_directories.empty())
-            ERR("FileFinder::getPath(): No directories set.");
-
-        for (auto it = _directories.begin(); it != _directories.end(); ++it)
-        {
-            std::string testDir(*it);
-            std::ifstream is(testDir.append(filename).c_str());
-            if (is.good())
-            {
-                is.close();
-                return testDir;
-            }
-        }
-        ERR("FileFinder::getPath(): File not found.");
-        return filename;
-    }
+    std::string getPath(std::string const& filename) const;
 
 private:
     std::vector<std::string> _directories;
-- 
GitLab