Calculator
Extensible stack-based calculator primarily in library form
Variable.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_H
15 #define VARIABLE_H
16 
17 #ifndef STACK_ITEM_H
18 #include "StackItem.h"
19 #endif // STACK_ITEM_H
20 
21 namespace Calculator {
22 
23  class Stack;
24 
25  /** StackItem representing a variable.
26  *
27  * These are not re-used and the current value is not modified after creation.
28  */
29  class Variable : public StackItem {
30  public:
31  typedef std::shared_ptr<Variable> Ptr;
32 
33  static const std::string indef_type_string() {
34  return "a Variable";
35  }
36 
37  /** Create with theName to represent.
38  *
39  * @param theName to be stored in this
40  *
41  * @return the Variable created
42  */
43  static Variable::Ptr create(const std::string& theName);
44 
45  virtual ~Variable();
46 
47  protected:
48  /** Create with theName to represent.
49  *
50  * @param theName to be stored in this
51  */
52  Variable(const std::string& theName);
53 
54  Variable() = delete;
55  Variable(const Variable&) = delete;
56  Variable(Variable&&) = delete;
57  Variable& operator=(const Variable&) = delete;
58  Variable& operator=(Variable&&) = delete;
59 
60  public:
61  /** @return the name of this Variable */
62  const std::string& getName() const;
63 
64  virtual std::string toString() const;
65 
66  private:
67  /** The name this represents */
68  const std::string name;
69  };
70 
71  /** Creates Variables from strings that convert to variables */
73  public:
74  virtual ~VariableCreator();
75 
76  virtual std::string getHelp() const;
77  virtual StackOperator::Ptr create(const std::string& str);
78  };
79 
80 } // namespace Calculator
81 
82 #endif // VARIABLE_H
Base class of all items that can be on the stack.
Definition: StackItem.h:28
Factory creators of StackOperator::Ptrs.
Definition: StackOperator.h:57
std::shared_ptr< StackOperator > Ptr
Definition: StackOperator.h:31
Creates Variables from strings that convert to variables.
Definition: Variable.h:72
virtual StackOperator::Ptr create(const std::string &str)
Definition: Variable.cpp:50
virtual std::string getHelp() const
Definition: Variable.cpp:46
StackItem representing a variable.
Definition: Variable.h:29
static Variable::Ptr create(const std::string &theName)
Create with theName to represent.
Definition: Variable.cpp:24
Variable(const Variable &)=delete
virtual ~Variable()
Definition: Variable.cpp:28
Variable & operator=(Variable &&)=delete
virtual std::string toString() const
Definition: Variable.cpp:40
const std::string & getName() const
Definition: Variable.cpp:36
Variable & operator=(const Variable &)=delete
std::shared_ptr< Variable > Ptr
Definition: Variable.h:31
static const std::string indef_type_string()
Definition: Variable.h:33
Variable(Variable &&)=delete
Container of Calculator resources.