Don't capture parameters in static blocks. That never ends well...

This commit is contained in:
David Given
2022-02-27 12:51:51 +01:00
parent d97e72edb6
commit d5245e3784
4 changed files with 49 additions and 49 deletions

View File

@@ -34,13 +34,13 @@ std::unique_ptr<FluxSink> FluxSink::create(const FluxSinkProto& config)
void FluxSink::updateConfigForFilename(FluxSinkProto* proto, const std::string& filename)
{
static const std::vector<std::pair<std::regex, std::function<void(const std::string&)>>> formats =
static const std::vector<std::pair<std::regex, std::function<void(const std::string&, FluxSinkProto*)>>> formats =
{
{ std::regex("^(.*\\.flux)$"), [&](const auto& s) { proto->mutable_fl2()->set_filename(s); }},
{ std::regex("^(.*\\.scp)$"), [&](const auto& s) { proto->mutable_scp()->set_filename(s); }},
{ std::regex("^vcd:(.*)$"), [&](const auto& s) { proto->mutable_vcd()->set_directory(s); }},
{ std::regex("^au:(.*)$"), [&](const auto& s) { proto->mutable_au()->set_directory(s); }},
{ std::regex("^drive:(.*)"), [&](const auto& s) { proto->mutable_drive()->set_drive(std::stoi(s)); }},
{ std::regex("^(.*\\.flux)$"), [](auto& s, auto* proto) { proto->mutable_fl2()->set_filename(s); }},
{ std::regex("^(.*\\.scp)$"), [](auto& s, auto* proto) { proto->mutable_scp()->set_filename(s); }},
{ std::regex("^vcd:(.*)$"), [](auto& s, auto* proto) { proto->mutable_vcd()->set_directory(s); }},
{ std::regex("^au:(.*)$"), [](auto& s, auto* proto) { proto->mutable_au()->set_directory(s); }},
{ std::regex("^drive:(.*)"), [](auto& s, auto* proto) { proto->mutable_drive()->set_drive(std::stoi(s)); }},
};
for (const auto& it : formats)
@@ -48,7 +48,7 @@ void FluxSink::updateConfigForFilename(FluxSinkProto* proto, const std::string&
std::smatch match;
if (std::regex_match(filename, match, it.first))
{
it.second(match[1]);
it.second(match[1], proto);
return;
}
}

View File

@@ -48,15 +48,15 @@ std::unique_ptr<FluxSource> FluxSource::create(const FluxSourceProto& config)
void FluxSource::updateConfigForFilename(FluxSourceProto* proto, const std::string& filename)
{
static const std::vector<std::pair<std::regex, std::function<void(const std::string&)>>> formats =
static const std::vector<std::pair<std::regex, std::function<void(const std::string&, FluxSourceProto*)>>> formats =
{
{ std::regex("^(.*\\.flux)$"), [&](const auto& s) { proto->mutable_fl2()->set_filename(s); }},
{ std::regex("^(.*\\.scp)$"), [&](const auto& s) { proto->mutable_scp()->set_filename(s); }},
{ std::regex("^(.*\\.cwf)$"), [&](const auto& s) { proto->mutable_cwf()->set_filename(s); }},
{ std::regex("^erase:$"), [&](const auto& s) { proto->mutable_erase(); }},
{ std::regex("^kryoflux:(.*)$"), [&](const auto& s) { proto->mutable_kryoflux()->set_directory(s); }},
{ std::regex("^testpattern:(.*)"), [&](const auto& s) { proto->mutable_test_pattern(); }},
{ std::regex("^drive:(.*)"), [&](const auto& s) { proto->mutable_drive()->set_drive(std::stoi(s)); }},
{ std::regex("^(.*\\.flux)$"), [](auto& s, auto* proto) { proto->mutable_fl2()->set_filename(s); }},
{ std::regex("^(.*\\.scp)$"), [](auto& s, auto* proto) { proto->mutable_scp()->set_filename(s); }},
{ std::regex("^(.*\\.cwf)$"), [](auto& s, auto* proto) { proto->mutable_cwf()->set_filename(s); }},
{ std::regex("^erase:$"), [](auto& s, auto* proto) { proto->mutable_erase(); }},
{ std::regex("^kryoflux:(.*)$"), [](auto& s, auto* proto) { proto->mutable_kryoflux()->set_directory(s); }},
{ std::regex("^testpattern:(.*)"), [](auto& s, auto* proto) { proto->mutable_test_pattern(); }},
{ std::regex("^drive:(.*)"), [](auto& s, auto* proto) { proto->mutable_drive()->set_drive(std::stoi(s)); }},
};
for (const auto& it : formats)
@@ -64,7 +64,7 @@ void FluxSource::updateConfigForFilename(FluxSourceProto* proto, const std::stri
std::smatch match;
if (std::regex_match(filename, match, it.first))
{
it.second(match[1]);
it.second(match[1], proto);
return;
}
}

View File

@@ -55,32 +55,32 @@ std::unique_ptr<ImageReader> ImageReader::create(const ImageReaderProto& config)
void ImageReader::updateConfigForFilename(ImageReaderProto* proto, const std::string& filename)
{
static const std::map<std::string, std::function<void(void)>> formats =
static const std::map<std::string, std::function<void(ImageReaderProto*)>> formats =
{
{".adf", [&]() { proto->mutable_img(); }},
{".d64", [&]() { proto->mutable_d64(); }},
{".d81", [&]() { proto->mutable_img(); }},
{".d88", [&]() { proto->mutable_d88(); }},
{".dim", [&]() { proto->mutable_dim(); }},
{".diskcopy", [&]() { proto->mutable_diskcopy(); }},
{".dsk", [&]() { proto->mutable_img(); }},
{".fdi", [&]() { proto->mutable_fdi(); }},
{".imd", [&]() { proto->mutable_imd(); }},
{".img", [&]() { proto->mutable_img(); }},
{".jv3", [&]() { proto->mutable_jv3(); }},
{".nfd", [&]() { proto->mutable_nfd(); }},
{".nsi", [&]() { proto->mutable_nsi(); }},
{".st", [&]() { proto->mutable_img(); }},
{".td0", [&]() { proto->mutable_td0(); }},
{".vgi", [&]() { proto->mutable_img(); }},
{".xdf", [&]() { proto->mutable_img(); }},
{".adf", [](auto* proto) { proto->mutable_img(); }},
{".d64", [](auto* proto) { proto->mutable_d64(); }},
{".d81", [](auto* proto) { proto->mutable_img(); }},
{".d88", [](auto* proto) { proto->mutable_d88(); }},
{".dim", [](auto* proto) { proto->mutable_dim(); }},
{".diskcopy", [](auto* proto) { proto->mutable_diskcopy(); }},
{".dsk", [](auto* proto) { proto->mutable_img(); }},
{".fdi", [](auto* proto) { proto->mutable_fdi(); }},
{".imd", [](auto* proto) { proto->mutable_imd(); }},
{".img", [](auto* proto) { proto->mutable_img(); }},
{".jv3", [](auto* proto) { proto->mutable_jv3(); }},
{".nfd", [](auto* proto) { proto->mutable_nfd(); }},
{".nsi", [](auto* proto) { proto->mutable_nsi(); }},
{".st", [](auto* proto) { proto->mutable_img(); }},
{".td0", [](auto* proto) { proto->mutable_td0(); }},
{".vgi", [](auto* proto) { proto->mutable_img(); }},
{".xdf", [](auto* proto) { proto->mutable_img(); }},
};
for (const auto& it : formats)
{
if (endsWith(filename, it.first))
{
it.second();
it.second(proto);
proto->set_filename(filename);
return;
}

View File

@@ -40,27 +40,27 @@ std::unique_ptr<ImageWriter> ImageWriter::create(const ImageWriterProto& config)
void ImageWriter::updateConfigForFilename(ImageWriterProto* proto, const std::string& filename)
{
static const std::map<std::string, std::function<void(void)>> formats =
static const std::map<std::string, std::function<void(ImageWriterProto*)>> formats =
{
{".adf", [&]() { proto->mutable_img(); }},
{".d64", [&]() { proto->mutable_d64(); }},
{".d81", [&]() { proto->mutable_img(); }},
{".diskcopy", [&]() { proto->mutable_diskcopy(); }},
{".dsk", [&]() { proto->mutable_img(); }},
{".img", [&]() { proto->mutable_img(); }},
{".ldbs", [&]() { proto->mutable_ldbs(); }},
{".nsi", [&]() { proto->mutable_nsi(); }},
{".raw", [&]() { proto->mutable_raw(); }},
{".st", [&]() { proto->mutable_img(); }},
{".vgi", [&]() { proto->mutable_img(); }},
{".xdf", [&]() { proto->mutable_img(); }},
{".adf", [](auto* proto) { proto->mutable_img(); }},
{".d64", [](auto* proto) { proto->mutable_d64(); }},
{".d81", [](auto* proto) { proto->mutable_img(); }},
{".diskcopy", [](auto* proto) { proto->mutable_diskcopy(); }},
{".dsk", [](auto* proto) { proto->mutable_img(); }},
{".img", [](auto* proto) { proto->mutable_img(); }},
{".ldbs", [](auto* proto) { proto->mutable_ldbs(); }},
{".nsi", [](auto* proto) { proto->mutable_nsi(); }},
{".raw", [](auto* proto) { proto->mutable_raw(); }},
{".st", [](auto* proto) { proto->mutable_img(); }},
{".vgi", [](auto* proto) { proto->mutable_img(); }},
{".xdf", [](auto* proto) { proto->mutable_img(); }},
};
for (const auto& it : formats)
{
if (endsWith(filename, it.first))
{
it.second();
it.second(proto);
proto->set_filename(filename);
return;
}