/* * Author: Patrick-Christopher Mattulat * Company: Lynar Studios * E-Mail: webmaster@lynarstudios.com * Created: 2020-08-09 * Changed: 2025-12-24 * * */ module; #include #include #include #include #include export module ls.std.boxing.boolean; using ls::std::core::Class; using ls::std::core::IllegalArgumentException; using ls::std::core::interface_type::IBoxing; using std::string; using std::transform; export namespace ls::std::boxing { class Boolean : public Class, public IBoxing { public: explicit Boolean(const bool _value) : Class(_fetchClassName()), value(_value) {} Boolean() : Class(_fetchClassName()) {} ~Boolean() noexcept override = default; Boolean &operator=(const int _value) { this->value = _value; return *this; } Boolean &operator=(const bool _value) { this->value = _value; return *this; } bool operator&&(const Boolean &_boolean) const { return this->value && _boolean.getValue(); } bool operator&&(const bool _value) const { return this->value && _value; } bool operator&&(const int _value) const { return this->value && _value; } bool operator||(const Boolean &_boolean) const { return this->value || _boolean.getValue(); } bool operator||(const bool _value) const { return this->value || _value; } bool operator||(const int _value) const { return this->value || _value; } void parse(const string &_parseText) override { string parseText = _parseText; transform(parseText.begin(), parseText.end(), parseText.begin(), ::tolower); if (parseText != this->TRUE_STRING && parseText != this->FALSE_STRING) { throw IllegalArgumentException{parseText + " is not a valid string representation"}; } else { if (parseText == this->TRUE_STRING) { this->value = true; } if (parseText == this->FALSE_STRING) { this->value = false; } } } [[nodiscard]] string toString() override { return this->_toString(); } [[nodiscard]] bool getValue() const { return this->value; } [[nodiscard]] static bool XOR(const Boolean &_leftExpression, const Boolean &_rightExpression) { return (_leftExpression.getValue() && !_rightExpression.getValue()) || (!_leftExpression.getValue() && _rightExpression.getValue()); } [[nodiscard]] static bool XOR(const Boolean &_leftExpression, const bool _rightExpression) { return (_leftExpression.getValue() && !_rightExpression) || (!_leftExpression.getValue() && _rightExpression); } [[nodiscard]] static bool XOR(const bool _leftExpression, const Boolean &_rightExpression) { return (_leftExpression && !_rightExpression.getValue()) || (!_leftExpression && _rightExpression.getValue()); } [[nodiscard]] static bool XOR(const bool _leftExpression, const bool _rightExpression) { return (_leftExpression && !_rightExpression) || (!_leftExpression && _rightExpression); } private: bool value{}; const string FALSE_STRING = "false"; const string TRUE_STRING = "true"; [[nodiscard]] static string _fetchClassName() { static const string className = "Boolean"; return className; } [[nodiscard]] string _toString() const { string booleanString{}; if (this->value) { booleanString = this->TRUE_STRING; } else { booleanString = this->FALSE_STRING; } return booleanString; } }; }