-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCommand.h
More file actions
77 lines (60 loc) · 2.55 KB
/
Copy pathCommand.h
File metadata and controls
77 lines (60 loc) · 2.55 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
// Blake Berry
// 03/08/2022
// Homework 4 design
// This file is an interface for the Command class. The Command class is an
// abstract baseclass for commands that can be executed in a store. The
// command is hashable and allows those derived to define how they execute
// their command
//-----------------------------------------------------------------------------
#pragma once
#include "HashableObject.h"
#include <string>
#include "TransactionManager.h"
#include "CustomerManager.h"
#include "ItemsManager.h"
class Command : public HashableObject
{
protected:
//-------------------------getCustomer -------------------------------------
// Returns a string of the customers number from a given command to process
// preconditions : Assumes the customer number is the first data and that
// it is 3 digits long
//
// assumes format ", XXX" where XXX is cust #
// Postconditions: The customer number is returned in string for,
// if an invalid customer number if found an empty string
// is returned
std::string getCustomer(std::string& command) const {
// for getting customer number get rid of ", "
command.erase(0, 2);
std::string custNum = command.substr(0, 3);
bool allDigits = true;
int custNumSize = custNum.size();
for (int i = 0; i < custNumSize; i++) {
allDigits = std::isdigit(custNum[i]);
if (!allDigits) {
custNum = "";
}
}
// gets rid of "XXX, "
command.erase(0, 5);
return custNum;
}
public:
//-------------------------- Constructor -----------------------------------
// Initializes the key in the hashable object class for a given command
// postconditions : Assigns a key for a given command object
Command(std::string key = "") : HashableObject(key) {};
//-------------------------- destructor -----------------------------------
// Frees any dynamic memory associated with the command objects
// Postconditions: The command is freed of any dynamic memory
virtual ~Command() {};
//-------------------------- Execute -----------------------------------
// Creates a specific Command based off a string type that is stored
// in the command class's field
// Postconditions: The command object is created
virtual void execute(TransactionManager*& tManager,
ItemsManager*& iManager,
CustomerManager*& cManager,
std::string& command) const = 0;
};