Skip to content

Commit 769d926

Browse files
committed
Add test with xfile_array
1 parent e4d52fe commit 769d926

File tree

3 files changed

+63
-9
lines changed

3 files changed

+63
-9
lines changed

include/xtensor-io/xfile_array.hpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,9 @@ namespace xt
145145

146146
xfile_array_container(const std::string& path, xfile_mode mode=xfile_mode::load);
147147

148+
template <class IOC>
149+
xfile_array_container(const std::string& path, IOC& io_config, xfile_mode mode=xfile_mode::load);
150+
148151
xfile_array_container(const std::string& path, xfile_mode mode, const value_type& init_value);
149152

150153
~xfile_array_container();
@@ -385,6 +388,19 @@ namespace xt
385388
set_path(path);
386389
}
387390

391+
template <class E, class IOH>
392+
template <class IOC>
393+
inline xfile_array_container<E, IOH>::xfile_array_container(const std::string& path, IOC& io_config, xfile_mode file_mode)
394+
: m_storage()
395+
, m_dirty(false)
396+
, m_io_handler()
397+
, m_file_mode(file_mode)
398+
, m_init(false)
399+
{
400+
m_io_handler.configure_io(io_config);
401+
set_path(path);
402+
}
403+
388404
template <class E, class IOH>
389405
inline xfile_array_container<E, IOH>::xfile_array_container(const std::string& path, xfile_mode file_mode, const value_type& init_value)
390406
: m_storage()

include/xtensor-io/xio_aws_handler.hpp

Lines changed: 29 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -26,15 +26,20 @@ namespace xt
2626
xio_aws_handler();
2727

2828
template <class E>
29-
void write(const xexpression<E>& expression, const Aws::String& path, xfile_dirty dirty);
29+
void write(const xexpression<E>& expression, const std::string& path, xfile_dirty dirty);
3030

3131
template <class ET>
32-
void read(ET& array, const Aws::String& path);
32+
void read(ET& array, const std::string& path);
3333

3434
void configure(const C& format_config, const xio_aws_config& io_config);
3535
void configure_io(const xio_aws_config& io_config);
3636

3737
private:
38+
template <class E>
39+
void write(const xexpression<E>& expression, const char* path, xfile_dirty dirty);
40+
41+
template <class ET>
42+
void read(ET& array, const char* path);
3843

3944
C m_format_config;
4045
Aws::S3::S3Client m_client;
@@ -48,16 +53,24 @@ namespace xt
4853

4954
template <class C>
5055
template <class E>
51-
inline void xio_aws_handler<C>::write(const xexpression<E>& expression, const Aws::String& path, xfile_dirty dirty)
56+
inline void xio_aws_handler<C>::write(const xexpression<E>& expression, const std::string& path, xfile_dirty dirty)
57+
{
58+
write(expression, path.c_str(), dirty);
59+
}
60+
61+
template <class C>
62+
template <class E>
63+
inline void xio_aws_handler<C>::write(const xexpression<E>& expression, const char* path, xfile_dirty dirty)
5264
{
5365
if (m_format_config.will_dump(dirty))
5466
{
67+
Aws::String path2 = path;
5568
Aws::S3::Model::PutObjectRequest request;
5669
request.SetBucket(m_bucket);
57-
request.SetKey(path);
70+
request.SetKey(path2);
5871

59-
std::shared_ptr<Aws::IOStream> writer = Aws::MakeShared<Aws::FStream>("SampleAllocationTag", path.c_str(), std::ios_base::in | std::ios_base::binary);
60-
dump_file(writer, expression, m_format_config);
72+
std::shared_ptr<Aws::IOStream> writer = Aws::MakeShared<Aws::FStream>("SampleAllocationTag", path, std::ios_base::in | std::ios_base::binary);
73+
dump_file(*writer, expression, m_format_config);
6174

6275
request.SetBody(writer);
6376

@@ -73,11 +86,19 @@ namespace xt
7386

7487
template <class C>
7588
template <class ET>
76-
inline void xio_aws_handler<C>::read(ET& array, const Aws::String& path)
89+
inline void xio_aws_handler<C>::read(ET& array, const std::string& path)
90+
{
91+
read(array, path.c_str());
92+
}
93+
94+
template <class C>
95+
template <class ET>
96+
inline void xio_aws_handler<C>::read(ET& array, const char* path)
7797
{
98+
Aws::String path2 = path;
7899
Aws::S3::Model::GetObjectRequest request;
79100
request.SetBucket(m_bucket);
80-
request.SetKey(path);
101+
request.SetKey(path2);
81102

82103
Aws::S3::Model::GetObjectOutcome outcome = m_client.GetObject(request);
83104

test/test_xio_aws_handler.cpp

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

1414
#include "gtest/gtest.h"
1515
#include "xtensor/xview.hpp"
16+
#include "xtensor-io/xfile_array.hpp"
1617
#include "xtensor-io/xio_binary.hpp"
1718
#include "xtensor-io/xio_aws_handler.hpp"
1819

@@ -30,7 +31,23 @@ namespace xt
3031
xio_aws_config c = {client, "elevation-tiles-prod"};
3132
h.configure_io(c);
3233
xarray<char> a0;
33-
h.read(a0, "main.js");
34+
std::string path = "main.js";
35+
h.read(a0, path);
36+
xarray<char> a1 = {'/', '*', 'j', 's', 'l', 'i', 'n', 't', ' ', 'b', 'r' ,'o', 'w', 's', 'e', 'r', ':', ' ', 't', 'r', 'u', 'e', '*', '/'};
37+
EXPECT_TRUE(xt::all(xt::equal(xt::view(a0, xt::range(0, 24)), a1)));
38+
39+
Aws::ShutdownAPI(options);
40+
}
41+
42+
TEST(xio_aws_handler, xfile_array)
43+
{
44+
Aws::SDKOptions options;
45+
Aws::InitAPI(options);
46+
47+
Aws::S3::S3Client client;
48+
xio_aws_config c = {client, "elevation-tiles-prod"};
49+
xfile_array<char, xio_aws_handler<xio_binary_config>> a0("main.js", c);
50+
3451
xarray<char> a1 = {'/', '*', 'j', 's', 'l', 'i', 'n', 't', ' ', 'b', 'r' ,'o', 'w', 's', 'e', 'r', ':', ' ', 't', 'r', 'u', 'e', '*', '/'};
3552
EXPECT_TRUE(xt::all(xt::equal(xt::view(a0, xt::range(0, 24)), a1)));
3653

0 commit comments

Comments
 (0)