-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtransactionFactory.cpp
More file actions
34 lines (32 loc) · 1.23 KB
/
transactionFactory.cpp
File metadata and controls
34 lines (32 loc) · 1.23 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
#include "transactionFactory.h"
//----------------------------------------------------------------------------
//constructor
//sets the C R H and D to their respective transaction types
TransactionFactory::TransactionFactory() {
for (int i = 0; i < hashTableSize; i++) { //set all to null pointer
transFactory[i] = nullptr;
}
transFactory[hash('C')] = new Checkout;
transFactory[hash('R')] = new Return;
transFactory[hash('H')] = new DPH;
transFactory[hash('D')] = new DPC;
}
//----------------------------------------------------------------------------
//destructor
TransactionFactory::~TransactionFactory() {
for (int i = 0; i < hashTableSize; i++) {
if (transFactory[i] != nullptr) {
delete transFactory[i];
transFactory[i] = nullptr;
}
}
}
//----------------------------------------------------------------------------
//createIt
//returns nullptr if not the correct type otherwise creates new object
//of that transaction type
Transaction* TransactionFactory::createIt(char ch) const {
int subscript = hash(ch);
if (transFactory[subscript] == nullptr) return nullptr; //incorrect type
return transFactory[subscript]->create();
}