-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPhoneBookMap.h
More file actions
46 lines (38 loc) · 1.82 KB
/
PhoneBookMap.h
File metadata and controls
46 lines (38 loc) · 1.82 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
// ===============================================================================
// PhoneBookMap.h // Using std::unordered_map
// ===============================================================================
#pragma once
#include "IPhoneBook.h"
#include <cstddef>
#include <forward_list>
#include <string>
#include <unordered_map>
namespace PhoneBook
{
class PhoneBookMap : public IPhoneBook
{
private:
std::unordered_map<std::string, std::size_t> m_map;
public:
// public interface
std::size_t size() const override;
bool insert(const std::string& first, const std::string& last, std::size_t number) override;
bool update(const std::string& first, const std::string& last, std::size_t number) override;
bool search(const std::string& first, const std::string& last, std::size_t& number) const override;
bool remove(const std::string& first, const std::string& last) override;
bool contains(const std::string& first, const std::string& last) const override;
std::forward_list<std::string> getNames() const override;
std::string toString() const override;
void print()const override;
private:
// helper methods
static std::pair<std::string, std::string> getNameFromKey(const std::string&);
static std::string getKeyFromName(const std::string&, const std::string&);
static void printEntry(const std::pair<std::string, std::size_t>&);
static std::string pairToString(const std::pair<std::string, std::size_t>&);
static std::string append(const std::string&, const std::pair<std::string, std::size_t>&);
};
}
// ===============================================================================
// End-of-File
// ===============================================================================