Pakman
TaskHandler.cc
1 #include "TaskHandler.h"
2 
3 // Construct from input string
4 TaskHandler::TaskHandler(const std::string& input_string) :
5  m_input_string(input_string)
6 {
7 }
8 
9 // Move constructor
11  m_input_string(std::move(t.m_input_string)),
12  m_output_string(std::move(t.m_output_string)),
13  m_error_code(t.m_error_code),
14  m_state(t.m_state)
15 {
16 }
17 
18 // Get state
20 {
21  return m_state;
22 }
23 
24 // Probe whether task is pending
26 {
27  return m_state == pending;
28 }
29 
30 // Probe whether task is finished
32 {
33  return m_state == finished;
34 }
35 
36 // Probe whether error occured
38 {
39  // This should only be called in the finished state
40  assert(m_state == finished);
41 
42  return m_error_code != 0;
43 }
44 
45 // Get input string
46 std::string TaskHandler::getInputString() const
47 {
48  // Return input string
49  return m_input_string;
50 }
51 
52 // Get output string
53 std::string TaskHandler::getOutputString() const
54 {
55  // Return output string
56  return m_output_string;
57 }
58 
59 // Get error code
61 {
62  // Return error code
63  return m_error_code;
64 }
65 
66 // Record output
67 void TaskHandler::recordOutputAndErrorCode(const std::string& output_string,
68  int error_code)
69 {
70  // This should only be called in the pending state
71  assert(m_state == pending);
72 
73  // Record output string, error code and set state to finished
74  m_output_string.assign(output_string);
75  m_error_code = error_code;
76  m_state = finished;
77 }
std::string getOutputString() const
Definition: TaskHandler.cc:53
bool isFinished() const
Definition: TaskHandler.cc:31
bool isPending() const
Definition: TaskHandler.cc:25
std::string getInputString() const
Definition: TaskHandler.cc:46
void recordOutputAndErrorCode(const std::string &output_string, int error_code)
Definition: TaskHandler.cc:67
bool didErrorOccur() const
Definition: TaskHandler.cc:37
int getErrorCode() const
Definition: TaskHandler.cc:60
state_t getState() const
Definition: TaskHandler.cc:19
TaskHandler(const std::string &input_string)
Definition: TaskHandler.cc:4