Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove fs_portability #149

Merged
merged 1 commit into from
Oct 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions include/fmi4cpp/fmi2/fmu.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,10 @@

#include <fmi4cpp/fmi2/cs_fmu.hpp>
#include <fmi4cpp/fmi2/me_fmu.hpp>
#include <fmi4cpp/fmi2/xml/cs_model_description.hpp>
#include <fmi4cpp/fmi2/xml/me_model_description.hpp>
#include <fmi4cpp/fmu_base.hpp>
#include <fmi4cpp/fs_portability.hpp>

#include <filesystem>
#include <memory>
#include <string>

Expand All @@ -26,7 +25,7 @@ class fmu : public virtual fmu_provider<model_description, cs_fmu, me_fmu>
std::shared_ptr<const fmi4cpp::fmi2::model_description> modelDescription_;

public:
explicit fmu(const fs::path& fmuPath);
explicit fmu(const std::filesystem::path& fmuPath);

[[nodiscard]] std::string get_model_description_xml() const;
[[nodiscard]] std::shared_ptr<const fmi4cpp::fmi2::model_description> get_model_description() const override;
Expand Down
7 changes: 3 additions & 4 deletions include/fmi4cpp/fmu_resource.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@
#ifndef FMI4CPP_FMURESOURCE_HPP
#define FMI4CPP_FMURESOURCE_HPP

#include <fmi4cpp/fs_portability.hpp>

#include <filesystem>
#include <string>

namespace fmi4cpp
Expand All @@ -13,10 +12,10 @@ class fmu_resource
{

private:
const fs::path path_;
std::filesystem::path path_;

public:
explicit fmu_resource(fs::path path);
explicit fmu_resource(std::filesystem::path path);

[[nodiscard]] std::string resource_path() const;

Expand Down
19 changes: 0 additions & 19 deletions include/fmi4cpp/fs_portability.hpp

This file was deleted.

3 changes: 1 addition & 2 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ set(publicHeaders
"fmi4cpp/fmu_variable_accessor.hpp"

"fmi4cpp/dll_handle.hpp"
"fmi4cpp/fs_portability.hpp"

"fmi4cpp/fmi2/fmi2.hpp"
"fmi4cpp/fmi2/fmu.hpp"
Expand Down Expand Up @@ -111,7 +110,7 @@ target_link_libraries(fmi4cpp
if(WIN32)
target_link_libraries(fmi4cpp PRIVATE "Bcrypt")
elseif(UNIX)
target_link_libraries(fmi4cpp PRIVATE stdc++fs dl)
target_link_libraries(fmi4cpp PRIVATE dl)
endif()


Expand Down
3 changes: 1 addition & 2 deletions src/fmi4cpp/fmi2/fmi2_library.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@

#include <fmi4cpp/fmi2/fmi2_library.hpp>
#include <fmi4cpp/fs_portability.hpp>
#include <fmi4cpp/library_helper.hpp>
#include <fmi4cpp/mlog.hpp>
#include <fmi4cpp/tools/os_util.hpp>
Expand Down Expand Up @@ -59,7 +58,7 @@ fmi2_library::fmi2_library(const std::string& modelIdentifier, const std::shared
{
const std::string libName = resource->absolute_library_path(modelIdentifier);

MLOG_DEBUG("Loading shared library '" + fs::path(libName).stem().string() + get_shared_library_extension() + "'");
MLOG_DEBUG("Loading shared library '" + std::filesystem::path(libName).stem().string() + get_shared_library_extension() + "'");

handle_ = load_library(libName);

Expand Down
4 changes: 2 additions & 2 deletions src/fmi4cpp/fmi2/fmu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
using namespace fmi4cpp;
using namespace fmi4cpp::fmi2;

fmu::fmu(const fs::path& fmuPath)
fmu::fmu(const std::filesystem::path& fmuPath)
{

if (!exists(fmuPath)) {
Expand All @@ -21,7 +21,7 @@ fmu::fmu(const fs::path& fmuPath)
}

const std::string fmuName = fmuPath.stem().string();
fs::path tmpPath(fs::temp_directory_path() /= fs::path("fmi4cpp_" + fmuName + "_" + generate_simple_id(8)));
std::filesystem::path tmpPath(std::filesystem::temp_directory_path() /= std::filesystem::path("fmi4cpp_" + fmuName + "_" + generate_simple_id(8)));

if (!create_directories(tmpPath)) {
const auto err = "Failed to create temporary directory '" + tmpPath.string() + "' !";
Expand Down
4 changes: 2 additions & 2 deletions src/fmi4cpp/fmu_resource.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

using namespace fmi4cpp;

fmu_resource::fmu_resource(fs::path path)
fmu_resource::fmu_resource(std::filesystem::path path)
: path_(std::move(path))
{}

Expand Down Expand Up @@ -37,7 +37,7 @@ std::string fmu_resource::get_model_description_xml() const
fmu_resource::~fmu_resource()
{
std::error_code success;
fs::remove_all(path_, success);
remove_all(path_, success);

if (!success) {
MLOG_DEBUG("Deleted temporal folder '" + path_.string() + "'");
Expand Down
13 changes: 7 additions & 6 deletions src/fmi4cpp/library_helper.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,19 @@
#define FMI4CPP_LIBRARYHELPER_HPP

#include <fmi4cpp/dll_handle.hpp>
#include <fmi4cpp/fs_portability.hpp>

#include <filesystem>
#include <sstream>

namespace
namespace fmi4cpp
{

DLL_HANDLE load_library(const std::string& libName)
inline DLL_HANDLE load_library(const std::string& libName)
{
std::string dllDirectory;

#ifdef _WIN32
fmi4cpp::fs::path path(libName);
std::filesystem::path path(libName);
if (path.has_parent_path()) {
dllDirectory = path.parent_path().string();
}
Expand Down Expand Up @@ -48,7 +49,7 @@ T load_function(DLL_HANDLE handle, const char* function_name)
#endif
}

bool free_library(DLL_HANDLE handle)
inline bool free_library(DLL_HANDLE handle)
{
#ifdef WIN32
return static_cast<bool>(FreeLibrary(handle));
Expand All @@ -57,7 +58,7 @@ bool free_library(DLL_HANDLE handle)
#endif
}

std::string getLastError()
inline std::string getLastError()
{
#ifdef WIN32
std::ostringstream os;
Expand Down
17 changes: 7 additions & 10 deletions src/fmi4cpp/tools/unzipper.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,16 @@
#ifndef FMI4CPP_UNZIPPER_HPP
#define FMI4CPP_UNZIPPER_HPP

#include <fmi4cpp/fs_portability.hpp>

#include <zip.h>

#include <filesystem>
#include <fstream>
#include <iostream>
#include <sstream>
#include <string>

namespace
namespace fmi4cpp
{

bool unzip(const fmi4cpp::fs::path& zip_file, const fmi4cpp::fs::path& tmp_path)
inline bool unzip(const std::filesystem::path& zip_file, const std::filesystem::path& tmp_path)
{
int* err = nullptr;
zip* za = zip_open(absolute(zip_file).string().c_str(), 0, err);
Expand All @@ -34,13 +31,13 @@ bool unzip(const fmi4cpp::fs::path& zip_file, const fmi4cpp::fs::path& tmp_path)
for (int i = 0; i < zip_get_num_entries(za, 0); i++) {
if (zip_stat_index(za, i, 0, &sb) == 0) {

const fmi4cpp::fs::path newFile = tmp_path / sb.name;
const std::filesystem::path newFile = tmp_path / sb.name;

if (sb.size == 0) {
fmi4cpp::fs::create_directories(newFile);
create_directories(newFile);
} else {
const auto containingDirectory = newFile.parent_path();
if (!fmi4cpp::fs::exists(containingDirectory) && !fmi4cpp::fs::create_directories(containingDirectory)) {
if (!exists(containingDirectory) && !create_directories(containingDirectory)) {
return false;
}
zf = zip_fopen_index(za, i, 0);
Expand All @@ -67,6 +64,6 @@ bool unzip(const fmi4cpp::fs::path& zip_file, const fmi4cpp::fs::path& tmp_path)
return true;
}

} // namespace
} // namespace fmi4cpp

#endif // FMI4CPP_UNZIPPER_HPP
Loading