Calculator
Extensible stack-based calculator primarily in library form
Executive.h
Go to the documentation of this file.
1 /*
2 Copyright (c) 2013, Komodo Does Inc
3 All rights reserved.
4 
5 Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
6 
7 - Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
8 - Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
9 - Neither the name of the Komodo Does Inc nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
10 
11 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
12 */
13 
14 #ifndef CALCULATOR_H
15 #define CALCULATOR_H
16 
17 #ifndef STACK_OPERATOR_H
18 #include "StackOperator.h"
19 #endif // STACK_OPERATOR_H
20 
21 namespace Calculator {
22 
23  class Stack;
24  class StackOperatorFactory;
25 
26  /** \class Executive
27  * \brief Drivable class to run the calculator with a variable factory per
28  * process call to support changing command sets.
29  */
30  class Executive {
31  public:
32  /** Create with the stack to process
33  *
34  * @param stack to process
35  */
36  Executive(Stack& stack);
37 
38  Executive(const Executive&) = delete;
39  Executive(Executive&&) = delete;
40  Executive& operator=(const Executive&) = delete;
42 
43  /** @return string representation of the current state */
44  std::string toString() const;
45 
46  /** Process commands from input and pushing generated info to output
47  *
48  * @param factory to parse input and generate Operators from
49  * @param input to read commands from
50  * @param output to write status to
51  */
52  void process(StackOperatorFactory& factory, std::istream& input, std::ostream& output);
53 
54  /** Process commands from input and pushing generated info to output
55  *
56  * @param factory to parse input and generate Operators from
57  * @param input to create one operator and execute from
58  *
59  * @return Result of processing
60  */
61  Result process(StackOperatorFactory& factory, const std::string& input);
62 
63  /** Process oper upon the Stack.
64  *
65  * @param oper to process on the Stack
66  *
67  * @return Result of processing
68  */
70 
71  /** @return the count of processed operations */
72  unsigned int getOperationCount() const;
73 
74  /** Generate help info for this executive to output.
75  *
76  * @param factory providing commands to get help from
77  * @param output to write help info to
78  */
79  void doHelp(const StackOperatorFactory& factory, std::ostream& output) const;
80 
81  private:
82  Stack& stack;
83  unsigned int operationCount;
84  };
85 
86  /** \class FixedOperatorExecutive
87  * \brief Drivable class to run the calculator with a single set of commands.
88  */
90  public:
91  FixedOperatorExecutive(StackOperatorFactory& theFactory, Stack& theStack);
92 
97 
98  void doHelp(std::ostream& output) const;
99 
100  /** Process commands from input and pushing generated info to output
101  *
102  * @param input to read commands from
103  * @param output to write status to
104  */
105  void process(std::istream& input, std::ostream& output);
106 
107  /** Process commands from input and pushing generated info to output
108  *
109  * @param input to create one operator and execute from
110  *
111  * @return Result of Processing
112  */
113  Result process(const std::string& input);
114 
115  private:
116  Executive executive;
117  StackOperatorFactory& factory;
118  };
119 
120 } // namespace Calculator
121 
122 #endif // CALCULATOR_H
Drivable class to run the calculator with a variable factory per process call to support changing com...
Definition: Executive.h:30
std::string toString() const
Definition: Executive.cpp:53
Executive(Executive &&)=delete
Executive & operator=(Executive &&)=delete
Executive & operator=(const Executive &)=delete
unsigned int getOperationCount() const
Definition: Executive.cpp:89
Executive(Stack &stack)
Create with the stack to process.
Definition: Executive.cpp:28
void doHelp(const StackOperatorFactory &factory, std::ostream &output) const
Generate help info for this executive to output.
Definition: Executive.cpp:93
Executive(const Executive &)=delete
void process(StackOperatorFactory &factory, std::istream &input, std::ostream &output)
Process commands from input and pushing generated info to output.
Definition: Executive.cpp:33
Drivable class to run the calculator with a single set of commands.
Definition: Executive.h:89
FixedOperatorExecutive & operator=(Executive &&)=delete
FixedOperatorExecutive(StackOperatorFactory &theFactory, Stack &theStack)
Definition: Executive.cpp:103
void process(std::istream &input, std::ostream &output)
Process commands from input and pushing generated info to output.
Definition: Executive.cpp:112
FixedOperatorExecutive(Executive &&)=delete
FixedOperatorExecutive(const Executive &)=delete
void doHelp(std::ostream &output) const
Definition: Executive.cpp:108
FixedOperatorExecutive & operator=(const Executive &)=delete
Collection of Result information for an operation.
Definition: Result.h:30
Stack of values to process from.
Definition: Stack.h:208
Factory to create StackOperators and help from StackOperatorCreators.
std::shared_ptr< StackOperator > Ptr
Definition: StackOperator.h:31
Container of Calculator resources.