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