Repository navigation
Expand file tree
/
Copy pathmain.cpp
More file actions
95 lines (74 loc) · 2.27 KB
/
Copy pathmain.cpp
File metadata and controls
95 lines (74 loc) · 2.27 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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
#include <iostream>
#include <vector>
#include <algorithm>
#include "Str.h"
#include "Book.h"
#include "User.h"
#include "Loan.h"
#include "DatabaseManager.h"
#include "Functionalities.h"
#include <fstream>
#include <string>
using namespace std;
using namespace OurBook;
vector<Book*> library_books; // Assuming you have a vector to store Book objects
vector<User*> library_users;
vector<Loan*> library_loans;
vector<Book*> Search_results; // Defined for every search the user needs and will be cleared after each search
vector<Book*> Cart;
// Setting database file name
std::string dbName = "test.db";
DatabaseManager dbManager(dbName);
// Check if file with this name exists
bool checkFileExist(const std::string& name) {
std::ifstream file(name.c_str());
return file.good();
}
void importFromDB(){
if (checkFileExist(dbName)) {
dbManager.createTables(); /* creates 3 tables in database */
dbManager.insertSampleData();
}
/* importing books from database to library_books and copies it to ex_library_books to use it in DatabaseManager */
dbManager.importBooks(library_books);
ex_library_books = library_books;
/* importing Users and Loans data from database to library vectors */
dbManager.importUsers(library_users);
ex_library_users = library_users;
dbManager.importLoans(library_loans);
ex_library_loans=library_loans;
}
void exportToDB(){
dbManager.boomboom(); /* clearing database */
/* exporting library vectors to database */
for(auto &it : library_books){
dbManager.insertBook(it);
}
for(auto &it : library_users){
dbManager.insertUser(it);
}
for(auto &it : library_loans){
dbManager.insertLoan(it);
}
}
void free_vectors(){
for(auto &it : library_books)
delete it;
for(auto &it : library_users)
delete it;
for(auto &it : library_loans)
delete it;
}
int main() {
importFromDB();
checkforoverdues();// this function will be called whenever the program runs and will check if there is an overdue on any loan
User* user = login();
if(Librarian *librarianPtr = dynamic_cast <Librarian*>(user))
libMenu();
else
memberMenu();
exportToDB();
free_vectors();
return 0;
}
Book* getBookPtr(str ISBN);