/* This file is part of solidity. solidity is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. solidity is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with solidity. If not, see . */ /** * Miscellaneous utilities for use in yul-phaser. */ #pragma once #include #include namespace solidity::phaser { /// Reads a token from the input stream and translates it to a string using a map. /// Sets the failbit in the stream if there's no matching value in the map. template std::istream& deserializeChoice( std::istream& _inputStream, C& _choice, std::map const& _stringToValueMap ) { std::string deserializedValue; _inputStream >> deserializedValue; auto const& pair = _stringToValueMap.find(deserializedValue); if (pair != _stringToValueMap.end()) _choice = pair->second; else _inputStream.setstate(std::ios_base::failbit); return _inputStream; } /// Translates a value to a string using a map and prints it to the output stream. /// Sets the failbit if the value is not in the map. template std::ostream& serializeChoice( std::ostream& _outputStream, C const& _choice, std::map const& _valueToStringMap ) { auto const& pair = _valueToStringMap.find(_choice); if (pair != _valueToStringMap.end()) _outputStream << pair->second; else _outputStream.setstate(std::ios_base::failbit); return _outputStream; } }