-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
156617a
commit 2d2156f
Showing
6 changed files
with
214 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
#ifndef XTENSOR_IO_FILE_HPP | ||
#define XTENSOR_IO_FILE_HPP | ||
|
||
#include <stdio.h> | ||
|
||
namespace xt | ||
{ | ||
class xfile | ||
{ | ||
public: | ||
xfile(FILE* stream); | ||
size_t fwrite(const void* ptr, size_t size, size_t count); | ||
size_t fread(void* ptr, size_t size, size_t count); | ||
long int ftell(); | ||
int fseek(long int offset, int origin); | ||
void rewind(); | ||
int fflush(); | ||
private: | ||
FILE* m_stream; | ||
}; | ||
|
||
inline xfile::xfile(FILE* stream) | ||
: m_stream(stream) | ||
{ | ||
} | ||
|
||
inline size_t xfile::fwrite(const void* ptr, size_t size, size_t count) | ||
{ | ||
return ::fwrite(ptr, size, count, m_stream); | ||
} | ||
|
||
inline size_t xfile::fread(void* ptr, size_t size, size_t count) | ||
{ | ||
return ::fread(ptr, size, count, m_stream); | ||
} | ||
|
||
inline long int xfile::ftell() | ||
{ | ||
return ::ftell(m_stream); | ||
} | ||
|
||
inline int xfile::fseek(long int offset, int origin) | ||
{ | ||
return ::fseek(m_stream, offset, origin); | ||
} | ||
|
||
inline void xfile::rewind() | ||
{ | ||
::rewind(m_stream); | ||
} | ||
|
||
inline int xfile::fflush() | ||
{ | ||
return ::fflush(m_stream); | ||
} | ||
} | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
#ifndef XTENSOR_IO_GDAL_HANDLER_HPP | ||
#define XTENSOR_IO_GDAL_HANDLER_HPP | ||
|
||
#include <xtensor/xarray.hpp> | ||
#include <xtensor/xexpression.hpp> | ||
#include <xtensor-io/xfile_array.hpp> | ||
#include <xtensor-io/xio_vsilfile.hpp> | ||
|
||
#include <cpl_vsi.h> | ||
|
||
namespace xt | ||
{ | ||
struct xio_gdal_config | ||
{ | ||
}; | ||
|
||
template <class C> | ||
class xio_gdal_handler | ||
{ | ||
public: | ||
using io_config = xio_gdal_config; | ||
|
||
template <class E> | ||
void write(const xexpression<E>& expression, const std::string& path, xfile_dirty dirty); | ||
|
||
template <class ET> | ||
void read(ET& array, const std::string& path); | ||
|
||
void configure(const C& format_config, const xio_gdal_config& io_config); | ||
void configure_io(const xio_gdal_config& io_config); | ||
|
||
private: | ||
|
||
C m_format_config; | ||
}; | ||
|
||
template <class C> | ||
template <class E> | ||
inline void xio_gdal_handler<C>::write(const xexpression<E>& expression, const std::string& path, xfile_dirty dirty) | ||
{ | ||
if (m_format_config.will_dump(dirty)) | ||
{ | ||
VSILFILE* out_file = VSIFOpenL(path.c_str(), "wb"); | ||
if (out_file != NULL) | ||
{ | ||
auto f = xvsilfile(out_file); | ||
dump_file(f, expression, m_format_config); | ||
} | ||
else | ||
{ | ||
XTENSOR_THROW(std::runtime_error, "write: failed to open file " + path); | ||
} | ||
} | ||
} | ||
|
||
template <class C> | ||
template <class ET> | ||
inline void xio_gdal_handler<C>::read(ET& array, const std::string& path) | ||
{ | ||
VSILFILE* in_file = VSIFOpenL(path.c_str(), "rb"); | ||
if (in_file != NULL) | ||
{ | ||
auto f = xvsilfile(in_file); | ||
load_file<ET>(f, array, m_format_config); | ||
} | ||
else | ||
{ | ||
XTENSOR_THROW(std::runtime_error, "read: failed to open file " + path); | ||
} | ||
} | ||
|
||
template <class C> | ||
inline void xio_gdal_handler<C>::configure(const C& format_config, const xio_gdal_config& io_config) | ||
{ | ||
m_format_config = format_config; | ||
} | ||
|
||
template <class C> | ||
inline void xio_gdal_handler<C>::configure_io(const xio_gdal_config& io_config) | ||
{ | ||
} | ||
|
||
} | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
#ifndef XTENSOR_IO_VSILFILE_HPP | ||
#define XTENSOR_IO_VSILFILE_HPP | ||
|
||
#include <cpl_vsi.h> | ||
|
||
namespace xt | ||
{ | ||
class xvsilfile | ||
{ | ||
public: | ||
xvsilfile(VSILFILE* stream); | ||
size_t fwrite(const void* ptr, size_t size, size_t count); | ||
size_t fread(void* ptr, size_t size, size_t count); | ||
long int ftell(); | ||
int fseek(long int offset, int origin); | ||
void rewind(); | ||
int fflush(); | ||
private: | ||
VSILFILE* m_stream; | ||
}; | ||
|
||
inline xvsilfile::xvsilfile(VSILFILE* stream) | ||
: m_stream(stream) | ||
{ | ||
} | ||
|
||
inline size_t xvsilfile::fwrite(const void* ptr, size_t size, size_t count) | ||
{ | ||
return VSIFWriteL(ptr, size, count, m_stream); | ||
} | ||
|
||
inline size_t xvsilfile::fread(void* ptr, size_t size, size_t count) | ||
{ | ||
return VSIFReadL(ptr, size, count, m_stream); | ||
} | ||
|
||
inline long int xvsilfile::ftell() | ||
{ | ||
return VSIFTellL(m_stream); | ||
} | ||
|
||
inline int xvsilfile::fseek(long int offset, int origin) | ||
{ | ||
return VSIFSeekL(m_stream, offset, origin); | ||
} | ||
|
||
inline void xvsilfile::rewind() | ||
{ | ||
VSIRewindL(m_stream); | ||
} | ||
|
||
inline int xvsilfile::fflush() | ||
{ | ||
return VSIFFlushL(m_stream); | ||
} | ||
} | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters