Skip to content

Commit 6d3969a

Browse files
committed
Split the dependency so that the encoders/decoders don't depend on arch.
1 parent ea35551 commit 6d3969a

File tree

10 files changed

+133
-121
lines changed

10 files changed

+133
-121
lines changed

arch/arch.cc

Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
#include "lib/core/globals.h"
2+
#include "lib/encoders/encoders.h"
3+
#include "lib/decoders/decoders.h"
4+
#include "lib/config/config.h"
5+
#include "arch/agat/agat.h"
6+
#include "arch/aeslanier/aeslanier.h"
7+
#include "arch/amiga/amiga.h"
8+
#include "arch/apple2/apple2.h"
9+
#include "arch/brother/brother.h"
10+
#include "arch/c64/c64.h"
11+
#include "arch/f85/f85.h"
12+
#include "arch/fb100/fb100.h"
13+
#include "arch/ibm/ibm.h"
14+
#include "arch/macintosh/macintosh.h"
15+
#include "arch/micropolis/micropolis.h"
16+
#include "arch/mx/mx.h"
17+
#include "arch/northstar/northstar.h"
18+
#include "arch/rolandd20/rolandd20.h"
19+
#include "arch/smaky6/smaky6.h"
20+
#include "arch/tartu/tartu.h"
21+
#include "arch/tids990/tids990.h"
22+
#include "arch/victor9k/victor9k.h"
23+
#include "arch/zilogmcz/zilogmcz.h"
24+
#include "arch/arch.h"
25+
26+
std::unique_ptr<Encoder> Arch::createEncoder(Config& config)
27+
{
28+
if (!config.hasEncoder())
29+
error("no encoder configured");
30+
return createEncoder(config->encoder());
31+
}
32+
33+
std::unique_ptr<Encoder> Arch::createEncoder(const EncoderProto& config){
34+
static const std::map<int,
35+
std::function<std::unique_ptr<Encoder>(const EncoderProto&)>>
36+
encoders = {
37+
{EncoderProto::kAgat, createAgatEncoder },
38+
{EncoderProto::kAmiga, createAmigaEncoder },
39+
{EncoderProto::kApple2, createApple2Encoder },
40+
{EncoderProto::kBrother, createBrotherEncoder },
41+
{EncoderProto::kC64, createCommodore64Encoder},
42+
{EncoderProto::kIbm, createIbmEncoder },
43+
{EncoderProto::kMacintosh, createMacintoshEncoder },
44+
{EncoderProto::kMicropolis, createMicropolisEncoder },
45+
{EncoderProto::kNorthstar, createNorthstarEncoder },
46+
{EncoderProto::kTartu, createTartuEncoder },
47+
{EncoderProto::kTids990, createTids990Encoder },
48+
{EncoderProto::kVictor9K, createVictor9kEncoder },
49+
};
50+
51+
auto encoder = encoders.find(config.format_case());
52+
if (encoder == encoders.end())
53+
error("no encoder specified");
54+
55+
return (encoder->second)(config);
56+
}
57+
58+
std::unique_ptr<Decoder> Arch::createDecoder(Config& config)
59+
{
60+
if (!config.hasDecoder())
61+
error("no decoder configured");
62+
return createDecoder(config->decoder());
63+
}
64+
65+
std::unique_ptr<Decoder> Arch::createDecoder(const DecoderProto& config)
66+
{
67+
static const std::map<int,
68+
std::function<std::unique_ptr<Decoder>(const DecoderProto&)>>
69+
decoders = {
70+
{DecoderProto::kAgat, createAgatDecoder },
71+
{DecoderProto::kAeslanier, createAesLanierDecoder },
72+
{DecoderProto::kAmiga, createAmigaDecoder },
73+
{DecoderProto::kApple2, createApple2Decoder },
74+
{DecoderProto::kBrother, createBrotherDecoder },
75+
{DecoderProto::kC64, createCommodore64Decoder},
76+
{DecoderProto::kF85, createDurangoF85Decoder },
77+
{DecoderProto::kFb100, createFb100Decoder },
78+
{DecoderProto::kIbm, createIbmDecoder },
79+
{DecoderProto::kMacintosh, createMacintoshDecoder },
80+
{DecoderProto::kMicropolis, createMicropolisDecoder },
81+
{DecoderProto::kMx, createMxDecoder },
82+
{DecoderProto::kNorthstar, createNorthstarDecoder },
83+
{DecoderProto::kRolandd20, createRolandD20Decoder },
84+
{DecoderProto::kSmaky6, createSmaky6Decoder },
85+
{DecoderProto::kTartu, createTartuDecoder },
86+
{DecoderProto::kTids990, createTids990Decoder },
87+
{DecoderProto::kVictor9K, createVictor9kDecoder },
88+
{DecoderProto::kZilogmcz, createZilogMczDecoder },
89+
};
90+
91+
auto decoder = decoders.find(config.format_case());
92+
if (decoder == decoders.end())
93+
error("no decoder specified");
94+
95+
return (decoder->second)(config);
96+
}

arch/arch.h

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#pragma once
2+
3+
class Encoder;
4+
class Decoder;
5+
class DecoderProto;
6+
class EncoderProto;
7+
class Config;
8+
9+
namespace Arch
10+
{
11+
std::unique_ptr<Decoder> createDecoder(Config& config);
12+
std::unique_ptr<Decoder> createDecoder(const DecoderProto& config);
13+
14+
std::unique_ptr<Encoder> createEncoder(Config& config);
15+
std::unique_ptr<Encoder> createEncoder(const EncoderProto& config);
16+
}

build.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
"./lib/decoders/fmmfm.cc",
2828
"./lib/encoders/encoders.cc",
2929
"./lib/readerwriter.cc",
30+
"./arch/arch.cc",
3031
"./arch/aeslanier/decoder.cc",
3132
"./arch/agat/agat.cc",
3233
"./arch/agat/decoder.cc",
@@ -89,6 +90,7 @@
8990
"arch/c64/data_gcr.h": "./arch/c64/data_gcr.h",
9091
"arch/c64/c64.h": "./arch/c64/c64.h",
9192
"arch/tartu/tartu.h": "./arch/tartu/tartu.h",
93+
"arch/arch.h": "./arch/arch.h",
9294
"lib/decoders/decoders.h": "./lib/decoders/decoders.h",
9395
"lib/decoders/fluxdecoder.h": "./lib/decoders/fluxdecoder.h",
9496
"lib/decoders/rawbits.h": "./lib/decoders/rawbits.h",

lib/decoders/decoders.cc

Lines changed: 0 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -4,25 +4,6 @@
44
#include "lib/config/config.h"
55
#include "lib/decoders/decoders.h"
66
#include "lib/encoders/encoders.h"
7-
#include "arch/agat/agat.h"
8-
#include "arch/aeslanier/aeslanier.h"
9-
#include "arch/amiga/amiga.h"
10-
#include "arch/apple2/apple2.h"
11-
#include "arch/brother/brother.h"
12-
#include "arch/c64/c64.h"
13-
#include "arch/f85/f85.h"
14-
#include "arch/fb100/fb100.h"
15-
#include "arch/ibm/ibm.h"
16-
#include "arch/macintosh/macintosh.h"
17-
#include "arch/micropolis/micropolis.h"
18-
#include "arch/mx/mx.h"
19-
#include "arch/northstar/northstar.h"
20-
#include "arch/rolandd20/rolandd20.h"
21-
#include "arch/smaky6/smaky6.h"
22-
#include "arch/tartu/tartu.h"
23-
#include "arch/tids990/tids990.h"
24-
#include "arch/victor9k/victor9k.h"
25-
#include "arch/zilogmcz/zilogmcz.h"
267
#include "lib/data/fluxmapreader.h"
278
#include "lib/data/flux.h"
289
#include "protocol.h"
@@ -33,45 +14,6 @@
3314
#include "lib/data/layout.h"
3415
#include <numeric>
3516

36-
std::unique_ptr<Decoder> Decoder::create(Config& config)
37-
{
38-
if (!config.hasDecoder())
39-
error("no decoder configured");
40-
return create(config->decoder());
41-
}
42-
43-
std::unique_ptr<Decoder> Decoder::create(const DecoderProto& config)
44-
{
45-
static const std::map<int,
46-
std::function<std::unique_ptr<Decoder>(const DecoderProto&)>>
47-
decoders = {
48-
{DecoderProto::kAgat, createAgatDecoder },
49-
{DecoderProto::kAeslanier, createAesLanierDecoder },
50-
{DecoderProto::kAmiga, createAmigaDecoder },
51-
{DecoderProto::kApple2, createApple2Decoder },
52-
{DecoderProto::kBrother, createBrotherDecoder },
53-
{DecoderProto::kC64, createCommodore64Decoder},
54-
{DecoderProto::kF85, createDurangoF85Decoder },
55-
{DecoderProto::kFb100, createFb100Decoder },
56-
{DecoderProto::kIbm, createIbmDecoder },
57-
{DecoderProto::kMacintosh, createMacintoshDecoder },
58-
{DecoderProto::kMicropolis, createMicropolisDecoder },
59-
{DecoderProto::kMx, createMxDecoder },
60-
{DecoderProto::kNorthstar, createNorthstarDecoder },
61-
{DecoderProto::kRolandd20, createRolandD20Decoder },
62-
{DecoderProto::kSmaky6, createSmaky6Decoder },
63-
{DecoderProto::kTartu, createTartuDecoder },
64-
{DecoderProto::kTids990, createTids990Decoder },
65-
{DecoderProto::kVictor9K, createVictor9kDecoder },
66-
{DecoderProto::kZilogmcz, createZilogMczDecoder },
67-
};
68-
69-
auto decoder = decoders.find(config.format_case());
70-
if (decoder == decoders.end())
71-
error("no decoder specified");
72-
73-
return (decoder->second)(config);
74-
}
7517

7618
std::shared_ptr<TrackDataFlux> Decoder::decodeToSectors(
7719
std::shared_ptr<const Fluxmap> fluxmap,

lib/encoders/encoders.cc

Lines changed: 0 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -3,57 +3,12 @@
33
#include "lib/data/fluxmap.h"
44
#include "lib/decoders/decoders.h"
55
#include "lib/encoders/encoders.h"
6-
#include "arch/agat/agat.h"
7-
#include "arch/amiga/amiga.h"
8-
#include "arch/apple2/apple2.h"
9-
#include "arch/brother/brother.h"
10-
#include "arch/c64/c64.h"
11-
#include "arch/ibm/ibm.h"
12-
#include "arch/macintosh/macintosh.h"
13-
#include "arch/micropolis/micropolis.h"
14-
#include "arch/northstar/northstar.h"
15-
#include "arch/tartu/tartu.h"
16-
#include "arch/tids990/tids990.h"
17-
#include "arch/victor9k/victor9k.h"
186
#include "lib/encoders/encoders.pb.h"
197
#include "lib/config/proto.h"
208
#include "lib/data/layout.h"
219
#include "lib/data/image.h"
2210
#include "protocol.h"
2311

24-
std::unique_ptr<Encoder> Encoder::create(Config& config)
25-
{
26-
if (!config.hasEncoder())
27-
error("no encoder configured");
28-
return create(config->encoder());
29-
}
30-
31-
std::unique_ptr<Encoder> Encoder::create(const EncoderProto& config)
32-
{
33-
static const std::map<int,
34-
std::function<std::unique_ptr<Encoder>(const EncoderProto&)>>
35-
encoders = {
36-
{EncoderProto::kAgat, createAgatEncoder },
37-
{EncoderProto::kAmiga, createAmigaEncoder },
38-
{EncoderProto::kApple2, createApple2Encoder },
39-
{EncoderProto::kBrother, createBrotherEncoder },
40-
{EncoderProto::kC64, createCommodore64Encoder},
41-
{EncoderProto::kIbm, createIbmEncoder },
42-
{EncoderProto::kMacintosh, createMacintoshEncoder },
43-
{EncoderProto::kMicropolis, createMicropolisEncoder },
44-
{EncoderProto::kNorthstar, createNorthstarEncoder },
45-
{EncoderProto::kTartu, createTartuEncoder },
46-
{EncoderProto::kTids990, createTids990Encoder },
47-
{EncoderProto::kVictor9K, createVictor9kEncoder },
48-
};
49-
50-
auto encoder = encoders.find(config.format_case());
51-
if (encoder == encoders.end())
52-
error("no encoder specified");
53-
54-
return (encoder->second)(config);
55-
}
56-
5712
nanoseconds_t Encoder::calculatePhysicalClockPeriod(
5813
nanoseconds_t targetClockPeriod, nanoseconds_t targetRotationalPeriod)
5914
{

lib/encoders/encoders.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ class Encoder
1616
virtual ~Encoder() {}
1717

1818
static std::unique_ptr<Encoder> create(Config& config);
19-
static std::unique_ptr<Encoder> create(const EncoderProto& config);
2019

2120
public:
2221
virtual std::shared_ptr<const Sector> getSector(

lib/vfs/vfs.cc

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
#include "lib/encoders/encoders.h"
1616
#include "lib/config/config.pb.h"
1717
#include "lib/core/utils.h"
18+
#include "arch/arch.h"
1819

1920
Path::Path(const std::vector<std::string> other):
2021
std::vector<std::string>(other)
@@ -244,12 +245,12 @@ std::unique_ptr<Filesystem> Filesystem::createFilesystemFromConfig()
244245
if (globalConfig().hasFluxSource())
245246
{
246247
fluxSource = FluxSource::create(globalConfig());
247-
decoder = Decoder::create(globalConfig());
248+
decoder = Arch::createDecoder(globalConfig());
248249
}
249250
if (globalConfig()->flux_sink().type() == FLUXTYPE_DRIVE)
250251
{
251252
fluxSink = FluxSink::create(globalConfig());
252-
encoder = Encoder::create(globalConfig());
253+
encoder = Arch::createEncoder(globalConfig());
253254
}
254255
sectorInterface = SectorInterface::createFluxSectorInterface(
255256
fluxSource, fluxSink, encoder, decoder);

src/fe-read.cc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#include "lib/fluxsource/fluxsource.h"
1010
#include "lib/fluxsink/fluxsink.h"
1111
#include "lib/imagewriter/imagewriter.h"
12+
#include "arch/arch.h"
1213
#include "fluxengine.h"
1314
#include <google/protobuf/text_format.h>
1415
#include <fstream>
@@ -66,7 +67,7 @@ int mainRead(int argc, const char* argv[])
6667
error("you cannot copy flux to a hardware device");
6768

6869
auto fluxSource = FluxSource::create(globalConfig());
69-
auto decoder = Decoder::create(globalConfig());
70+
auto decoder = Arch::createDecoder(globalConfig());
7071
auto writer = ImageWriter::create(globalConfig());
7172

7273
readDiskCommand(*fluxSource, *decoder, *writer);

src/fe-write.cc

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,7 @@
99
#include "lib/config/proto.h"
1010
#include "lib/fluxsink/fluxsink.h"
1111
#include "lib/fluxsource/fluxsource.h"
12-
#include "arch/brother/brother.h"
13-
#include "arch/ibm/ibm.h"
12+
#include "arch/arch.h"
1413
#include "lib/imagereader/imagereader.h"
1514
#include "fluxengine.h"
1615
#include <google/protobuf/text_format.h>
@@ -71,14 +70,14 @@ int mainWrite(int argc, const char* argv[])
7170
auto reader = ImageReader::create(globalConfig());
7271
std::shared_ptr<Image> image = reader->readMappedImage();
7372

74-
auto encoder = Encoder::create(globalConfig());
73+
auto encoder = Arch::createEncoder(globalConfig());
7574
auto fluxSink = FluxSink::create(globalConfig());
7675

7776
std::shared_ptr<Decoder> decoder;
7877
std::shared_ptr<FluxSource> verificationFluxSource;
7978
if (globalConfig().hasDecoder() && fluxSink->isHardware() && verify)
8079
{
81-
decoder = Decoder::create(globalConfig());
80+
decoder = Arch::createDecoder(globalConfig());
8281
verificationFluxSource =
8382
FluxSource::create(globalConfig().getVerificationFluxSourceProto());
8483
}

src/gui/context.cc

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
1-
#include <lib/core/globals.h>
2-
#include <lib/fluxsource/fluxsource.h>
3-
#include <lib/fluxsink/fluxsink.h>
4-
#include <lib/imagereader/imagereader.h>
5-
#include <lib/imagewriter/imagewriter.h>
6-
#include <lib/decoders/decoders.h>
7-
#include <lib/encoders/encoders.h>
8-
#include <lib/config/config.h>
1+
#include "lib/core/globals.h"
2+
#include "lib/fluxsource/fluxsource.h"
3+
#include "lib/fluxsink/fluxsink.h"
4+
#include "lib/imagereader/imagereader.h"
5+
#include "lib/imagewriter/imagewriter.h"
6+
#include "lib/decoders/decoders.h"
7+
#include "lib/encoders/encoders.h"
8+
#include "arch/arch.h"
9+
#include "lib/config/config.h"
910
#include "context.h"
1011
#include "gui.h"
1112

@@ -64,7 +65,7 @@ namespace
6465
{
6566
if (!_encoder)
6667
{
67-
_encoder = Encoder::create(globalConfig());
68+
_encoder = Arch::createEncoder(globalConfig());
6869
}
6970
return _encoder.get();
7071
}
@@ -73,7 +74,7 @@ namespace
7374
{
7475
if (!_decoder)
7576
{
76-
_decoder = Decoder::create(globalConfig());
77+
_decoder = Arch::createDecoder(globalConfig());
7778
}
7879
return _decoder.get();
7980
}

0 commit comments

Comments
 (0)