#include #include "Phone.h" using std::string; template boost::bimap makeBimap(std::initializer_list::value_type> list) { return boost::bimap(list.begin(), list.end()); } boost::bimap phonesByName = makeBimap({ { "None", Phone::None }, { "Unknown", Phone::Unknown }, { "AO", Phone::AO }, { "AA", Phone::AA }, { "IY", Phone::IY }, { "UW", Phone::UW }, { "EH", Phone::EH }, { "IH", Phone::IH }, { "UH", Phone::UH }, { "AH", Phone::AH }, { "AE", Phone::AE }, { "EY", Phone::EY }, { "AY", Phone::AY }, { "OW", Phone::OW }, { "AW", Phone::AW }, { "OY", Phone::OY }, { "ER", Phone::ER }, { "P", Phone::P }, { "B", Phone::B }, { "T", Phone::T }, { "D", Phone::D }, { "K", Phone::K }, { "G", Phone::G }, { "CH", Phone::CH }, { "JH", Phone::JH }, { "F", Phone::F }, { "V", Phone::V }, { "TH", Phone::TH }, { "DH", Phone::DH }, { "S", Phone::S }, { "Z", Phone::Z }, { "SH", Phone::SH }, { "ZH", Phone::ZH }, { "HH", Phone::HH }, { "M", Phone::M }, { "N", Phone::N }, { "NG", Phone::NG }, { "L", Phone::L }, { "R", Phone::R }, { "Y", Phone::Y }, { "W", Phone::W }, }); Phone stringToPhone(const string& s) { if (s == "SIL") return Phone::None; auto it = phonesByName.left.find(s); return (it != phonesByName.left.end()) ? it->second : Phone::Unknown; } string phoneToString(Phone phone) { auto it = phonesByName.right.find(phone); return (it != phonesByName.right.end()) ? it->second : phoneToString(Phone::Unknown); } std::ostream &operator<<(std::ostream &stream, const Phone phone) { return stream << phoneToString(phone); }