-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtransaction.cpp
More file actions
54 lines (48 loc) · 1.26 KB
/
transaction.cpp
File metadata and controls
54 lines (48 loc) · 1.26 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
/*
* transaction.h
*
* @authors Juan Arias & Nick Tibbott
*
* Implementations for Transaction and TransactionFactory
*
*/
#include "store.h"
#include "transaction.h"
/*
* Static function to ensure map is initialized before
* TransactionFactories self register
*/
map<char, TransactionFactory*>& Transaction::getMap() {
static map<char, TransactionFactory*> factoryMap;
return factoryMap;
}
/*
* Protected constructor for subclasses to set store pointer
*/
Transaction::Transaction(Store* store, const string& fileName)
:Command(store, fileName) {
}
/*
* Static function for TransactionFactories to self register with
* char representing their type
*/
void Transaction::registerType(char type, TransactionFactory* factory) {
Transaction::getMap().emplace(type, factory);
}
/*
* Create and return the right Transaction from the type and line of info
*/
Transaction* Transaction::create(Store* store, const ItemType* itemType,
const string& fileName, char type, const string& line) {
Transaction* trans = nullptr;
if (Transaction::getMap().count(type)) {
TransactionFactory* factory = Transaction::getMap().at(type);
trans = factory->create(store, itemType, fileName, line);
}
return trans;
}
/*
* Virtual destructor
*/
Transaction::~Transaction() {
}