Boolean.cpp 3.0 KB

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