diff --git a/tools/yulPhaser/Phaser.cpp b/tools/yulPhaser/Phaser.cpp index 45d9672d1..44fb9d130 100644 --- a/tools/yulPhaser/Phaser.cpp +++ b/tools/yulPhaser/Phaser.cpp @@ -18,6 +18,7 @@ #include #include +#include #include #include #include @@ -27,6 +28,7 @@ #include #include +#include #include #include @@ -41,32 +43,20 @@ using namespace solidity::phaser; namespace po = boost::program_options; -istream& phaser::operator>>(istream& _inputStream, Algorithm& _algorithm) +namespace { - string value; - _inputStream >> value; - if (value == "random") - _algorithm = Algorithm::Random; - else if (value == "GEWEP") - _algorithm = Algorithm::GEWEP; - else - _inputStream.setstate(ios_base::failbit); +map const AlgorithmToStringMap = +{ + {Algorithm::Random, "random"}, + {Algorithm::GEWEP, "GEWEP"}, +}; +map const StringToAlgorithmMap = invertMap(AlgorithmToStringMap); - return _inputStream; } -ostream& phaser::operator<<(ostream& _outputStream, Algorithm _algorithm) -{ - if (_algorithm == Algorithm::Random) - _outputStream << "random"; - else if (_algorithm == Algorithm::GEWEP) - _outputStream << "GEWEP"; - else - _outputStream.setstate(ios_base::failbit); - - return _outputStream; -} +istream& phaser::operator>>(istream& _inputStream, Algorithm& _algorithm) { return deserializeChoice(_inputStream, _algorithm, StringToAlgorithmMap); } +ostream& phaser::operator<<(ostream& _outputStream, Algorithm _algorithm) { return serializeChoice(_outputStream, _algorithm, AlgorithmToStringMap); } GeneticAlgorithmFactory::Options GeneticAlgorithmFactory::Options::fromCommandLine(po::variables_map const& _arguments) {