Website Summary Files Commits Branches @commit @diff @stats
path: root / Week07 / Exercise01 / OnlineLibrary.h
blob: 4121af02c4c9c5e540f653775a1c4854f5cd5804 (plain) (blame)
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
#ifndef _ONLINE_LIBRARY
#define _ONLINE_LIBRARY

#include "Book.h"
#include "LibraryBanking.h"
#include "Transaction.h"
#include "User.h"
#include "Librarian.h"

class OnlineLibrary {
	Book* books;
	unsigned booksCount;
	unsigned booksAlloc;

	User* users;
	unsigned usersCount;
	unsigned usersAlloc;

	Librarian* librarians;
	unsigned librariansCount;
	unsigned librariansAlloc;

	// В методи на OnlineLibrary, тази структура се казва "TransactionConnection"
	// Извън методи на OnlineLibrary, тази структура се казва "OnlineLibrary::TransactionConnection"
	struct TransactionConnection {
		const User* user;
		const Book* book;
		const Transaction* transaction;
	};
	TransactionConnection* connections;
	unsigned connectionsCount;
	unsigned connectionsAlloc;

	void free();
	void copyFrom(const OnlineLibrary& other);

	void resizeBooks();
	void resizeUsers();
	void resizeLibrarians();
	void resizeConnections();

public:
	OnlineLibrary();
	~OnlineLibrary();
	OnlineLibrary(const OnlineLibrary& other);
	OnlineLibrary& operator=(const OnlineLibrary& other);
	OnlineLibrary(OnlineLibrary&& other);
	OnlineLibrary& operator=(OnlineLibrary&& other);

	void RegisterUser(const User& user);
	User* LoginUser(const String& email, const String& password);

	void RegisterLibrarian(const Librarian& librarian);
	Librarian* LoginLibrarian(unsigned librarianNumber, const String& password);

	void ListBooks() const;
	Book* GetBook(unsigned index);
	void AddBook(const Book& book);
	void PurchaseBook(const Book& book, const User& user, LibraryBanking& banking);

	void ListTransactions(const User& user) const;
	void ExportTransactions(const User& user, const String& fileName) const;
};

#endif /* _ONLINE_LIBRARY */