Skip to content

Commit

Permalink
Exit sup::path stage left; enter std::filesystem::path stage right (
Browse files Browse the repository at this point in the history
#2165)

Title says all, STL took over from our homegrown stuff.
  • Loading branch information
thorstenhater authored Aug 3, 2023
1 parent fdcf511 commit 0f2a81b
Show file tree
Hide file tree
Showing 17 changed files with 44 additions and 1,366 deletions.
3 changes: 2 additions & 1 deletion arbor/include/arbor/mechcat.hpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#pragma once

#include <filesystem>
#include <map>
#include <memory>
#include <string>
Expand Down Expand Up @@ -115,6 +116,6 @@ ARB_ARBOR_API const mechanism_catalogue& global_bbp_catalogue();
ARB_ARBOR_API const mechanism_catalogue& global_stochastic_catalogue();

// Load catalogue from disk.
ARB_ARBOR_API const mechanism_catalogue load_catalogue(const std::string&);
ARB_ARBOR_API const mechanism_catalogue load_catalogue(const std::filesystem::path&);

} // namespace arb
2 changes: 1 addition & 1 deletion arbor/mechcat.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -595,7 +595,7 @@ std::pair<mechanism_ptr, mechanism_overrides> mechanism_catalogue::instance_impl

mechanism_catalogue::~mechanism_catalogue() = default;

ARB_ARBOR_API const mechanism_catalogue load_catalogue(const std::string& fn) {
ARB_ARBOR_API const mechanism_catalogue load_catalogue(const std::filesystem::path& fn) {
typedef void* global_catalogue_t(int*);
global_catalogue_t* get_catalogue = nullptr;
try {
Expand Down
5 changes: 3 additions & 2 deletions arbor/util/dylib.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include <fstream>
#include <string>
#include <filesystem>

#include <dlfcn.h>

Expand All @@ -11,7 +12,7 @@
namespace arb {
namespace util {

void* dl_open(const std::string& fn) {
void* dl_open(const std::filesystem::path& fn) {
try {
std::ifstream fd{fn.c_str()};
if(!fd.good()) throw file_not_found_error{fn};
Expand All @@ -30,7 +31,7 @@ void* dl_open(const std::string& fn) {
}

namespace impl{
void* dl_get_symbol(const std::string& fn, const std::string& symbol) {
void* dl_get_symbol(const std::filesystem::path& fn, const std::string& symbol) {
// Call once to clear errors not caused by us
dlerror();

Expand Down
7 changes: 4 additions & 3 deletions arbor/util/dylib.hpp
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
#pragma once

#include <string>
#include <filesystem>

#include <arbor/arbexcept.hpp>

namespace arb {
namespace util {

namespace impl{
void* dl_get_symbol(const std::string& filename, const std::string& symbol);
void* dl_get_symbol(const std::filesystem::path& filename, const std::string& symbol);
} // namespace impl

struct dl_error: arbor_exception {
Expand All @@ -18,8 +19,8 @@ struct dl_error: arbor_exception {
// Find and return a symbol from a dynamic library with filename.
// Throws dl_error on error.
template<typename T>
T dl_get_symbol(const std::string& filename, const std::string& symbol) {
return reinterpret_cast<T>(impl::dl_get_symbol(filename, symbol));
T dl_get_symbol(const std::filesystem::path& filename, const std::string& symbol) {
return reinterpret_cast<T>(impl::dl_get_symbol(filename.string(), symbol));
}

} // namespace util
Expand Down
15 changes: 0 additions & 15 deletions arbor/util/file.hpp

This file was deleted.

5 changes: 3 additions & 2 deletions arborio/include/arborio/neurolucida.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include <cstddef>
#include <stdexcept>
#include <string>
#include <filesystem>

#include <arbor/arbexcept.hpp>
#include <arbor/morph/label_dict.hpp>
Expand Down Expand Up @@ -48,7 +49,7 @@ ARB_ARBORIO_API asc_morphology parse_asc_string(const char* input);
ARB_ARBORIO_API arb::segment_tree parse_asc_string_raw(const char* input);

// Load asc morphology from file with name filename.
ARB_ARBORIO_API asc_morphology load_asc(std::string filename);
ARB_ARBORIO_API arb::segment_tree load_asc_raw(std::string filename);
ARB_ARBORIO_API asc_morphology load_asc(const std::filesystem::path& filename);
ARB_ARBORIO_API arb::segment_tree load_asc_raw(const std::filesystem::path&filename);

} // namespace arborio
8 changes: 4 additions & 4 deletions arborio/neurolucida.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -790,11 +790,11 @@ ARB_ARBORIO_API asc_morphology parse_asc_string(const char* input) {
}


inline std::string read_file(std::string filename) {
inline std::string read_file(const std::filesystem::path& filename) {
std::ifstream fid(filename);

if (!fid.good()) {
throw arb::file_not_found_error(filename);
throw arb::file_not_found_error(filename.string());
}

// load contents of the file into a string.
Expand All @@ -809,13 +809,13 @@ inline std::string read_file(std::string filename) {
}


ARB_ARBORIO_API asc_morphology load_asc(std::string filename) {
ARB_ARBORIO_API asc_morphology load_asc(const std::filesystem::path& filename) {
std::string fstr = read_file(filename);
return parse_asc_string(fstr.c_str());
}


ARB_ARBORIO_API arb::segment_tree load_asc_raw(std::string filename) {
ARB_ARBORIO_API arb::segment_tree load_asc_raw(const std::filesystem::path& filename) {
std::string fstr = read_file(filename);
return parse_asc_string_raw(fstr.c_str());
}
Expand Down
2 changes: 1 addition & 1 deletion doc/cpp/morphology.rst
Original file line number Diff line number Diff line change
Expand Up @@ -567,7 +567,7 @@ regions and locations.

.. cpp:member:: arb::label_dict labels

.. cpp:function:: asc_morphology load_asc(const std::string& filename)
.. cpp:function:: asc_morphology load_asc(const std::filesystem::path& filename)

Parse a Neurolucida ASCII file.
Throws an exception if there is an error parsing the file.
Expand Down
2 changes: 0 additions & 2 deletions example/brunel/brunel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,6 @@

#include <sup/ioutil.hpp>
#include <sup/json_meter.hpp>
#include <sup/path.hpp>
#include <sup/strsub.hpp>

#ifdef ARB_MPI_ENABLED
#include <mpi.h>
Expand Down
19 changes: 18 additions & 1 deletion sup/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,11 +1,28 @@
set(sup-sources
ioutil.cpp
json_meter.cpp
path.cpp
)

add_library(arbor-sup ${sup-sources})

if (ARB_USE_BUNDLED_FMT)
target_include_directories(arbor-sup
PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>
$<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}/include>
PRIVATE
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/../ext/fmt/include>)

target_compile_definitions(arbor-sup PRIVATE FMT_HEADER_ONLY)
else()
target_include_directories(arbor-sup
PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>
$<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}/include>)
find_package(fmt REQUIRED)
target_link_libraries(arbor-sup PRIVATE fmt::fmt-header-only)
endif()

# Compile sup library with the same optimization flags as libarbor.
target_compile_options(arbor-sup PRIVATE ${ARB_CXX_FLAGS_TARGET_FULL})

Expand Down
6 changes: 3 additions & 3 deletions sup/include/sup/ioutil.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@

#include <iostream>
#include <fstream>
#include <filesystem>

#include <sup/export.hpp>
#include <sup/path.hpp>

namespace sup {

Expand Down Expand Up @@ -89,9 +89,9 @@ class ARB_SUP_API mask_stream {
bool mask_;
};

ARB_SUP_API std::fstream open_or_throw(const sup::path& p, std::ios_base::openmode, bool exclusive);
ARB_SUP_API std::fstream open_or_throw(const std::filesystem::path& p, std::ios_base::openmode, bool exclusive);

inline std::fstream open_or_throw(const sup::path& p, bool exclusive) {
inline std::fstream open_or_throw(const std::filesystem::path& p, bool exclusive) {
using std::ios_base;
return open_or_throw(p, ios_base::in|ios_base::out, exclusive);
}
Expand Down
Loading

0 comments on commit 0f2a81b

Please sign in to comment.