Boolean.cpp 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  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-07
  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() = default;
  17. ls::std::boxing::Boolean::operator bool() const
  18. {
  19. return this->value;
  20. }
  21. ls::std::boxing::Boolean &ls::std::boxing::Boolean::operator=(int _value)
  22. {
  23. this->value = _value;
  24. return *this;
  25. }
  26. ls::std::boxing::Boolean &ls::std::boxing::Boolean::operator=(bool _value)
  27. {
  28. this->value = _value;
  29. return *this;
  30. }
  31. bool ls::std::boxing::Boolean::operator&&(const ls::std::boxing::Boolean &_boolean) const
  32. {
  33. return this->value && _boolean;
  34. }
  35. bool ls::std::boxing::Boolean::operator&&(bool _value) const
  36. {
  37. return this->value && _value;
  38. }
  39. bool ls::std::boxing::Boolean::operator&&(int _value) const
  40. {
  41. return this->value && _value;
  42. }
  43. bool ls::std::boxing::Boolean::operator||(const ls::std::boxing::Boolean &_boolean) const
  44. {
  45. return this->value || _boolean;
  46. }
  47. bool ls::std::boxing::Boolean::operator||(bool _value) const
  48. {
  49. return this->value || _value;
  50. }
  51. bool ls::std::boxing::Boolean::operator||(int _value) const
  52. {
  53. return this->value || _value;
  54. }
  55. void ls::std::boxing::Boolean::parse(::std::string _parseText)
  56. {
  57. ::std::transform(_parseText.begin(), _parseText.end(), _parseText.begin(), ::tolower);
  58. if (_parseText != this->TRUE_STRING && _parseText != this->FALSE_STRING)
  59. {
  60. throw ls::std::core::IllegalArgumentException{_parseText + " is not a valid string representation"};
  61. }
  62. else
  63. {
  64. if (_parseText == this->TRUE_STRING)
  65. {
  66. this->value = true;
  67. }
  68. if (_parseText == this->FALSE_STRING)
  69. {
  70. this->value = false;
  71. }
  72. }
  73. }
  74. ::std::string ls::std::boxing::Boolean::toString()
  75. {
  76. return this->_toString();
  77. }
  78. bool ls::std::boxing::Boolean::getValue() const
  79. {
  80. return this->value;
  81. }
  82. bool ls::std::boxing::Boolean::XOR(const ls::std::boxing::Boolean &_leftExpression, const ls::std::boxing::Boolean &_rightExpression)
  83. {
  84. return (_leftExpression && !_rightExpression) || (!_leftExpression && _rightExpression);
  85. }
  86. bool ls::std::boxing::Boolean::XOR(const ls::std::boxing::Boolean &_leftExpression, bool _rightExpression)
  87. {
  88. return (_leftExpression && !_rightExpression) || (!_leftExpression && _rightExpression);
  89. }
  90. bool ls::std::boxing::Boolean::XOR(bool _leftExpression, const ls::std::boxing::Boolean &_rightExpression)
  91. {
  92. return (_leftExpression && !_rightExpression) || (!_leftExpression && _rightExpression);
  93. }
  94. bool ls::std::boxing::Boolean::XOR(bool _leftExpression, bool _rightExpression)
  95. {
  96. return (_leftExpression && !_rightExpression) || (!_leftExpression && _rightExpression);
  97. }
  98. ::std::string ls::std::boxing::Boolean::_toString() const
  99. {
  100. ::std::string booleanString{};
  101. if (this->value)
  102. {
  103. booleanString = this->TRUE_STRING;
  104. }
  105. else
  106. {
  107. booleanString = this->FALSE_STRING;
  108. }
  109. return booleanString;
  110. }