Calculator
Extensible stack-based calculator primarily in library form
VariableManipulator.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 VARIABLE_MANIPULATOR_H
15 #define VARIABLE_MANIPULATOR_H
16 
17 #ifndef STACK_OPERATOR_H
18 #include "StackOperator.h"
19 #endif // STACK_OPERATOR_H
20 
21 namespace Calculator {
22 
23  /** Variable Modifier for Variable Operations
24  *
25  * Support multiple operations distinguished by the Operation parameter.
26  *
27  * Operations support separate variable-element manipulations
28  */
30  public:
31  typedef std::shared_ptr<VariableManipulator> Ptr;
32 
33  /** \enum Operation Operations supported */
34  enum class Operation {
35  /** Write the value in next-to-top to variable in top*/
36  WRITE,
37 
38  /** Replace the top variable with its value */
39  READ
40  };
41 
42  /** Create to perform operation.
43  *
44  * @param op to perform
45  *
46  * @return VariableManipulator created
47  */
49 
51 
52  protected:
53  /** Create to perform operation.
54  *
55  * @param op to perform
56  */
58 
63 
64  virtual Result operator()(Stack& stack, StackOperator::Ptr ofThis);
65 
66  private:
67  const Operation op;
68  };
69 
70  /** Create VariableManipulator from a string */
72  public:
74 
75  virtual std::string getHelp() const;
76  virtual StackOperator::Ptr create(const std::string& str);
77  };
78 } // namespace Calculator
79 
80 #endif // VARIABLE_MANIPULATOR_H
Collection of Result information for an operation.
Definition: Result.h:30
Stack of values to process from.
Definition: Stack.h:208
Factory creators of StackOperator::Ptrs.
Definition: StackOperator.h:57
Base class for all operators.
Definition: StackOperator.h:29
std::shared_ptr< StackOperator > Ptr
Definition: StackOperator.h:31
Create VariableManipulator from a string.
virtual StackOperator::Ptr create(const std::string &str)
Variable Modifier for Variable Operations.
VariableManipulator & operator=(VariableManipulator &&)=delete
virtual Result operator()(Stack &stack, StackOperator::Ptr ofThis)
Execute this operator on stack.
VariableManipulator(const VariableManipulator &)=delete
VariableManipulator(Operation op)
Create to perform operation.
@ READ
Replace the top variable with its value.
@ WRITE
Write the value in next-to-top to variable in top.
static VariableManipulator::Ptr create(Operation op)
Create to perform operation.
VariableManipulator(VariableManipulator &&)=delete
std::shared_ptr< VariableManipulator > Ptr
VariableManipulator & operator=(const VariableManipulator &)=delete
Container of Calculator resources.