Contact ContactManager::get_contact_by_phone(string phone) { if(!phone_exists(phone)) { throw ContactMissingException(); } return phone_map[phone]; }
Contact ContactManager::get_contact_by_name(string name) { if(!name_exists(name)) { throw ContactMissingException(); } return name_map[name]; }
void ContactManager::update_email(string name, string new_email) { if(!name_map.count(name)) { throw ContactMissingException(); } Contact& c = name_map[name]; c.email = new_email; phone_map[c.phone].email = c.email; }
void ContactManager::update_email(string name, string new_email) { if(!name_map.contains(name)) { throw ContactMissingException(); } Contact c = name_map.get(name); c.email = new_email; name_map.add(name, c); phone_map.add(c.phone, c); }
void ContactManager::update_phone(string name, string new_number) { if(!name_map.count(name)) { throw ContactMissingException(); } Contact& c = name_map[name]; string old_number = c.phone; c.phone = new_number; phone_map.erase(phone_map.find(old_number)); phone_map[c.phone] = c; }
void ContactManager::update_phone(string name, string new_number) { if(!name_map.contains(name)) { throw ContactMissingException(); } Contact c = name_map.get(name); string old_number = c.phone; c.phone = new_number; name_map.add(name, c); phone_map.remove(old_number); phone_map.add(c.phone, c); }