Advertisement
Guest User

Untitled

a guest
Mar 28th, 2020
128
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.52 KB | None | 0 0
  1. enum class eOperandType
  2. {
  3.     Int8,
  4.     Int16,
  5.     Int32,
  6.     Float,
  7.     Double,
  8.     None,
  9. };
  10.  
  11. class IOperand
  12. {
  13. public:
  14.     [[nodiscard]] virtual int getPrecision() const = 0;
  15.     // Precision of the type of the instance
  16.     [[nodiscard]] virtual eOperandType  getType() const = 0;
  17.     // Type of the instance
  18.     virtual IOperand const* operator+(const IOperand& rhs) const = 0;
  19.     // Sum
  20.     virtual IOperand const* operator-(const IOperand& rhs) const = 0;
  21.     // Difference
  22.     virtual IOperand const* operator*(const IOperand& rhs) const = 0;
  23.     // Product
  24.     virtual IOperand const* operator/(const IOperand& rhs) const = 0;
  25.     // Quotient
  26.     virtual IOperand const* operator%(const IOperand& rhs) const = 0;
  27.     // Modulo
  28.     [[nodiscard]] virtual std::string const & toString() const = 0;
  29.     // String representation of the instance
  30.     virtual ~IOperand() = default;
  31. };
  32.  
  33. /////////////////////////////////////////
  34.  
  35. class OInt8 : public IOperand
  36. {
  37. public:
  38.     explicit OInt8(int8_t val);
  39.     explicit OInt8(const std::string &raw);
  40.     [[nodiscard]] int getPrecision() const override ;
  41.     [[nodiscard]] eOperandType  getType() const override;
  42.     IOperand const* operator+(const IOperand& rhs) const override;
  43.     IOperand const* operator-(const IOperand& rhs) const override;
  44.     IOperand const* operator*(const IOperand& rhs) const override;
  45.     IOperand const* operator/(const IOperand& rhs) const override;
  46.     IOperand const* operator%(const IOperand& rhs) const override;
  47.     [[nodiscard]] std::string const & toString() const override;
  48.  
  49. private:
  50.     int8_t value_;
  51.     std::string raw_;
  52. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement