nod/lib/DiscIOISO.cpp

62 lines
1.6 KiB
C++
Raw Normal View History

2015-06-26 19:30:03 +00:00
#include <stdio.h>
2015-07-02 18:33:55 +00:00
#include "NOD/Util.hpp"
#include "NOD/IDiscIO.hpp"
2016-01-26 02:01:55 +00:00
#include "NOD/IFileIO.hpp"
2015-06-26 19:30:03 +00:00
namespace NOD
{
2015-06-28 05:43:53 +00:00
class DiscIOISO : public IDiscIO
2015-06-26 19:30:03 +00:00
{
2016-01-26 02:01:55 +00:00
std::unique_ptr<IFileIO> m_fio;
2015-06-26 19:30:03 +00:00
public:
2015-07-02 18:33:55 +00:00
DiscIOISO(const SystemString& fpin)
2016-01-26 02:01:55 +00:00
: m_fio(std::move(NewFileIO(fpin))) {}
2015-06-26 19:30:03 +00:00
2015-06-28 05:43:53 +00:00
class ReadStream : public IReadStream
2015-06-26 19:30:03 +00:00
{
2015-06-28 05:43:53 +00:00
friend class DiscIOISO;
2016-01-26 02:01:55 +00:00
std::unique_ptr<IFileIO::IReadStream> fp;
ReadStream(std::unique_ptr<IFileIO::IReadStream>&& fpin)
: fp(std::move(fpin)) {}
2015-06-26 19:30:03 +00:00
public:
2016-01-25 05:55:31 +00:00
uint64_t read(void* buf, uint64_t length)
2016-01-26 02:01:55 +00:00
{return fp->read(buf, length);}
2015-07-07 03:22:19 +00:00
uint64_t position() const
2016-01-26 02:01:55 +00:00
{return fp->position();}
void seek(int64_t offset, int whence)
2016-01-26 02:01:55 +00:00
{fp->seek(offset, whence);}
2015-06-26 19:30:03 +00:00
};
2016-01-25 05:55:31 +00:00
std::unique_ptr<IReadStream> beginReadStream(uint64_t offset) const
2015-06-26 19:30:03 +00:00
{
2016-01-26 02:01:55 +00:00
return std::unique_ptr<IReadStream>(new ReadStream(std::move(m_fio->beginReadStream(offset))));
2016-01-25 05:55:31 +00:00
}
2015-06-26 19:30:03 +00:00
2015-06-28 05:43:53 +00:00
class WriteStream : public IWriteStream
2015-06-26 19:30:03 +00:00
{
2015-06-28 05:43:53 +00:00
friend class DiscIOISO;
2016-01-26 02:01:55 +00:00
std::unique_ptr<IFileIO::IWriteStream> fp;
WriteStream(std::unique_ptr<IFileIO::IWriteStream>&& fpin)
: fp(std::move(fpin)) {}
2015-06-26 19:30:03 +00:00
public:
2016-01-25 05:55:31 +00:00
uint64_t write(const void* buf, uint64_t length)
{
2016-01-26 02:01:55 +00:00
return fp->write(buf, length);
2016-01-25 05:55:31 +00:00
}
2015-06-26 19:30:03 +00:00
};
2016-01-25 05:55:31 +00:00
std::unique_ptr<IWriteStream> beginWriteStream(uint64_t offset) const
2015-06-26 19:30:03 +00:00
{
2016-01-26 02:01:55 +00:00
return std::unique_ptr<IWriteStream>(new WriteStream(std::move(m_fio->beginWriteStream(offset))));
2015-06-26 19:30:03 +00:00
}
};
2015-07-02 18:33:55 +00:00
std::unique_ptr<IDiscIO> NewDiscIOISO(const SystemChar* path)
2015-06-26 19:30:03 +00:00
{
2015-06-28 05:43:53 +00:00
return std::unique_ptr<IDiscIO>(new DiscIOISO(path));
2015-06-26 19:30:03 +00:00
}
}