mirror of
https://github.com/davidgiven/fluxengine.git
synced 2025-10-31 11:17:01 -07:00
Switch to resource path type thingies for specifying flux file types, where
appropriate. Much better.
This commit is contained in:
@@ -6,6 +6,7 @@
|
||||
#include "proto.h"
|
||||
#include "utils.h"
|
||||
#include "fmt/format.h"
|
||||
#include <regex>
|
||||
|
||||
std::unique_ptr<FluxSink> FluxSink::create(const FluxSinkProto& config)
|
||||
{
|
||||
@@ -34,19 +35,20 @@ std::unique_ptr<FluxSink> FluxSink::create(const FluxSinkProto& config)
|
||||
void FluxSink::updateConfigForFilename(const std::string& filename)
|
||||
{
|
||||
FluxSinkProto* f = config.mutable_output()->mutable_flux();
|
||||
static const std::map<std::string, std::function<void(void)>> formats =
|
||||
static const std::vector<std::pair<std::regex, std::function<void(const std::string&)>>> formats =
|
||||
{
|
||||
{".flux", [&]() { f->set_fluxfile(filename); }},
|
||||
{".scp", [&]() { f->mutable_scp()->set_filename(filename); }},
|
||||
{".vcd", [&]() { f->mutable_vcd()->set_directory(filename); }},
|
||||
{".au", [&]() { f->mutable_au()->set_directory(filename); }},
|
||||
{ std::regex("^(.*\\.flux)$"), [&](const auto& s) { f->set_fluxfile(s); }},
|
||||
{ std::regex("^(.*\\.scp)$"), [&](const auto& s) { f->mutable_scp()->set_filename(s); }},
|
||||
{ std::regex("^vcd:(.*)$"), [&](const auto& s) { f->mutable_vcd()->set_directory(s); }},
|
||||
{ std::regex("^au:(.*)$"), [&](const auto& s) { f->mutable_au()->set_directory(s); }},
|
||||
};
|
||||
|
||||
for (const auto& it : formats)
|
||||
{
|
||||
if (endsWith(filename, it.first))
|
||||
std::smatch match;
|
||||
if (std::regex_match(filename, match, it.first))
|
||||
{
|
||||
it.second();
|
||||
it.second(match[1]);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,6 +3,10 @@
|
||||
#include "dataspec.h"
|
||||
#include "fluxsource/fluxsource.h"
|
||||
#include "lib/config.pb.h"
|
||||
#include "proto.h"
|
||||
#include "utils.h"
|
||||
#include "fmt/format.h"
|
||||
#include <regex>
|
||||
|
||||
static bool ends_with(const std::string& value, const std::string& ending)
|
||||
{
|
||||
@@ -35,3 +39,29 @@ std::unique_ptr<FluxSource> FluxSource::create(const FluxSourceProto& config)
|
||||
return std::unique_ptr<FluxSource>();
|
||||
}
|
||||
|
||||
void FluxSource::updateConfigForFilename(const std::string& filename)
|
||||
{
|
||||
FluxSourceProto* f = config.mutable_input()->mutable_flux();
|
||||
static const std::vector<std::pair<std::regex, std::function<void(const std::string&)>>> formats =
|
||||
{
|
||||
{ std::regex("^(.*\\.flux)$"), [&](const auto& s) { f->set_fluxfile(s); }},
|
||||
{ std::regex("^erase:$"), [&](const auto& s) { f->mutable_erase(); }},
|
||||
{ std::regex("^kryoflux:(.*)$"), [&](const auto& s) { f->mutable_kryoflux()->set_directory(s); }},
|
||||
{ std::regex("^testpattern:(.*)"), [&](const auto& s) { f->mutable_test_pattern(); }},
|
||||
};
|
||||
|
||||
for (const auto& it : formats)
|
||||
{
|
||||
std::smatch match;
|
||||
if (std::regex_match(filename, match, it.first))
|
||||
{
|
||||
it.second(match[1]);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
Error() << fmt::format("unrecognised flux filename '{}'", filename);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -25,6 +25,7 @@ private:
|
||||
|
||||
public:
|
||||
static std::unique_ptr<FluxSource> create(const FluxSourceProto& spec);
|
||||
static void updateConfigForFilename(const std::string& filename);
|
||||
|
||||
public:
|
||||
virtual std::unique_ptr<Fluxmap> readFlux(int track, int side) = 0;
|
||||
|
||||
@@ -21,7 +21,7 @@ message TestPatternFluxSourceProto {
|
||||
message EraseFluxSourceProto {}
|
||||
|
||||
message KryofluxFluxSourceProto {
|
||||
optional string path = 1 [(help) = "path to Kryoflux stream directory"];
|
||||
optional string directory = 1 [(help) = "path to Kryoflux stream directory"];
|
||||
}
|
||||
|
||||
message FluxSourceProto {
|
||||
|
||||
@@ -8,7 +8,7 @@ class KryofluxFluxSource : public FluxSource
|
||||
{
|
||||
public:
|
||||
KryofluxFluxSource(const KryofluxFluxSourceProto& config):
|
||||
_path(config.path())
|
||||
_path(config.directory())
|
||||
{}
|
||||
|
||||
public:
|
||||
|
||||
Reference in New Issue
Block a user