Boolean.cpp 3.1 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: 2022-05-20
  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() : ls::std::core::Class("Boolean")
  13. {}
  14. ls::std::boxing::Boolean::Boolean(bool _value)
  15. : ls::std::core::Class("Boolean"),
  16. value(_value)
  17. {}
  18. ls::std::boxing::Boolean::operator bool() const
  19. {
  20. return this->value;
  21. }
  22. ls::std::boxing::Boolean &ls::std::boxing::Boolean::operator=(int _value)
  23. {
  24. this->value = _value;
  25. return *this;
  26. }
  27. ls::std::boxing::Boolean &ls::std::boxing::Boolean::operator=(bool _value)
  28. {
  29. this->value = _value;
  30. return *this;
  31. }
  32. bool ls::std::boxing::Boolean::operator&&(const ls::std::boxing::Boolean &_boolean) const
  33. {
  34. return this->value && _boolean;
  35. }
  36. bool ls::std::boxing::Boolean::operator&&(bool _value) const
  37. {
  38. return this->value && _value;
  39. }
  40. bool ls::std::boxing::Boolean::operator&&(int _value) const
  41. {
  42. return this->value && _value;
  43. }
  44. bool ls::std::boxing::Boolean::operator||(const ls::std::boxing::Boolean &_boolean) const
  45. {
  46. return this->value || _boolean;
  47. }
  48. bool ls::std::boxing::Boolean::operator||(bool _value) const
  49. {
  50. return this->value || _value;
  51. }
  52. bool ls::std::boxing::Boolean::operator||(int _value) const
  53. {
  54. return this->value || _value;
  55. }
  56. void ls::std::boxing::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::core::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::boxing::Boolean::toString()
  76. {
  77. return this->_toString();
  78. }
  79. bool ls::std::boxing::Boolean::getValue() const
  80. {
  81. return this->value;
  82. }
  83. bool ls::std::boxing::Boolean::XOR(const ls::std::boxing::Boolean &_leftExpression, const ls::std::boxing::Boolean &_rightExpression)
  84. {
  85. return (_leftExpression && !_rightExpression) || (!_leftExpression && _rightExpression);
  86. }
  87. bool ls::std::boxing::Boolean::XOR(const ls::std::boxing::Boolean &_leftExpression, bool _rightExpression)
  88. {
  89. return (_leftExpression && !_rightExpression) || (!_leftExpression && _rightExpression);
  90. }
  91. bool ls::std::boxing::Boolean::XOR(bool _leftExpression, const ls::std::boxing::Boolean &_rightExpression)
  92. {
  93. return (_leftExpression && !_rightExpression) || (!_leftExpression && _rightExpression);
  94. }
  95. bool ls::std::boxing::Boolean::XOR(bool _leftExpression, bool _rightExpression)
  96. {
  97. return (_leftExpression && !_rightExpression) || (!_leftExpression && _rightExpression);
  98. }
  99. ::std::string ls::std::boxing::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. }