Boolean.cpp 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. /*
  2. * Author: Patrick-Christopher Mattulat
  3. * Company: Lynar Studios
  4. * E-Mail: webmaster@lynarstudios.com
  5. * Created: 2020-08-09
  6. * Changed: 2023-02-22
  7. *
  8. * */
  9. #include <algorithm>
  10. #include <ls-std/boxing/Boolean.hpp>
  11. #include <ls-std/core/exception/IllegalArgumentException.hpp>
  12. ls::std::boxing::Boolean::Boolean(bool _value) : ls::std::core::Class("Boolean"), value(_value)
  13. {}
  14. ls::std::boxing::Boolean::Boolean() : ls::std::core::Class("Boolean")
  15. {}
  16. ls::std::boxing::Boolean::~Boolean() noexcept = default;
  17. ls::std::boxing::Boolean &ls::std::boxing::Boolean::operator=(int _value)
  18. {
  19. this->value = _value;
  20. return *this;
  21. }
  22. ls::std::boxing::Boolean &ls::std::boxing::Boolean::operator=(bool _value)
  23. {
  24. this->value = _value;
  25. return *this;
  26. }
  27. bool ls::std::boxing::Boolean::operator&&(const ls::std::boxing::Boolean &_boolean) const
  28. {
  29. return this->value && _boolean.getValue();
  30. }
  31. bool ls::std::boxing::Boolean::operator&&(bool _value) const
  32. {
  33. return this->value && _value;
  34. }
  35. bool ls::std::boxing::Boolean::operator&&(int _value) const
  36. {
  37. return this->value && _value;
  38. }
  39. bool ls::std::boxing::Boolean::operator||(const ls::std::boxing::Boolean &_boolean) const
  40. {
  41. return this->value || _boolean.getValue();
  42. }
  43. bool ls::std::boxing::Boolean::operator||(bool _value) const
  44. {
  45. return this->value || _value;
  46. }
  47. bool ls::std::boxing::Boolean::operator||(int _value) const
  48. {
  49. return this->value || _value;
  50. }
  51. void ls::std::boxing::Boolean::parse(::std::string _parseText)
  52. {
  53. ::std::transform(_parseText.begin(), _parseText.end(), _parseText.begin(), ::tolower);
  54. if (_parseText != this->TRUE_STRING && _parseText != this->FALSE_STRING)
  55. {
  56. throw ls::std::core::IllegalArgumentException{_parseText + " is not a valid string representation"};
  57. }
  58. else
  59. {
  60. if (_parseText == this->TRUE_STRING)
  61. {
  62. this->value = true;
  63. }
  64. if (_parseText == this->FALSE_STRING)
  65. {
  66. this->value = false;
  67. }
  68. }
  69. }
  70. ::std::string ls::std::boxing::Boolean::toString()
  71. {
  72. return this->_toString();
  73. }
  74. bool ls::std::boxing::Boolean::getValue() const
  75. {
  76. return this->value;
  77. }
  78. bool ls::std::boxing::Boolean::XOR(const ls::std::boxing::Boolean &_leftExpression, const ls::std::boxing::Boolean &_rightExpression)
  79. {
  80. return (_leftExpression && !_rightExpression) || (!_leftExpression && _rightExpression.getValue());
  81. }
  82. bool ls::std::boxing::Boolean::XOR(const ls::std::boxing::Boolean &_leftExpression, bool _rightExpression)
  83. {
  84. return (_leftExpression && !_rightExpression) || (!_leftExpression && _rightExpression);
  85. }
  86. bool ls::std::boxing::Boolean::XOR(bool _leftExpression, const ls::std::boxing::Boolean &_rightExpression)
  87. {
  88. return (_leftExpression && !_rightExpression) || (!_leftExpression && _rightExpression.getValue());
  89. }
  90. bool ls::std::boxing::Boolean::XOR(bool _leftExpression, bool _rightExpression)
  91. {
  92. return (_leftExpression && !_rightExpression) || (!_leftExpression && _rightExpression);
  93. }
  94. ::std::string ls::std::boxing::Boolean::_toString() const
  95. {
  96. ::std::string booleanString{};
  97. if (this->value)
  98. {
  99. booleanString = this->TRUE_STRING;
  100. }
  101. else
  102. {
  103. booleanString = this->FALSE_STRING;
  104. }
  105. return booleanString;
  106. }