#ifndef INCLUDE_WEBM_ISTREAM_READER_H_
#define INCLUDE_WEBM_ISTREAM_READER_H_
#include <cstdint>
#include <cstdlib>
#include <istream>
#include <memory>
#include <type_traits>
#include "./reader.h"
#include "./status.h"
namespace webm {
class IstreamReader : public Reader {
public:
IstreamReader() = default;
template <typename T>
explicit IstreamReader(T&& istream) : istream_(new T(std::move(istream))) {}
IstreamReader(IstreamReader&& other);
IstreamReader& operator=(IstreamReader&& other);
Status Read(std::size_t num_to_read, std::uint8_t* buffer,
std::uint64_t* num_actually_read) override;
Status Skip(std::uint64_t num_to_skip,
std::uint64_t* num_actually_skipped) override;
std::uint64_t Position() const override;
template <typename T, typename... Args>
static IstreamReader Emplace(Args&&... args) {
IstreamReader reader;
reader.istream_.reset(new T(std::forward<Args>(args)...));
return reader;
}
private:
std::unique_ptr<std::istream> istream_;
std::uint64_t position_ = 0;
};
}
#endif