28 Executive::Executive(
Stack& theStack)
29 : stack(theStack), operationCount(0)
44 output <<
"User requested quit..." << endl;
48 output << result.
toString(std::string(
">> ") + std::to_string(operationCount));
54 return std::string(
"Stack: ") + stack.
toString();
58 if(0 == input.compare(
"quit")) {
62 if(0 == input.compare(
"help")) {
63 std::ostringstream os;
71 return Result({std::string(
"Ignoring invalid input: \"") + input +
"\""});
79 return Result({
"Internal Error: Invalid Operator"});
82 Result results = (*oper)(stack, oper);
90 return operationCount;
94 output <<
"Stack-based calculator." << endl;
95 output <<
"Commands:" << endl;
96 output <<
"\tquit -- exit the program" << endl;
97 output <<
"\thelp -- help for the program" << endl;
104 : executive(theStack), factory(theFactory)
109 executive.
doHelp(factory, output);
113 executive.
process(factory, input, output);
117 return executive.
process(factory, input);
std::string toString() const
unsigned int getOperationCount() const
void doHelp(const StackOperatorFactory &factory, std::ostream &output) const
Generate help info for this executive to output.
void process(StackOperatorFactory &factory, std::istream &input, std::ostream &output)
Process commands from input and pushing generated info to output.
FixedOperatorExecutive(StackOperatorFactory &theFactory, Stack &theStack)
void process(std::istream &input, std::ostream &output)
Process commands from input and pushing generated info to output.
void doHelp(std::ostream &output) const
Collection of Result information for an operation.
std::string toString() const
bool hasMessage(const std::string &message) const
Convenience to test with message has been set.
Stack of values to process from.
std::string toString() const
Create string representation of the current contents of the Stack.
Factory to create StackOperators and help from StackOperatorCreators.
std::shared_ptr< StackOperator > create(const std::string &str) const
Try to create a StackOperator for the given str.
std::string getHelp() const
std::shared_ptr< StackOperator > Ptr
const std::string Ok
Operation was successful.
Container of Calculator resources.