From 7ee183ca481c2729cb703ced3b6a3fa4ad7d73a3 Mon Sep 17 00:00:00 2001 From: Walter van Niftrik Date: Sat, 26 Mar 2016 01:01:10 +0100 Subject: ADL: Refactor disk classes --- engines/adl/disk.h | 97 +++++++++++++++++++++++++++++++++++------------------- 1 file changed, 64 insertions(+), 33 deletions(-) (limited to 'engines/adl/disk.h') diff --git a/engines/adl/disk.h b/engines/adl/disk.h index 799fa371df..12801ec9e7 100644 --- a/engines/adl/disk.h +++ b/engines/adl/disk.h @@ -43,6 +43,7 @@ public: }; typedef Common::SharedPtr DataBlockPtr; +typedef Common::ScopedPtr StreamPtr; class Files { public: @@ -50,60 +51,90 @@ public: virtual const DataBlockPtr getDataBlock(const Common::String &filename, uint offset = 0) const = 0; virtual Common::SeekableReadStream *createReadStream(const Common::String &filename, uint offset = 0) const = 0; -}; - -class FilesDataBlock : public DataBlock { -public: - FilesDataBlock(const Files *files, const Common::String &filename, uint offset) : _files(files), _filename(filename), _offset(offset) { } - - bool isValid() const { return true; } - Common::SeekableReadStream *createReadStream() const; - -private: - const Common::String _filename; - uint _offset; - const Files *_files; -}; -class PlainFiles : public Files { -public: - const DataBlockPtr getDataBlock(const Common::String &filename, uint offset = 0) const; - Common::SeekableReadStream *createReadStream(const Common::String &filename, uint offset = 0) const; +protected: + class DataBlock : public Adl::DataBlock { + public: + DataBlock(const Files *files, const Common::String &filename, uint offset) : + _files(files), + _filename(filename), + _offset(offset) { } + + bool isValid() const { + return true; + } + + Common::SeekableReadStream *createReadStream() const { + return _files->createReadStream(_filename, _offset); + } + + private: + const Common::String _filename; + uint _offset; + const Files *_files; + }; }; class DiskImage { public: - DiskImage(); - virtual ~DiskImage(); + DiskImage() : + _tracks(0), + _sectorsPerTrack(0), + _bytesPerSector(0) { + _f = new Common::File(); + } + + virtual ~DiskImage() { + delete _f; + } virtual bool open(const Common::String &filename) = 0; - virtual const DataBlockPtr getDataBlock(uint track, uint sector, uint offset, uint size) const = 0; - virtual Common::SeekableReadStream *createReadStream(uint track, uint sector, uint offset, uint size) const = 0; + virtual const DataBlockPtr getDataBlock(uint track, uint sector, uint offset = 0, uint size = 0) const = 0; + virtual Common::SeekableReadStream *createReadStream(uint track, uint sector, uint offset = 0, uint size = 0) const = 0; protected: + class DataBlock : public Adl::DataBlock { + public: + DataBlock(const DiskImage *disk, uint track, uint sector, uint offset, uint size) : + _track(track), + _sector(sector), + _offset(offset), + _size(size), + _disk(disk) { } + + bool isValid() const { + return _track != 0 || _sector != 0 || _offset != 0 || _size != 0; + } + + Common::SeekableReadStream *createReadStream() const { + return _disk->createReadStream(_track, _sector, _offset, _size); + } + + private: + uint _track, _sector, _offset, _size; + const DiskImage *_disk; + }; + Common::File *_f; uint _tracks, _sectorsPerTrack, _bytesPerSector; }; -class DiskImageDataBlock : public DataBlock { +// Data in plain files +class Files_Plain : public Files { public: - DiskImageDataBlock(const DiskImage *disk, uint track, uint sector, uint offset, uint size); - - bool isValid() const; - Common::SeekableReadStream *createReadStream() const; - -private: - uint _track, _sector, _offset, _size; - const DiskImage *_disk; + const DataBlockPtr getDataBlock(const Common::String &filename, uint offset = 0) const; + Common::SeekableReadStream *createReadStream(const Common::String &filename, uint offset = 0) const; }; +// .DSK disk image - 35 tracks, 16 sectors per track, 256 bytes per sector class DiskImage_DSK : public DiskImage { public: bool open(const Common::String &filename); - const DataBlockPtr getDataBlock(uint track, uint sector, uint offset, uint size) const; + const DataBlockPtr getDataBlock(uint track, uint sector, uint offset = 0, uint size = 0) const; Common::SeekableReadStream *createReadStream(uint track, uint sector, uint offset = 0, uint size = 0) const; }; +// Data in files contained in Apple DOS 3.3 disk image class Files_DOS33 : public Files { public: Files_DOS33(); @@ -141,7 +172,7 @@ private: Common::SeekableReadStream *createReadStreamText(const TOCEntry &entry) const; Common::SeekableReadStream *createReadStreamBinary(const TOCEntry &entry) const; - DiskImage_DSK *_disk; + DiskImage *_disk; Common::HashMap _toc; }; -- cgit v1.2.3