diff --git a/io/copy.h b/io/copy.h index e193626..fd34e7f 100644 --- a/io/copy.h +++ b/io/copy.h @@ -1,7 +1,7 @@ #ifndef IOUTILITIES_COPY_H #define IOUTILITIES_COPY_H -#include "../global.h" +#include "./nativefilestream.h" #include #include @@ -19,6 +19,9 @@ public: void copy(std::istream &input, std::ostream &output, std::size_t count); void callbackCopy(std::istream &input, std::ostream &output, std::size_t count, const std::function &isAborted, const std::function &callback); + void copy(NativeFileStream &input, NativeFileStream &output, std::size_t count); + void callbackCopy(NativeFileStream &input, NativeFileStream &output, std::size_t count, const std::function &isAborted, + const std::function &callback); char *buffer(); private: @@ -77,6 +80,36 @@ void CopyHelper::callbackCopy(std::istream &input, std::ostream &out callback(1.0); } +/*! + * \brief Copies \a count bytes from \a input to \a output. + * \remarks + * - Set an exception mask using std::ios::exceptions() to get a std::ios_base::failure exception + * when an IO error occurs. + * - Possibly uses native APIs such as POSIX sendfile() to improve the speed (not implemented yet). + */ +template void CopyHelper::copy(NativeFileStream &input, NativeFileStream &output, std::size_t count) +{ + copy(static_cast(input), static_cast(output), count); +} + +/*! + * \brief Copies \a count bytes from \a input to \a output. The procedure might be aborted and + * progress updates will be reported. + * + * Copying is aborted when \a isAborted returns true. The current progress is reported by calling + * the specified \a callback function. + * + * - Set an exception mask using std::ios::exceptions() to get a std::ios_base::failure exception + * when an IO error occurs. + * - Possibly uses native APIs such as POSIX sendfile() to improve the speed (not implemented yet). + */ +template +void CopyHelper::callbackCopy(NativeFileStream &input, NativeFileStream &output, std::size_t count, + const std::function &isAborted, const std::function &callback) +{ + callbackCopy(static_cast(input), static_cast(output), count, isAborted, callback); +} + /*! * \brief Returns the internal buffer. */