-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPipedCommand.h
executable file
·137 lines (93 loc) · 4.04 KB
/
PipedCommand.h
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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
/* file: PipedCommand.cpp
Piped Command Class Header File
==================================================
Wimpy Shell Project - Com Sci 342
Shea Daniels
This class is based around the data and functions
needed for storing and parsing piped commands.
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
! Information on constructors: !
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
PipedCommand()
--------------------------------------------------
This is the basic constructor for the class.
POST: The object has been initialized.
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
! Information on public methods: !
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
void setCommandText(string new_cmd_text)
--------------------------------------------------
Sets the text of the entire command to whatever
string the user specifies.
PRE: new_cmd_text is a string containing the text
of the command line.
POST: new_cmd_text is now the value of this object's
command text.
string getCommandText() const
--------------------------------------------------
Returns the command text of this object.
POST: A string containing the text of the command
line is returned.
string getErrorReason() const
--------------------------------------------------
Returns the reason the command couldn't be parsed.
POST: If command couldn't be parsed, returns a string
containing the reason. If command was parsed
successfully or has not been parsed at all,
returns "none".
vector<Command> getCommands() const
--------------------------------------------------
Returns the vector of sub commands that are
all part of this larger object.
POST: Returns a vector of Command objects.
bool checkForPiping()
--------------------------------------------------
Checks to see if the command is a piped command
or if this object isn't needed. (looks for '|' chars)
PRE: The command text of this object has been set.
POST: Returns true if the command is piped.
Returns false if it is not.
bool parsePipedCommand()
--------------------------------------------------
Tries to parse the piped command into separate
sub commands and then parse those commands.
PRE: The command text of this object has been set
and is known to be a command that is piped.
POST: A boolean is returned based on whether the
command was parsed correctly or not. If false
is returned, the reason is stored by this
object. If the command was parsed correctly
and true is returned, all of the data
will be set correctly and available using
the public "get" commands.
*/
#ifndef PIPECMD_HEADER
#define PIPECMD_HEADER
#include <string>
#include <vector>
#include <iostream>
#include "Command.h"
using namespace std;
class PipedCommand {
public:
// constructor
PipedCommand();
// set functions
void setCommandText(string new_cmd_text);
// get functions
string getCommandText() const;
string getErrorReason() const;
vector<Command> getCommands() const;
// other functions
bool checkForPiping();
bool parsePipedCommand();
private:
//------------------------------------------------------------
// Data
//------------------------------------------------------------
string command_text;
string error_reason;
// list of commands to be piped
vector<Command> cmds;
};
#endif