feat!: Migrate to std::filesystem consistently

This commit is contained in:
Dennis Klein
2023-02-13 14:12:38 +01:00
committed by Dennis Klein
parent f2dce91098
commit 05b734ee0d
10 changed files with 123 additions and 40 deletions

View File

@@ -197,7 +197,7 @@ if(BUILD_FAIRMQ)
$<$<PLATFORM_ID:Linux>:rt>
Boost::boost
Boost::program_options
Boost::filesystem
Boost::filesystem # still needed for Boost.DLL
Boost::regex
FairLogger::FairLogger

View File

@@ -22,7 +22,6 @@ using namespace std;
using fair::mq::Plugin;
using fair::mq::tools::ToString;
using fair::mq::tools::ToStrVector;
namespace fs = boost::filesystem;
namespace po = boost::program_options;
namespace dll = boost::dll;
using boost::optional;
@@ -171,7 +170,7 @@ auto fair::mq::PluginManager::LoadPluginPrelinkedDynamic(const string& pluginNam
}
auto fair::mq::PluginManager::SearchPluginFile(const string& pluginName) const
-> boost::filesystem::path
-> fs::path
{
for (const auto& searchPath : SearchPaths()) {
for (const auto& libPrefix : {fgkLibPrefix, fgkLibPrefixAlt}) {
@@ -181,7 +180,7 @@ auto fair::mq::PluginManager::SearchPluginFile(const string& pluginName) const
libPrefix,
pluginName,
boost::dll::detail::shared_library_impl::suffix().native());
auto const found = boost::filesystem::exists(file);
auto const found = fs::exists(file);
if (found) {
return file;
}

View File

@@ -1,5 +1,5 @@
/********************************************************************************
* Copyright (C) 2017 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH *
* Copyright (C) 2017-2023 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH *
* *
* This software is distributed under the terms of the *
* GNU Lesser General Public Licence (LGPL) version 3, *
@@ -13,9 +13,16 @@
#include <fairmq/PluginServices.h>
#include <fairmq/tools/Strings.h>
#if FAIRMQ_HAS_STD_FILESYSTEM
#include <filesystem>
namespace fs = std::filesystem;
#else
#define BOOST_FILESYSTEM_VERSION 3
#define BOOST_FILESYSTEM_NO_DEPRECATED
#include <boost/filesystem.hpp>
namespace fs = ::boost::filesystem;
#endif
#include <boost/optional.hpp>
#include <boost/program_options.hpp>
#include <boost/dll/import.hpp>
@@ -60,13 +67,13 @@ class PluginManager
LOG(debug) << "Shutting down Plugin Manager";
}
auto SetSearchPaths(const std::vector<boost::filesystem::path>&) -> void;
auto AppendSearchPath(const boost::filesystem::path&) -> void;
auto PrependSearchPath(const boost::filesystem::path&) -> void;
auto SearchPaths() const -> const std::vector<boost::filesystem::path>& { return fSearchPaths; }
auto SetSearchPaths(const std::vector<fs::path>&) -> void;
auto AppendSearchPath(const fs::path&) -> void;
auto PrependSearchPath(const fs::path&) -> void;
auto SearchPaths() const -> const std::vector<fs::path>& { return fSearchPaths; }
struct BadSearchPath : std::invalid_argument { using std::invalid_argument::invalid_argument; };
auto SearchPluginFile(const std::string&) const -> boost::filesystem::path;
auto SearchPluginFile(const std::string&) const -> fs::path;
struct PluginNotFound : std::runtime_error { using std::runtime_error::runtime_error; };
auto LoadPlugin(const std::string& pluginName) -> void;
auto LoadPlugins(const std::vector<std::string>& pluginNames) -> void { for(const auto& pluginName : pluginNames) { LoadPlugin(pluginName); } }
@@ -88,18 +95,33 @@ class PluginManager
auto WaitForPluginsToReleaseDeviceControl() -> void { fPluginServices->WaitForReleaseDeviceControl(); }
private:
static auto ValidateSearchPath(const boost::filesystem::path&) -> void;
static auto ValidateSearchPath(const fs::path&) -> void;
auto LoadPluginPrelinkedDynamic(const std::string& pluginName) -> void;
auto LoadPluginDynamic(const std::string& pluginName) -> void;
auto LoadPluginStatic(const std::string& pluginName) -> void;
template<typename... Args>
auto LoadSymbols(const std::string& pluginName, Args&&... args) -> void
#if FAIRMQ_HAS_STD_FILESYSTEM
template<typename T>
static auto AdaptPathType(T&& path)
{
if constexpr(std::is_same_v<T, std::filesystem::path>) {
return boost::filesystem::path(std::forward<T>(path));
} else {
return std::forward<T>(path);
}
}
#endif
template<typename FirstArg, typename... Args>
auto LoadSymbols(const std::string& pluginName, FirstArg&& farg, Args&&... args) -> void
{
using namespace boost::dll;
using fair::mq::tools::ToString;
auto lib = shared_library{std::forward<Args>(args)...};
#if FAIRMQ_HAS_STD_FILESYSTEM
auto lib = shared_library{AdaptPathType(std::forward<FirstArg>(farg)), std::forward<Args>(args)...};
#else
auto lib = shared_library{std::forward<FirstArg>(farg), std::forward<Args>(args)...};
#endif
fgDLLKeepAlive.push_back(lib);
fPluginFactories[pluginName] = import_alias<PluginFactory>(
@@ -121,7 +143,7 @@ class PluginManager
static const std::string fgkLibPrefix;
static const std::string fgkLibPrefixAlt;
std::vector<boost::filesystem::path> fSearchPaths;
std::vector<fs::path> fSearchPaths;
static std::vector<boost::dll::shared_library> fgDLLKeepAlive; // NOLINT(cppcoreguidelines-avoid-non-const-global-variables)
std::map<std::string, std::function<PluginFactory>> fPluginFactories;
std::unique_ptr<PluginServices> fPluginServices;

View File

@@ -1,5 +1,5 @@
/********************************************************************************
* Copyright (C) 2014-2018 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH *
* Copyright (C) 2014-2023 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH *
* *
* This software is distributed under the terms of the *
* GNU Lesser General Public Licence (LGPL) version 3, *
@@ -8,7 +8,15 @@
#include <fairmq/Properties.h>
#if FAIRMQ_HAS_STD_FILESYSTEM
#include <filesystem>
namespace fs = std::filesystem;
#else
#define BOOST_FILESYSTEM_VERSION 3
#define BOOST_FILESYSTEM_NO_DEPRECATED
#include <boost/filesystem.hpp>
namespace fs = ::boost::filesystem;
#endif
using namespace std;
using boost::any_cast;
@@ -84,7 +92,12 @@ unordered_map<type_index, function<pair<string, string>(const Property&)>> Prope
{ type_index(typeid(long double)), [](const Property& p) { return getStringPair<long double>(p, "long double"); } },
{ type_index(typeid(bool)), [](const Property& p) { stringstream ss; ss << boolalpha << any_cast<bool>(p); return pair<string, string>{ ss.str(), "bool" }; } },
{ type_index(typeid(vector<bool>)), [](const Property& p) { stringstream ss; ss << boolalpha << any_cast<vector<bool>>(p); return pair<string, string>{ ss.str(), "vector<bool>>" }; } },
{ type_index(typeid(boost::filesystem::path)), [](const Property& p) { return getStringPair<boost::filesystem::path>(p, "boost::filesystem::path"); } },
{ type_index(typeid(fs::path)), [](const Property& p) { return getStringPair<fs::path>(p,
#if FAIRMQ_HAS_STD_FILESYSTEM
"std::filesystem::path"); } },
#else
"boost::filesystem::path"); } },
#endif
{ type_index(typeid(vector<char>)), [](const Property& p) { return getStringPair<vector<char>>(p, "vector<char>"); } },
{ type_index(typeid(vector<signed char>)), [](const Property& p) { return getStringPair<vector<signed char>>(p, "vector<signed char>"); } },
{ type_index(typeid(vector<unsigned char>)), [](const Property& p) { return getStringPair<vector<unsigned char>>(p, "vector<unsigned char>"); } },
@@ -100,7 +113,12 @@ unordered_map<type_index, function<pair<string, string>(const Property&)>> Prope
{ type_index(typeid(vector<float>)), [](const Property& p) { return getStringPair<vector<float>>(p, "vector<float>"); } },
{ type_index(typeid(vector<double>)), [](const Property& p) { return getStringPair<vector<double>>(p, "vector<double>"); } },
{ type_index(typeid(vector<long double>)), [](const Property& p) { return getStringPair<vector<long double>>(p, "vector<long double>"); } },
{ type_index(typeid(vector<boost::filesystem::path>)), [](const Property& p) { return getStringPair<vector<boost::filesystem::path>>(p, "vector<boost::filesystem::path>"); } },
{ type_index(typeid(vector<fs::path>)), [](const Property& p) { return getStringPair<vector<fs::path>>(p,
#if FAIRMQ_HAS_STD_FILESYSTEM
"vector<std::filesystem::path>"); } },
#else
"vector<boost::filesystem::path>"); } },
#endif
};
unordered_map<type_index, void(*)(const EventManager&, const string&, const Property&)> PropertyHelper::fEventEmitters = {
@@ -122,7 +140,7 @@ unordered_map<type_index, void(*)(const EventManager&, const string&, const Prop
{ type_index(typeid(long double)), [](const EventManager& em, const string& k, const Property& p) { em.Emit<PropertyChange, long double>(k, any_cast<long double>(p)); } },
{ type_index(typeid(bool)), [](const EventManager& em, const string& k, const Property& p) { em.Emit<PropertyChange, bool>(k, any_cast<bool>(p)); } },
{ type_index(typeid(vector<bool>)), [](const EventManager& em, const string& k, const Property& p) { em.Emit<PropertyChange, vector<bool>>(k, any_cast<vector<bool>>(p)); } },
{ type_index(typeid(boost::filesystem::path)), [](const EventManager& em, const string& k, const Property& p) { em.Emit<PropertyChange, boost::filesystem::path>(k, any_cast<boost::filesystem::path>(p)); } },
{ type_index(typeid(fs::path)), [](const EventManager& em, const string& k, const Property& p) { em.Emit<PropertyChange, fs::path>(k, any_cast<fs::path>(p)); } },
{ type_index(typeid(vector<char>)), [](const EventManager& em, const string& k, const Property& p) { em.Emit<PropertyChange, vector<char>>(k, any_cast<vector<char>>(p)); } },
{ type_index(typeid(vector<signed char>)), [](const EventManager& em, const string& k, const Property& p) { em.Emit<PropertyChange, vector<signed char>>(k, any_cast<vector<signed char>>(p)); } },
{ type_index(typeid(vector<unsigned char>)), [](const EventManager& em, const string& k, const Property& p) { em.Emit<PropertyChange, vector<unsigned char>>(k, any_cast<vector<unsigned char>>(p)); } },
@@ -138,7 +156,7 @@ unordered_map<type_index, void(*)(const EventManager&, const string&, const Prop
{ type_index(typeid(vector<float>)), [](const EventManager& em, const string& k, const Property& p) { em.Emit<PropertyChange, vector<float>>(k, any_cast<vector<float>>(p)); } },
{ type_index(typeid(vector<double>)), [](const EventManager& em, const string& k, const Property& p) { em.Emit<PropertyChange, vector<double>>(k, any_cast<vector<double>>(p)); } },
{ type_index(typeid(vector<long double>)), [](const EventManager& em, const string& k, const Property& p) { em.Emit<PropertyChange, vector<long double>>(k, any_cast<vector<long double>>(p)); } },
{ type_index(typeid(vector<boost::filesystem::path>)), [](const EventManager& em, const string& k, const Property& p) { em.Emit<PropertyChange, vector<boost::filesystem::path>>(k, any_cast<vector<boost::filesystem::path>>(p)); } },
{ type_index(typeid(vector<fs::path>)), [](const EventManager& em, const string& k, const Property& p) { em.Emit<PropertyChange, vector<fs::path>>(k, any_cast<vector<fs::path>>(p)); } },
};
} // namespace fair::mq

View File

@@ -1,5 +1,5 @@
/********************************************************************************
* Copyright (C) 2014-2021 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH *
* Copyright (C) 2014-2023 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH *
* *
* This software is distributed under the terms of the *
* GNU Lesser General Public Licence (LGPL) version 3, *
@@ -20,7 +20,6 @@
#include <fairlogger/Logger.h>
#include <boost/date_time/posix_time/posix_time.hpp>
#include <boost/filesystem.hpp>
#include <boost/interprocess/ipc/message_queue.hpp>
#include <boost/interprocess/managed_shared_memory.hpp>
#include <boost/interprocess/sync/interprocess_condition.hpp>

View File

@@ -1,5 +1,5 @@
/********************************************************************************
* Copyright (C) 2014-2021 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH *
* Copyright (C) 2014-2023 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH *
* *
* This software is distributed under the terms of the *
* GNU Lesser General Public Licence (LGPL) version 3, *
@@ -16,7 +16,6 @@
#include <fairlogger/Logger.h>
#include <boost/filesystem.hpp>
#include <boost/date_time/posix_time/posix_time.hpp>
#include <boost/interprocess/managed_shared_memory.hpp>
#include <boost/interprocess/file_mapping.hpp>