// PhonebookList.h #include #include #include #include "PhoneBookEntry.h" class PhoneBookList { public: PhoneBookList() : itr_current_entry(m_entries.end()) {} void add( const std::string & name, const std::string & number ); void display_current_entry() const; void move_to_next(); void edit_current(const std::string & new_number); void find(const std::string & name); bool empty() const { return m_entries.empty(); } void read_file( const std::string & file_name ); void write_file( const std::string & file_name ) const; private: std::map m_entries; std::map::iterator itr_current_entry; }; inline void PhoneBookList::add(const std::string & name, const std::string & number) { auto result = // m_entries.insert( // std::pair( // name, PhoneBookEntry(name, number))); // m_entries.insert({name, PhoneBookEntry(name, number)}); m_entries.insert({name, {name, number}}); itr_current_entry = result.first; } inline void PhoneBookList::display_current_entry() const { if (m_entries.empty()) return; std::cout << itr_current_entry->second; } inline void PhoneBookList::move_to_next() { if (m_entries.empty()) return; ++itr_current_entry; if (itr_current_entry == m_entries.end()) { itr_current_entry = m_entries.begin(); } } inline void PhoneBookList::edit_current( const std::string & new_number) { itr_current_entry->second.number = new_number; } inline void PhoneBookList::find(const std::string & name) { auto itr = m_entries.find(name); if (itr != m_entries.end()) itr_current_entry = itr; }