38 typedef std::function<float (
float,
float)> Function;
44 : op(theOp), symbol(theSymbol), function(theFunction)
52 std::string getSymbol()
const {
56 Function getFunction()
const {
68 typedef std::map<std::string, OpInfo> OpInfoBySymbol;
69 typedef std::map<BinaryMathOperator::Operation, OpInfo> OpInfoByOp;
73 const OpInfo data[] = {
81 for(OpInfo info : data) {
82 bySymbol[info.getSymbol()] = info;
83 byOp[info.getOp()] = info;
87 const OpInfo* operator[](std::string symbol)
const {
88 OpInfoBySymbol::const_iterator found = bySymbol.find(symbol);
89 if(bySymbol.end() == found) {
92 return &found->second;
96 OpInfoByOp::const_iterator found = byOp.find(op);
97 if(byOp.end() == found) {
100 return &found->second;
104 OpInfoBySymbol bySymbol;
108 static const OpInfoMap opInfoMap;
129 iter >> first >> second;
137 const OpInfo* info = opInfoMap[op];
138 if(
nullptr == info) {
140 return Result({
"Internal Error: Missing BinaryMathOperator."});
145 (*item)(stack, item);
154 return "One op of: +-*/^ -- Replace the top and second items with top op second.\n\t^ is exponent.";
158 const OpInfo* info = opInfoMap[str];
159 if(
nullptr != info) {
virtual std::string getHelp() const
virtual StackOperator::Ptr create(const std::string &str)
virtual ~BinaryMathCreator()
Operation
Operations supported.
@ MULTIPLY
Multiply the two values.
@ DIVIDE
Divide the two values.
@ SUBTRACT
Subtract the two values.
@ EXPONENT
Raise top to the exponent second.
BinaryMathOperator(Operation op)
Create to perform operation.
std::shared_ptr< BinaryMathOperator > Ptr
static BinaryMathOperator::Ptr create(Operation op)
Create to perform operation.
virtual Result operator()(Stack &stack, StackOperator::Ptr ofThis)
Execute this operator on stack.
std::shared_ptr< Number > Ptr
static Number::Ptr create(float theValue)
Create with theValue to represent.
Collection of Result information for an operation.
Stack of values to process from.
void popAfter(StackIterator &iter)
Pop all items after iter on the Stack.
Iterator over a Stack from top to bottom.
const Result & getResult() const
std::shared_ptr< StackOperator > Ptr
const std::string Ok
Operation was successful.
Container of Calculator resources.