More SectorInterface refactoring.

This commit is contained in:
David Given
2022-08-26 00:43:01 +02:00
parent 9007e264cf
commit f0ec8bd5b9
5 changed files with 36 additions and 22 deletions

View File

@@ -67,6 +67,7 @@ LIBFLUXENGINE_SRCS = \
lib/vfs/brother120fs.cc \
lib/vfs/acorndfs.cc \
lib/vfs/vfs.cc \
lib/vfs/imagesectorinterface.cc \
LIBFLUXENGINE_OBJS = $(patsubst %.cc, $(OBJDIR)/%.o, $(LIBFLUXENGINE_SRCS))
OBJS += $(LIBFLUXENGINE_OBJS)

View File

@@ -0,0 +1,31 @@
#include "lib/globals.h"
#include "lib/vfs/sectorinterface.h"
#include "lib/image.h"
class ImageSectorInterface : public SectorInterface
{
public:
ImageSectorInterface(std::shared_ptr<Image> image):
_image(image)
{}
public:
std::shared_ptr<const Sector> get(unsigned track, unsigned side, unsigned sectorId)
{
return _image->get(track, side, sectorId);
}
std::shared_ptr<Sector> put(unsigned track, unsigned side, unsigned sectorId)
{
return _image->put(track, side, sectorId);
}
private:
std::shared_ptr<Image> _image;
};
std::unique_ptr<SectorInterface> SectorInterface::createImageSectorInterface(std::shared_ptr<Image> image)
{
return std::make_unique<ImageSectorInterface>(image);
}

View File

@@ -2,6 +2,7 @@
#define SECTORINTERFACE_H
class Image;
class Sector;
class SectorInterface
{
@@ -10,28 +11,9 @@ public:
virtual std::shared_ptr<Sector> put(unsigned track, unsigned side, unsigned sectorId) = 0;
virtual void flush() {}
};
class ImageSectorInterface : public SectorInterface
{
public:
ImageSectorInterface(std::shared_ptr<Image> image):
_image(image)
{}
public:
std::shared_ptr<const Sector> get(unsigned track, unsigned side, unsigned sectorId)
{
return _image->get(track, side, sectorId);
}
std::shared_ptr<Sector> put(unsigned track, unsigned side, unsigned sectorId)
{
return _image->put(track, side, sectorId);
}
private:
std::shared_ptr<Image> _image;
static std::unique_ptr<SectorInterface> createImageSectorInterface(std::shared_ptr<Image> image);
};
#endif

View File

@@ -51,7 +51,7 @@ int mainGetFileInfo(int argc, const char* argv[])
auto reader = ImageReader::create(config.image_reader());
std::shared_ptr<Image> image(std::move(reader->readImage()));
sectorInterface = std::make_shared<ImageSectorInterface>(image);
sectorInterface = SectorInterface::createImageSectorInterface(image);
auto filesystem =
Filesystem::createFilesystem(config.filesystem(), sectorInterface);

View File

@@ -60,7 +60,7 @@ int mainLs(int argc, const char* argv[])
auto reader = ImageReader::create(config.image_reader());
std::shared_ptr<Image> image(std::move(reader->readImage()));
sectorInterface = std::make_shared<ImageSectorInterface>(image);
sectorInterface = SectorInterface::createImageSectorInterface(image);
auto filesystem =
Filesystem::createFilesystem(config.filesystem(), sectorInterface);