Calculator
Extensible stack-based calculator primarily in library form
StackItem.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 STACK_ITEM_H
15 #define STACK_ITEM_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 
25  /** \class StackItem
26  * \brief Base class of all items that can be on the stack.
27  */
28  class StackItem : public StackOperator {
29  public:
30  typedef std::shared_ptr<StackItem> Ptr;
31 
32  virtual ~StackItem();
33 
34  protected:
35  StackItem() = default;
36 
37  StackItem(const StackItem&) = delete;
38  StackItem(StackItem&&) = delete;
39  StackItem& operator=(const StackItem&) = delete;
41 
42  public:
43  /** Execute this item modifying stack.
44  *
45  * @param stack to process on
46  * @param ofThis the StackOperator::Ptr for this object so that its info
47  * can be passed around.
48  *
49  * @return Result from execution
50  */
51  virtual Result operator()(Stack& stack, StackOperator::Ptr ofThis);
52 
53  /** @return string representation of this */
54  virtual std::string toString() const = 0;
55  };
56 
57 } // namespace Calculator
58 
59 # endif // STACK_ITEM_H
Collection of Result information for an operation.
Definition: Result.h:30
Stack of values to process from.
Definition: Stack.h:208
Base class of all items that can be on the stack.
Definition: StackItem.h:28
virtual std::string toString() const =0
StackItem(StackItem &&)=delete
std::shared_ptr< StackItem > Ptr
Definition: StackItem.h:30
StackItem & operator=(StackItem &&)=delete
StackItem(const StackItem &)=delete
virtual Result operator()(Stack &stack, StackOperator::Ptr ofThis)
Execute this item modifying stack.
Definition: StackItem.cpp:27
StackItem & operator=(const StackItem &)=delete
Base class for all operators.
Definition: StackOperator.h:29
std::shared_ptr< StackOperator > Ptr
Definition: StackOperator.h:31
Container of Calculator resources.