Skip to content

Commit 76883c4

Browse files
committed
Use WriteBuffer type for smart pointers
1 parent 1fbba25 commit 76883c4

7 files changed

Lines changed: 23 additions & 16 deletions

File tree

include/openPMD/toolkit/Aws.hpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,8 @@ struct ExternalBlockStorageAws : ExternalBlockStorageBackend
3838
std::string bucketName,
3939
std::optional<std::string> endpoint,
4040
bool async);
41-
auto put(std::string const &identifier, void const *data, size_t len)
41+
auto
42+
put(std::string const &identifier, auxiliary::WriteBuffer data, size_t len)
4243
-> std::string override;
4344
void get(std::string const &external_ref, void *data, size_t len) override;
4445
[[nodiscard]] auto externalStorageLocation() const

include/openPMD/toolkit/ExternalBlockStorage.hpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#pragma once
22

33
#include "openPMD/Dataset.hpp"
4+
#include "openPMD/auxiliary/Memory.hpp"
45
#include "openPMD/toolkit/AwsBuilder.hpp"
56
#include "openPMD/toolkit/StdioBuilder.hpp"
67

@@ -22,7 +23,7 @@ namespace openPMD::internal
2223
struct ExternalBlockStorageBackend
2324
{
2425
virtual auto
25-
put(std::string const &identifier, void const *data, size_t len)
26+
put(std::string const &identifier, auxiliary::WriteBuffer data, size_t len)
2627
-> std::string = 0;
2728
virtual void
2829
get(std::string const &external_ref, void *data, size_t len) = 0;
@@ -90,7 +91,7 @@ class ExternalBlockStorage
9091
nlohmann::json &fullJsonDataset,
9192
nlohmann::json::json_pointer const &path,
9293
std::optional<std::string> infix, // e.g. for distinguishing MPI ranks
93-
T const *data) -> std::string;
94+
auxiliary::WriteBuffer data) -> std::string;
9495

9596
template <typename DatatypeHandling, typename T>
9697
void read(

include/openPMD/toolkit/Stdio.hpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@ struct ExternalBlockStorageStdio : ExternalBlockStorageBackend
1212

1313
public:
1414
ExternalBlockStorageStdio(std::string directory, std::string openMode);
15-
auto put(std::string const &identifier, void const *data, size_t len)
15+
auto
16+
put(std::string const &identifier, auxiliary::WriteBuffer data, size_t len)
1617
-> std::string override;
1718
void get(std::string const &external_ref, void *data, size_t len) override;
1819
[[nodiscard]] auto externalStorageLocation() const

src/IO/JSON/JSONIOHandlerImpl.cpp

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1467,11 +1467,10 @@ namespace
14671467
struct StoreExternally
14681468
{
14691469
template <typename T, typename... Args>
1470-
static void call(
1471-
ExternalBlockStorage &blockStorage, void const *ptr, Args &&...args)
1470+
static void call(ExternalBlockStorage &blockStorage, Args &&...args)
14721471
{
14731472
blockStorage.store<internal::JsonDatatypeHandling, T>(
1474-
std::forward<Args>(args)..., static_cast<T const *>(ptr));
1473+
std::forward<Args>(args)...);
14751474
}
14761475

14771476
static constexpr char const *errorMsg = "StoreExternally";
@@ -1525,13 +1524,13 @@ void JSONIOHandlerImpl::writeDataset(
15251524
switchDatasetType<StoreExternally>(
15261525
parameters.dtype,
15271526
*external,
1528-
parameters.data.get(),
15291527
j.at("extent").get<Extent>(),
15301528
parameters.offset,
15311529
parameters.extent,
15321530
jsonRoot,
15331531
filePosition->id,
1534-
std::move(rankInfix));
1532+
std::move(rankInfix),
1533+
std::move(parameters.data));
15351534
}},
15361535
verifyDataset(parameters, j).as_base());
15371536

src/toolkit/Aws.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,8 @@ ExternalBlockStorageAws::ExternalBlockStorageAws(
8989
ExternalBlockStorageAws::~ExternalBlockStorageAws() = default;
9090

9191
auto ExternalBlockStorageAws::put(
92-
std::string const &identifier, void const *data, size_t len) -> std::string
92+
std::string const &identifier, auxiliary::WriteBuffer data, size_t len)
93+
-> std::string
9394
{
9495
auto sanitized = !identifier.empty() && identifier.at(0) == '/'
9596
? identifier.substr(1)
@@ -100,7 +101,9 @@ auto ExternalBlockStorageAws::put(
100101
put_request.SetKey(sanitized);
101102

102103
auto input_data = Aws::MakeShared<imemstream>(
103-
"PutObjectInputStream", reinterpret_cast<char const *>(data), len);
104+
"PutObjectInputStream",
105+
reinterpret_cast<char const *>(data.get()),
106+
len);
104107
put_request.SetBody(input_data);
105108
put_request.SetContentLength(static_cast<long long>(len));
106109

src/toolkit/ExternalBlockStorage.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
#include "openPMD/DatatypeMacros.hpp"
44
#include "openPMD/IO/JSON/JSONIOHandlerImpl.hpp"
5+
#include "openPMD/auxiliary/Memory.hpp"
56
#include "openPMD/auxiliary/StringManip.hpp"
67

78
#include <nlohmann/json.hpp>
@@ -74,7 +75,7 @@ auto ExternalBlockStorage::store(
7475
nlohmann::json &fullJsonDataset,
7576
nlohmann::json::json_pointer const &path,
7677
std::optional<std::string> infix,
77-
T const *data) -> std::string
78+
auxiliary::WriteBuffer data) -> std::string
7879
{
7980
auto &dataset = fullJsonDataset[path];
8081

@@ -154,7 +155,7 @@ auto ExternalBlockStorage::store(
154155
filesystem_identifier << "--" << index_as_str;
155156
auto escaped_filesystem_identifier = m_worker->put(
156157
filesystem_identifier.str(),
157-
data,
158+
std::move(data),
158159
sizeof(T) * flat_extent(blockExtent));
159160
block["external_ref"] = escaped_filesystem_identifier;
160161
return index_as_str;
@@ -250,7 +251,7 @@ void ExternalBlockStorage::sanitizeString(std::string &s)
250251
nlohmann::json &fullJsonDataset, \
251252
nlohmann::json::json_pointer const &path, \
252253
std::optional<std::string> infix, \
253-
type const *data) -> std::string; \
254+
auxiliary::WriteBuffer) -> std::string; \
254255
template void ExternalBlockStorage::read<datatypehandling, type>( \
255256
std::string const &identifier, \
256257
nlohmann::json const &fullJsonDataset, \

src/toolkit/Stdio.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,8 @@ ExternalBlockStorageStdio::ExternalBlockStorageStdio(
6262
ExternalBlockStorageStdio::~ExternalBlockStorageStdio() = default;
6363

6464
auto ExternalBlockStorageStdio::put(
65-
std::string const &identifier, void const *data, size_t len) -> std::string
65+
std::string const &identifier, auxiliary::WriteBuffer data, size_t len)
66+
-> std::string
6667
{
6768
auto sanitized = identifier + ".dat";
6869
ExternalBlockStorage::sanitizeString(sanitized);
@@ -81,7 +82,7 @@ auto ExternalBlockStorageStdio::put(
8182
filepath);
8283
}
8384

84-
size_t written = std::fwrite(data, 1, len, file);
85+
size_t written = std::fwrite(data.get(), 1, len, file);
8586
if (written != len)
8687
{
8788
throw std::runtime_error(

0 commit comments

Comments
 (0)