44 lines
1.0 KiB
C++
44 lines
1.0 KiB
C++
#ifndef CALCULATOR_CHALLENGE_CALCULATOR_HPP
|
|
#define CALCULATOR_CHALLENGE_CALCULATOR_HPP
|
|
|
|
#include <optional>
|
|
#include <string>
|
|
#include <utility>
|
|
#include <vector>
|
|
|
|
#include "Operand.hpp"
|
|
|
|
struct Operation
|
|
{
|
|
std::string variable;
|
|
|
|
Operand lhs;
|
|
Operand rhs;
|
|
|
|
Operator binary_op;
|
|
};
|
|
|
|
class Calculator
|
|
{
|
|
public:
|
|
Calculator() noexcept = default;
|
|
Calculator(const Calculator&) noexcept = default;
|
|
Calculator(Calculator&&) noexcept = default;
|
|
auto operator=(const Calculator&) noexcept -> Calculator& = default;
|
|
auto operator=(Calculator&&) noexcept -> Calculator& = default;
|
|
~Calculator() noexcept = default;
|
|
|
|
void addOperation(Operation operation) noexcept;
|
|
void addOperation(std::string result, Operand lhs, Operand rhs, Operator binary_operator) noexcept;
|
|
|
|
void undoOperation(std::size_t count) noexcept;
|
|
|
|
auto computeLast() noexcept -> std::pair<std::string, std::optional<double>>;
|
|
auto computeLastValue() noexcept -> double;
|
|
|
|
private:
|
|
std::vector<Operation> _operations;
|
|
};
|
|
|
|
#endif
|