123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213 |
- /*
- * Author: Patrick-Christopher Mattulat
- * Company: Lynar Studios
- * E-Mail: webmaster@lynarstudios.com
- * Created: 2020-08-09
- * Changed: 2021-05-30
- *
- * */
- #include <algorithm>
- #include <ls_std/boxing/Boolean.hpp>
- #include <ls_std/exception/IllegalArgumentException.hpp>
- ls_std::Boolean::Boolean() : ls_std::Class("Boolean")
- {}
- ls_std::Boolean::Boolean(bool _value)
- : ls_std::Class("Boolean"),
- value(_value)
- {}
- ls_std::Boolean::operator bool() const
- {
- return this->value;
- }
- ls_std::Boolean &ls_std::Boolean::operator=(int _value)
- {
- this->value = _value;
- return *this;
- }
- ls_std::Boolean &ls_std::Boolean::operator=(bool _value)
- {
- this->value = _value;
- return *this;
- }
- bool ls_std::Boolean::operator&&(const ls_std::Boolean &_boolean) const
- {
- return this->value && _boolean;
- }
- bool ls_std::Boolean::operator&&(bool _value) const
- {
- return this->value && _value;
- }
- bool ls_std::Boolean::operator&&(int _value) const
- {
- return this->value && _value;
- }
- bool ls_std::Boolean::operator||(const ls_std::Boolean &_boolean) const
- {
- return this->value || _boolean;
- }
- bool ls_std::Boolean::operator||(bool _value) const
- {
- return this->value || _value;
- }
- bool ls_std::Boolean::operator||(int _value) const
- {
- return this->value || _value;
- }
- ls_std::byte_field ls_std::Boolean::load()
- {
- ls_std::byte_field data{};
- if (this->storable != nullptr && this->serializable != nullptr)
- {
- data = this->storable->load();
- this->serializable->unmarshal(data);
- }
- return data;
- }
- ls_std::byte_field ls_std::Boolean::marshal()
- {
- ls_std::byte_field data{};
- if (this->serializable != nullptr)
- {
- data = this->serializable->marshal();
- }
- return data;
- }
- void ls_std::Boolean::parse(std::string _parseText)
- {
- std::transform(_parseText.begin(), _parseText.end(), _parseText.begin(), ::tolower);
- if (_parseText != this->TRUE_STRING && _parseText != this->FALSE_STRING)
- {
- throw ls_std::IllegalArgumentException{};
- }
- else
- {
- if (_parseText == this->TRUE_STRING)
- {
- this->value = true;
- }
- if (_parseText == this->FALSE_STRING)
- {
- this->value = false;
- }
- }
- }
- void ls_std::Boolean::save(const ls_std::byte_field &_data)
- {
- if (this->serializable != nullptr)
- {
- if (_data.empty())
- {
- this->storable->save(this->serializable->marshal());
- }
- else
- {
- this->storable->save(_data);
- }
- }
- }
- std::string ls_std::Boolean::toString()
- {
- return this->_toString();
- }
- void ls_std::Boolean::unmarshal(const ls_std::byte_field &_data)
- {
- if (this->serializable != nullptr)
- {
- this->serializable->unmarshal(_data);
- }
- }
- bool ls_std::Boolean::getValue() const
- {
- return this->value;
- }
- void ls_std::Boolean::setSerializable(const std::shared_ptr<ls_std::ISerializable>& _serializable)
- {
- this->_assignSerializable(_serializable);
- }
- void ls_std::Boolean::setStorable(const std::shared_ptr<ls_std::IStorable>& _storable)
- {
- this->_assignStorable(_storable);
- }
- bool ls_std::Boolean::XOR(const ls_std::Boolean &_leftExpression, const ls_std::Boolean &_rightExpression)
- {
- return (_leftExpression && !_rightExpression) || (!_leftExpression && _rightExpression);
- }
- bool ls_std::Boolean::XOR(const ls_std::Boolean &_leftExpression, bool _rightExpression)
- {
- return (_leftExpression && !_rightExpression) || (!_leftExpression && _rightExpression);
- }
- bool ls_std::Boolean::XOR(bool _leftExpression, const ls_std::Boolean &_rightExpression)
- {
- return (_leftExpression && !_rightExpression) || (!_leftExpression && _rightExpression);
- }
- bool ls_std::Boolean::XOR(bool _leftExpression, bool _rightExpression)
- {
- return (_leftExpression && !_rightExpression) || (!_leftExpression && _rightExpression);
- }
- void ls_std::Boolean::_assignSerializable(const std::shared_ptr<ls_std::ISerializable> &_serializable)
- {
- if (_serializable == nullptr)
- {
- throw ls_std::IllegalArgumentException{};
- }
- this->serializable = _serializable;
- }
- void ls_std::Boolean::_assignStorable(const std::shared_ptr<ls_std::IStorable> &_storable)
- {
- if (_storable == nullptr)
- {
- throw ls_std::IllegalArgumentException{};
- }
- this->storable = _storable;
- }
- std::string ls_std::Boolean::_toString() const
- {
- std::string booleanString{};
- if (this->value)
- {
- booleanString = this->TRUE_STRING;
- }
- else
- {
- booleanString = this->FALSE_STRING;
- }
- return booleanString;
- }
|