-
Notifications
You must be signed in to change notification settings - Fork 0
/
Library_MemoryService.hpp
56 lines (42 loc) · 1.51 KB
/
Library_MemoryService.hpp
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
53
54
55
56
#ifndef _LIBRARY_MEMORY_MANAGER_
#define _LIBRARY_MEMORY_MANAGER_
#include "Book.hpp"
#include "Command.hpp"
#include "LibraryService.hpp"
#include <iostream>
#include <sstream>
#include <string>
#include <unordered_map>
#include <vector>
using namespace std;
class LibraryMemoryService : public LibraryService {
/* IMPORTANT NOTE : The caller of these functions are responbilites for
freeing the Book pointers that are returned :
.create_book()
.find_book()
.find_all_books() <----- iterate over it
.update_book()
.patch_book()
*/
int last_id = 0;
std::unordered_map<int, Book *> m_books;
public:
bool validate(const Book &book);
const Book *create_book(const Book &book);
std::stringstream execute_command(Command &command);
const Book *find_book(unsigned const int &id);
bool dupchk(const Book &book);
bool dupchk_upd(const Book &book, int id);
const std::unordered_map<int, Book *>
find_all_books(const std::string &name = "", const std::string &author = "",
unsigned const int &pages = 0);
const Book *update_book(unsigned const int &id, const Book &book);
const Book *patch_book(unsigned const int &id, const Book &book);
bool delete_book(unsigned const int &id);
void delete_condition(const std::string &name = "",
const std::string &author = "",
unsigned const int &pages = 0);
void delete_all_books();
void import(std::unordered_map<int, Book *> library, int id);
};
#endif // _LIBRARY_MEMORY_MANAGER_