From 9b27e5c33d8c09b7d64d5eff91a7b89d4c3e4934 Mon Sep 17 00:00:00 2001 From: Christoph Lehmann <christoph.lehmann@ufz.de> Date: Wed, 7 Nov 2018 10:45:41 +0100 Subject: [PATCH] Made project directory accessible via global functions. --- Applications/CLI/ogs.cpp | 5 ++++- BaseLib/FileTools.cpp | 28 ++++++++++++++++++++++++++++ BaseLib/FileTools.h | 6 ++++++ 3 files changed, 38 insertions(+), 1 deletion(-) diff --git a/Applications/CLI/ogs.cpp b/Applications/CLI/ogs.cpp index 1a8183b377e..777b455e028 100644 --- a/Applications/CLI/ogs.cpp +++ b/Applications/CLI/ogs.cpp @@ -166,8 +166,11 @@ int main(int argc, char* argv[]) project_arg.getValue(), !nonfatal_arg.getValue(), "OpenGeoSysProject"); + BaseLib::setProjectDirectory( + BaseLib::extractPath(project_arg.getValue())); + ProjectData project(*project_config, - BaseLib::extractPath(project_arg.getValue()), + BaseLib::getProjectDirectory(), outdir_arg.getValue()); #ifdef USE_INSITU diff --git a/BaseLib/FileTools.cpp b/BaseLib/FileTools.cpp index 7a50c5e6cc0..b1c1a9c3e0e 100644 --- a/BaseLib/FileTools.cpp +++ b/BaseLib/FileTools.cpp @@ -19,6 +19,15 @@ #include <sys/stat.h> #include <boost/algorithm/string.hpp> +namespace +{ +/// The directory where the prj file resides. +static std::string project_directory = ""; + +/// Whether the project directory has already been set. +static bool project_directory_is_set = false; +} // anonymous namespace + namespace BaseLib { /** @@ -176,4 +185,23 @@ std::string joinPaths(std::string const& pathA, std::string const& pathB) return appendPathSeparator(pathA) + pathB; } +std::string const& getProjectDirectory() +{ + if (!project_directory_is_set) + { + OGS_FATAL("The project directory has not yet been set."); + } + return project_directory; +} + +void setProjectDirectory(std::string const& dir) +{ + if (project_directory_is_set) + { + OGS_FATAL("The project directory has already been set."); + } + project_directory = dir; + project_directory_is_set = true; +} + } // end namespace BaseLib diff --git a/BaseLib/FileTools.h b/BaseLib/FileTools.h index b3a2c9ec0d0..7ba0820d6fb 100644 --- a/BaseLib/FileTools.h +++ b/BaseLib/FileTools.h @@ -161,4 +161,10 @@ std::string appendPathSeparator(std::string const& path); */ std::string joinPaths(std::string const& pathA, std::string const& pathB); +/// Returns the directory where the prj file resides. +std::string const& getProjectDirectory(); + +/// Sets the project directory. +void setProjectDirectory(std::string const& dir); + } // end namespace BaseLib -- GitLab