Boolean.cpp 2.7 KB

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