Add NativeFileStream overloads to CopyHelper

In a future version these overloads could use native APIs such
as POSIX sendfile() to improve the speed. Libraries such as
tagparser will benefit from this change automatically when in
places where NativeFileStream is already used anyways.
This commit is contained in:
Martchus 2019-08-13 00:32:59 +02:00
parent 5bed21c9d2
commit db4cba4fe5
1 changed files with 34 additions and 1 deletions

View File

@ -1,7 +1,7 @@
#ifndef IOUTILITIES_COPY_H #ifndef IOUTILITIES_COPY_H
#define IOUTILITIES_COPY_H #define IOUTILITIES_COPY_H
#include "../global.h" #include "./nativefilestream.h"
#include <functional> #include <functional>
#include <iostream> #include <iostream>
@ -19,6 +19,9 @@ public:
void copy(std::istream &input, std::ostream &output, std::size_t count); 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<bool(void)> &isAborted, void callbackCopy(std::istream &input, std::ostream &output, std::size_t count, const std::function<bool(void)> &isAborted,
const std::function<void(double)> &callback); const std::function<void(double)> &callback);
void copy(NativeFileStream &input, NativeFileStream &output, std::size_t count);
void callbackCopy(NativeFileStream &input, NativeFileStream &output, std::size_t count, const std::function<bool(void)> &isAborted,
const std::function<void(double)> &callback);
char *buffer(); char *buffer();
private: private:
@ -77,6 +80,36 @@ void CopyHelper<bufferSize>::callbackCopy(std::istream &input, std::ostream &out
callback(1.0); 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 <std::size_t bufferSize> void CopyHelper<bufferSize>::copy(NativeFileStream &input, NativeFileStream &output, std::size_t count)
{
copy(static_cast<std::istream &>(input), static_cast<std::ostream &>(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 <std::size_t bufferSize>
void CopyHelper<bufferSize>::callbackCopy(NativeFileStream &input, NativeFileStream &output, std::size_t count,
const std::function<bool(void)> &isAborted, const std::function<void(double)> &callback)
{
callbackCopy(static_cast<std::istream &>(input), static_cast<std::ostream &>(output), count, isAborted, callback);
}
/*! /*!
* \brief Returns the internal buffer. * \brief Returns the internal buffer.
*/ */