2015-06-26 19:30:03 +00:00
|
|
|
#ifndef __NOD_IDISC_IO__
|
|
|
|
#define __NOD_IDISC_IO__
|
|
|
|
|
|
|
|
#include <memory>
|
|
|
|
#include <stdlib.h>
|
2015-06-28 05:43:53 +00:00
|
|
|
#include <stdio.h>
|
2015-06-30 19:38:51 +00:00
|
|
|
#include <stdint.h>
|
2015-06-26 19:30:03 +00:00
|
|
|
|
2015-07-08 04:24:34 +00:00
|
|
|
#if NOD_ATHENA
|
|
|
|
#include <Athena/IStreamReader.hpp>
|
|
|
|
#include <Athena/IStreamWriter.hpp>
|
|
|
|
#endif
|
|
|
|
|
2015-06-26 19:30:03 +00:00
|
|
|
namespace NOD
|
|
|
|
{
|
|
|
|
|
|
|
|
class IDiscIO
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
virtual ~IDiscIO() {}
|
|
|
|
|
2015-06-28 05:43:53 +00:00
|
|
|
struct IReadStream
|
2015-06-26 19:30:03 +00:00
|
|
|
{
|
2015-07-16 01:56:33 +00:00
|
|
|
virtual ~IReadStream() {}
|
2015-06-30 19:38:51 +00:00
|
|
|
virtual uint64_t read(void* buf, uint64_t length)=0;
|
|
|
|
virtual void seek(int64_t offset, int whence=SEEK_SET)=0;
|
2015-07-07 03:22:19 +00:00
|
|
|
virtual uint64_t position() const=0;
|
2015-06-26 19:30:03 +00:00
|
|
|
};
|
2015-06-30 19:38:51 +00:00
|
|
|
virtual std::unique_ptr<IReadStream> beginReadStream(uint64_t offset=0) const=0;
|
2015-06-26 19:30:03 +00:00
|
|
|
|
2015-06-28 05:43:53 +00:00
|
|
|
struct IWriteStream
|
2015-06-26 19:30:03 +00:00
|
|
|
{
|
2015-07-16 01:56:33 +00:00
|
|
|
virtual ~IWriteStream() {}
|
2015-06-30 19:38:51 +00:00
|
|
|
virtual uint64_t write(void* buf, uint64_t length)=0;
|
2015-06-26 19:30:03 +00:00
|
|
|
};
|
2015-06-30 19:38:51 +00:00
|
|
|
virtual std::unique_ptr<IWriteStream> beginWriteStream(uint64_t offset=0) const=0;
|
2015-06-26 19:30:03 +00:00
|
|
|
};
|
|
|
|
|
2015-06-30 06:46:19 +00:00
|
|
|
struct IPartReadStream
|
|
|
|
{
|
2015-07-16 01:56:33 +00:00
|
|
|
virtual ~IPartReadStream() {}
|
2015-06-30 19:38:51 +00:00
|
|
|
virtual void seek(int64_t offset, int whence=SEEK_SET)=0;
|
2015-07-07 03:22:19 +00:00
|
|
|
virtual uint64_t position() const=0;
|
2015-06-30 19:38:51 +00:00
|
|
|
virtual uint64_t read(void* buf, uint64_t length)=0;
|
2015-06-30 06:46:19 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
struct IPartWriteStream
|
|
|
|
{
|
2015-07-16 01:56:33 +00:00
|
|
|
virtual ~IPartWriteStream() {}
|
2016-01-25 02:00:02 +00:00
|
|
|
virtual void close()=0;
|
2015-07-07 03:22:19 +00:00
|
|
|
virtual uint64_t position() const=0;
|
2016-01-25 02:00:02 +00:00
|
|
|
virtual uint64_t write(const void* buf, uint64_t length)=0;
|
2015-06-30 06:46:19 +00:00
|
|
|
};
|
|
|
|
|
2015-07-07 03:22:19 +00:00
|
|
|
#if NOD_ATHENA
|
|
|
|
|
|
|
|
class AthenaPartReadStream : public Athena::io::IStreamReader
|
|
|
|
{
|
|
|
|
std::unique_ptr<IPartReadStream> m_rs;
|
|
|
|
public:
|
|
|
|
AthenaPartReadStream(std::unique_ptr<IPartReadStream>&& rs) : m_rs(std::move(rs)) {}
|
|
|
|
|
|
|
|
inline void seek(atInt64 off, Athena::SeekOrigin origin)
|
|
|
|
{
|
|
|
|
if (origin == Athena::Begin)
|
|
|
|
m_rs->seek(off, SEEK_SET);
|
|
|
|
else if (origin == Athena::Current)
|
|
|
|
m_rs->seek(off, SEEK_CUR);
|
|
|
|
}
|
|
|
|
inline atUint64 position() const {return m_rs->position();}
|
|
|
|
inline atUint64 length() const {return 0;}
|
|
|
|
inline atUint64 readUBytesToBuf(void* buf, atUint64 sz) {m_rs->read(buf, sz); return sz;}
|
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
2015-06-26 19:30:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#endif // __NOD_IDISC_IO__
|