Repository navigation
Expand file tree
/
Copy pathcli.h
More file actions
52 lines (43 loc) · 1.78 KB
/
Copy pathcli.h
File metadata and controls
52 lines (43 loc) · 1.78 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
47
48
49
50
51
52
#pragma once
#include "Phonebook.h"
#include <iostream>
#include <limits>
#include <string>
#include <vector>
namespace cli {
void displayMenu();
void printContact(const Contact& contact);
void printAllContacts(const Phonebook& phonebook);
std::vector<Contact> searchContacts(const Phonebook& phonebook);
std::string getNameInput(const std::string& prompt, bool isMandatory);
std::string getAddressInput(const std::string& prompt);
Date getBirthDateInput(const std::string& prompt);
std::string getEmailInput(const std::string& forename, const Phonebook& phonebook,
int ignoreId = 0);
std::string getPhoneTypeInput();
std::string getPhoneNumberInput(const Phonebook& phonebook, const Contact* currentContact, int editIdx = -1);
void addContact(Phonebook& phonebook);
void editContact(Phonebook& phonebook);
void deleteContact(Phonebook& phonebook);
void sortContacts(Phonebook& phonebook);
template<typename T> T getInput(const std::string& prompt) {
T value;
while (true) {
std::cout << prompt;
std::cin >> value;
if (std::cin.fail()) {
std::cout << "Invalid input." << std::endl;
std::cin.clear();
std::cin.ignore(std::numeric_limits<std::streamsize>::max(), '\n');
continue;
}
if (std::cin.peek() != '\n') {
std::cout << "Entered more than one value." << std::endl;
std::cin.ignore(std::numeric_limits<std::streamsize>::max(), '\n');
continue;
}
std::cin.ignore(std::numeric_limits<std::streamsize>::max(), '\n');
return value;
}
}
}