Boolean.cpp 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  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-09
  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. bool ls_std::Boolean::operator&&(const Boolean &_boolean) const
  22. {
  23. return this->value && _boolean;
  24. }
  25. bool ls_std::Boolean::operator&&(bool _value) const
  26. {
  27. return this->value && _value;
  28. }
  29. bool ls_std::Boolean::operator&&(int _value) const
  30. {
  31. return this->value && _value;
  32. }
  33. bool ls_std::Boolean::operator||(const Boolean &_boolean) const
  34. {
  35. return this->value || _boolean;
  36. }
  37. bool ls_std::Boolean::operator||(bool _value) const
  38. {
  39. return this->value || _value;
  40. }
  41. bool ls_std::Boolean::operator||(int _value) const
  42. {
  43. return this->value || _value;
  44. }
  45. void ls_std::Boolean::parse(std::string parseText)
  46. {
  47. std::transform(parseText.begin(), parseText.end(), parseText.begin(), ::tolower);
  48. if(parseText != this->TRUE_STRING && parseText != this->FALSE_STRING) {
  49. throw ls_std::IllegalArgumentException {};
  50. } else {
  51. if(parseText == this->TRUE_STRING) {
  52. this->value = true;
  53. }
  54. if(parseText == this->FALSE_STRING) {
  55. this->value = false;
  56. }
  57. }
  58. }
  59. std::string ls_std::Boolean::toString()
  60. {
  61. return this->_toString();
  62. }
  63. std::string ls_std::Boolean::_toString() const
  64. {
  65. std::string booleanString {};
  66. if(this->value) {
  67. booleanString = this->TRUE_STRING;
  68. } else {
  69. booleanString = this->FALSE_STRING;
  70. }
  71. return booleanString;
  72. }