-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlibrary.cpp
More file actions
75 lines (67 loc) · 2.16 KB
/
Copy pathlibrary.cpp
File metadata and controls
75 lines (67 loc) · 2.16 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
/**
* @file bookDatabase.h
* @author Alex Lambert
*
* Description:
* - Library class contains books and patrons, the patrons can do things
* such as checking out or returning the books.
* - There are a few commands that happen to do this checking in and out
* of books, and also displaying information about the library.
*
* Assumptions/Implmentation:
* - The library should be created by LibraryBuilder so it is properly done.
* - Processes commands by using an ifstream, which should be properly
* formatted.
* - Can process multiple sets of commands if desired
*/
#include "library.h"
//---------------------------------------------------------------------------
/** Library()
* Default Constructor
*
* Constructs a Library object containing bookDB and patronDB.
* @param bookDB is a complete valid bookDatabase
* @param patronDB is a complete valid patronDatabase
* @pre None.
* @post Library object exists and is initialized
*/
Library::Library(BookDatabase* bookDB, PatronDatabase* patronDB)
{
this->bookDB = bookDB;
this->patronDB = patronDB;
}
//---------------------------------------------------------------------------
/** ~Library()
* Default Destructor
*
* Destroys the library and everything in it
* @pre None.
* @post All memory used by everything in the library is deallocated.
*/
Library::~Library()
{
delete bookDB;
bookDB = nullptr;
delete patronDB;
patronDB = nullptr;
}
//---------------------------------------------------------------------------
/** processComands()
* Process Commands
*
* Runs all the commands in the commandFile that are legal.
* @param commandFile is an input file of the commands to execute.
* @pre commandFile is properly formatted.
* @post valid legal commands are executed in the library.
*/
void Library::processCommands(ifstream& commandFile)
{
CommandFactory* commandFactory = new CommandFactory(bookDB, patronDB);
CommandQueue* commandQueue = commandFactory->createCommands(commandFile);
delete commandFactory;
commandFactory = nullptr;
while (!commandQueue->isEmpty())
commandQueue->executeNext();
delete commandQueue;
commandQueue = nullptr;
}