@brief value class */
| 49 | |
| 50 | /** @brief value class */ |
| 51 | class value { |
| 52 | private: |
| 53 | bigint mIntValue{}; |
| 54 | double mDoubleValue{}; |
| 55 | enum class Type : std::uint8_t { INT, LONG, LONGLONG, FLOAT } mType; |
| 56 | bool mIsUnsigned{}; |
| 57 | |
| 58 | void promote(const value &v); |
| 59 | |
| 60 | public: |
| 61 | /** |
| 62 | * @throws InternalError thrown on invalid value |
| 63 | */ |
| 64 | explicit value(const std::string &s); |
| 65 | std::string str() const; |
| 66 | bool isInt() const { |
| 67 | return mType != Type::FLOAT; |
| 68 | } |
| 69 | bool isFloat() const { |
| 70 | return mType == Type::FLOAT; |
| 71 | } |
| 72 | |
| 73 | double getDoubleValue() const { |
| 74 | return isFloat() ? mDoubleValue : static_cast<double>(mIntValue); |
| 75 | } |
| 76 | |
| 77 | /** |
| 78 | * @throws InternalError thrown on invalid/unhandled calculation or division by zero |
| 79 | */ |
| 80 | static value calc(char op, const value &v1, const value &v2); |
| 81 | int compare(const value &v) const; |
| 82 | value add(int v) const; |
| 83 | /** |
| 84 | * @throws InternalError thrown if operand is not an integer |
| 85 | */ |
| 86 | value shiftLeft(const value &v) const; |
| 87 | /** |
| 88 | * @throws InternalError thrown if operand is not an integer |
| 89 | */ |
| 90 | value shiftRight(const value &v) const; |
| 91 | }; |
| 92 | |
| 93 | static const int bigint_bits; |
| 94 |
no outgoing calls
no test coverage detected