mirror of
				https://github.com/davidgiven/fluxengine.git
				synced 2025-10-31 11:17:01 -07:00 
			
		
		
		
	Move setting the flux source into Config.
This commit is contained in:
		| @@ -5,14 +5,6 @@ | ||||
| #include "lib/config.pb.h" | ||||
| #include "proto.h" | ||||
| #include "utils.h" | ||||
| #include <regex> | ||||
|  | ||||
| static bool ends_with(const std::string& value, const std::string& ending) | ||||
| { | ||||
|     if (ending.size() > value.size()) | ||||
|         return false; | ||||
|     return std::equal(ending.rbegin(), ending.rend(), value.rbegin()); | ||||
| } | ||||
|  | ||||
| std::unique_ptr<FluxSource> FluxSource::create(const FluxSourceProto& config) | ||||
| { | ||||
| @@ -51,80 +43,6 @@ 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&, FluxSourceProto*)>>> | ||||
|         formats = { | ||||
|             {std::regex("^(.*\\.flux)$"), | ||||
|              [](auto& s, auto* proto) | ||||
|                 { | ||||
|                     proto->set_type(FluxSourceProto::FLUX); | ||||
|                     proto->mutable_fl2()->set_filename(s); | ||||
|                 }}, | ||||
|             {std::regex("^(.*\\.scp)$"), | ||||
|              [](auto& s, auto* proto) | ||||
|                 { | ||||
|                     proto->set_type(FluxSourceProto::SCP); | ||||
|                     proto->mutable_scp()->set_filename(s); | ||||
|                 }}, | ||||
|             {std::regex("^(.*\\.a2r)$"), | ||||
|              [](auto& s, auto* proto) | ||||
|                 { | ||||
|                     proto->set_type(FluxSourceProto::A2R); | ||||
|                     proto->mutable_a2r()->set_filename(s); | ||||
|                 }}, | ||||
|             {std::regex("^(.*\\.cwf)$"), | ||||
|              [](auto& s, auto* proto) | ||||
|                 { | ||||
|                     proto->set_type(FluxSourceProto::CWF); | ||||
|                     proto->mutable_cwf()->set_filename(s); | ||||
|                 }}, | ||||
|             {std::regex("^erase:$"), | ||||
|              [](auto& s, auto* proto) | ||||
|                 { | ||||
|                     proto->set_type(FluxSourceProto::ERASE); | ||||
|                 }}, | ||||
|             {std::regex("^kryoflux:(.*)$"), | ||||
|              [](auto& s, auto* proto) | ||||
|                 { | ||||
|                     proto->set_type(FluxSourceProto::KRYOFLUX); | ||||
|                     proto->mutable_kryoflux()->set_directory(s); | ||||
|                 }}, | ||||
|             {std::regex("^testpattern:(.*)"), | ||||
|              [](auto& s, auto* proto) | ||||
|                 { | ||||
|                     proto->set_type(FluxSourceProto::TEST_PATTERN); | ||||
|                 }}, | ||||
|             {std::regex("^drive:(.*)"), | ||||
|              [](auto& s, auto* proto) | ||||
|                 { | ||||
|                     proto->set_type(FluxSourceProto::DRIVE); | ||||
|                     globalConfig()->mutable_drive()->set_drive(std::stoi(s)); | ||||
|                 }}, | ||||
|             {std::regex("^flx:(.*)$"), | ||||
|              [](auto& s, auto* proto) | ||||
|                 { | ||||
|                     proto->set_type(FluxSourceProto::FLX); | ||||
|                     proto->mutable_flx()->set_directory(s); | ||||
|                 }}, | ||||
|     }; | ||||
|  | ||||
|     for (const auto& it : formats) | ||||
|     { | ||||
|         std::smatch match; | ||||
|         if (std::regex_match(filename, match, it.first)) | ||||
|         { | ||||
|             it.second(match[1], proto); | ||||
|             return; | ||||
|         } | ||||
|     } | ||||
|  | ||||
|     error("unrecognised flux filename '{}'", filename); | ||||
| } | ||||
|  | ||||
| class TrivialFluxSourceIterator : public FluxSourceIterator | ||||
| { | ||||
| public: | ||||
|   | ||||
| @@ -56,8 +56,6 @@ public: | ||||
|         const DiskFlux& flux); | ||||
|  | ||||
|     static std::unique_ptr<FluxSource> create(const FluxSourceProto& spec); | ||||
|     static void updateConfigForFilename( | ||||
|         FluxSourceProto* proto, const std::string& filename); | ||||
|  | ||||
| public: | ||||
|     virtual std::unique_ptr<FluxSourceIterator> readFlux( | ||||
|   | ||||
		Reference in New Issue
	
	Block a user