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