| 1 |
/* SPDX-License-Identifier: BSL-1.0 OR BSD-3-Clause */ |
| 2 |
|
| 3 |
#ifndef MPT_IO_READ_FILECURSOR_STDSTREAM_HPP |
| 4 |
#define MPT_IO_READ_FILECURSOR_STDSTREAM_HPP |
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
#include "mpt/base/namespace.hpp" |
| 9 |
#include "mpt/io_read/filecursor.hpp" |
| 10 |
#include "mpt/io_read/filecursor_filename_traits.hpp" |
| 11 |
#include "mpt/io_read/filecursor_traits_filedata.hpp" |
| 12 |
#include "mpt/io_read/filedata_stdstream.hpp" |
| 13 |
|
| 14 |
#include <istream> |
| 15 |
#include <memory> |
| 16 |
#include <utility> |
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
namespace mpt { |
| 21 |
inline namespace MPT_INLINE_NS { |
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
namespace IO { |
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
// Initialize file reader object with a std::istream. |
| 30 |
template <typename Tpath> |
| 31 |
inline FileCursor<FileCursorTraitsFileData, FileCursorFilenameTraits<Tpath>> make_FileCursor(std::istream & s, std::shared_ptr<Tpath> filename = nullptr) { |
| 32 |
if (FileDataStdStream::IsSeekable(s)) { |
| 33 |
return FileCursor<FileCursorTraitsFileData, FileCursorFilenameTraits<Tpath>>(std::static_pointer_cast<IFileData>(std::make_shared<FileDataStdStreamSeekable>(s)), std::move(filename)); |
| 34 |
} else { |
| 35 |
return FileCursor<FileCursorTraitsFileData, FileCursorFilenameTraits<Tpath>>(std::static_pointer_cast<IFileData>(std::make_shared<FileDataStdStreamUnseekable>(s)), std::move(filename)); |
| 36 |
} |
| 37 |
} |
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
} // namespace IO |
| 42 |
|
| 43 |
|
| 44 |
|
| 45 |
} // namespace MPT_INLINE_NS |
| 46 |
} // namespace mpt |
| 47 |
|
| 48 |
|
| 49 |
|
| 50 |
#endif // MPT_IO_READ_FILECURSOR_STDSTREAM_HPP |