diff --git a/Applications/FileIO/XmlIO/Qt/XmlGspInterface.cpp b/Applications/FileIO/XmlIO/Qt/XmlGspInterface.cpp index a41eab63349e2e23de4113c03317a1d4a6d5a934..0637656341bbf99e8b368f3f67c78a6d1db81d82 100644 --- a/Applications/FileIO/XmlIO/Qt/XmlGspInterface.cpp +++ b/Applications/FileIO/XmlIO/Qt/XmlGspInterface.cpp @@ -18,29 +18,31 @@ #include <vector> #include <logog/include/logog.hpp> +#include <QFile> +#include <QFileInfo> +#include <QtXml/QDomDocument> + +#include "BaseLib/BuildInfo.h" +#include "BaseLib/FileTools.h" +#include "BaseLib/FileFinder.h" +#include "BaseLib/IO/Writer.h" #include "GeoLib/GEOObjects.h" #include "GeoLib/IO/XmlIO/Qt/XmlGmlInterface.h" #include "GeoLib/IO/XmlIO/Qt/XmlStnInterface.h" -#include "BaseLib/FileTools.h" -#include "BaseLib/FileFinder.h" -#include "BaseLib/IO/Writer.h" #include "MeshLib/IO/Legacy/MeshIO.h" #include "MeshLib/IO/readMeshFromFile.h" #include "MeshLib/Mesh.h" -#include <QFile> -#include <QFileInfo> -#include <QtXml/QDomDocument> namespace FileIO { XmlGspInterface::XmlGspInterface(DataHolderLib::Project& project) -: XMLInterface(), XMLQtInterface(BaseLib::FileFinder().getPath("OpenGeoSysProject.xsd")), +: XMLInterface(), XMLQtInterface(BaseLib::FileFinder({BaseLib::BuildInfo::app_xml_schema_path}).getPath("OpenGeoSysProject.xsd")), _project(project) { } diff --git a/Applications/FileIO/XmlIO/Qt/XmlNumInterface.cpp b/Applications/FileIO/XmlIO/Qt/XmlNumInterface.cpp index 26c8c5bd217a1a8a8c16f34b722176a452d9a7f9..f90ddb7edaa1d866da2bb63e6226cc46653709d8 100644 --- a/Applications/FileIO/XmlIO/Qt/XmlNumInterface.cpp +++ b/Applications/FileIO/XmlIO/Qt/XmlNumInterface.cpp @@ -20,13 +20,14 @@ #include <logog/include/logog.hpp> +#include "BaseLib/BuildInfo.h" #include "BaseLib/FileFinder.h" namespace FileIO { XmlNumInterface::XmlNumInterface() : - XMLInterface(), XMLQtInterface(BaseLib::FileFinder().getPath("OpenGeoSysNUM.xsd")) +XMLInterface(), XMLQtInterface(BaseLib::FileFinder({BaseLib::BuildInfo::app_xml_schema_path}).getPath("OpenGeoSysNUM.xsd")) { } diff --git a/BaseLib/BuildInfo.cpp.in b/BaseLib/BuildInfo.cpp.in index 20bd9ba5f81c3beab06727c246e63732eb835c05..1ca7d040f42c62495e0609a00f10705394768595 100644 --- a/BaseLib/BuildInfo.cpp.in +++ b/BaseLib/BuildInfo.cpp.in @@ -31,6 +31,8 @@ namespace BuildInfo const std::string ogs_version("@OGS_VERSION@"); const std::string source_path("@CMAKE_CURRENT_SOURCE_DIR@"); + const std::string geo_xml_schema_path("@CMAKE_CURRENT_SOURCE_DIR@/GeoLib/IO/XmlIO"); + const std::string app_xml_schema_path("@CMAKE_CURRENT_SOURCE_DIR@/Applications/FileIO/XmlIO"); const std::string data_path("@Data_SOURCE_DIR@"); const std::string data_binary_path("@Data_BINARY_DIR@"); const std::string tests_tmp_path("@PROJECT_BINARY_DIR@/Tests/"); diff --git a/BaseLib/BuildInfo.h b/BaseLib/BuildInfo.h index 5f55223a8838363a4d81cdcd36d9b451ba53b57f..85624410c49298259ef74277f7b7a165333ceb4a 100644 --- a/BaseLib/BuildInfo.h +++ b/BaseLib/BuildInfo.h @@ -33,6 +33,8 @@ namespace BuildInfo extern const std::string ogs_version; extern const std::string source_path; + extern const std::string geo_xml_schema_path; + extern const std::string app_xml_schema_path; extern const std::string data_path; extern const std::string data_binary_path; extern const std::string tests_tmp_path; diff --git a/BaseLib/FileFinder.cpp b/BaseLib/FileFinder.cpp new file mode 100644 index 0000000000000000000000000000000000000000..dde0f1299d2e928c7a527b1b99ce03613107a839 --- /dev/null +++ b/BaseLib/FileFinder.cpp @@ -0,0 +1,67 @@ +/** + * \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::initializer_list<std::string> dirs) +{ + addDirectory("."); + for (auto const& dir : dirs) + 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 e4e3af4b034bea2c009166fae907334b273fb236..814f27883b545d039e898c26a1961316c6a01cfe 100644 --- a/BaseLib/FileFinder.h +++ b/BaseLib/FileFinder.h @@ -15,12 +15,10 @@ #ifndef FILEFINDER_H #define FILEFINDER_H -#include <fstream> +#include <initializer_list> #include <string> #include <vector> -#include "BuildInfo.h" -#include <logog/include/logog.hpp> namespace BaseLib { @@ -32,52 +30,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 an initializer list of additional directory paths to the search-space + */ + FileFinder(std::initializer_list<std::string> dirs); /** * \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; diff --git a/GeoLib/IO/XmlIO/Qt/XmlGmlInterface.cpp b/GeoLib/IO/XmlIO/Qt/XmlGmlInterface.cpp index 9279af2781e117ecbe2d08cba1fbf4caf29c5b41..df86ca8dcda2de1a0fe36891e6609492637c86e0 100644 --- a/GeoLib/IO/XmlIO/Qt/XmlGmlInterface.cpp +++ b/GeoLib/IO/XmlIO/Qt/XmlGmlInterface.cpp @@ -20,6 +20,7 @@ #include <logog/include/logog.hpp> +#include "BaseLib/BuildInfo.h" #include "BaseLib/FileFinder.h" #include "GeoLib/Triangle.h" @@ -28,7 +29,7 @@ namespace GeoLib namespace IO { XmlGmlInterface::XmlGmlInterface(GeoLib::GEOObjects& geo_objs) : - XMLInterface(), XMLQtInterface(BaseLib::FileFinder().getPath("OpenGeoSysGLI.xsd")), _geo_objs(geo_objs) +XMLInterface(), XMLQtInterface(BaseLib::FileFinder({BaseLib::BuildInfo::geo_xml_schema_path}).getPath("OpenGeoSysGLI.xsd")), _geo_objs(geo_objs) { } diff --git a/GeoLib/IO/XmlIO/Qt/XmlStnInterface.cpp b/GeoLib/IO/XmlIO/Qt/XmlStnInterface.cpp index 43d2a7eb33e2455d0be54bbd9a556bfebec9e3e3..adcef0e0a8dcf49dca233ba60ad7f5f10248e324 100644 --- a/GeoLib/IO/XmlIO/Qt/XmlStnInterface.cpp +++ b/GeoLib/IO/XmlIO/Qt/XmlStnInterface.cpp @@ -21,6 +21,7 @@ #include <logog/include/logog.hpp> +#include "BaseLib/BuildInfo.h" #include "BaseLib/DateTools.h" #include "BaseLib/FileTools.h" #include "BaseLib/FileFinder.h" @@ -33,7 +34,7 @@ namespace GeoLib namespace IO { XmlStnInterface::XmlStnInterface(GeoLib::GEOObjects& geo_objs) : - XMLInterface(), XMLQtInterface(BaseLib::FileFinder().getPath("OpenGeoSysSTN.xsd")), _geo_objs(geo_objs) +XMLInterface(), XMLQtInterface(BaseLib::FileFinder({BaseLib::BuildInfo::geo_xml_schema_path}).getPath("OpenGeoSysSTN.xsd")), _geo_objs(geo_objs) { }