Boolean.cpp 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  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. 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. std::string ls_std::Boolean::_toString() const
  74. {
  75. std::string booleanString {};
  76. if(this->value) {
  77. booleanString = this->TRUE_STRING;
  78. } else {
  79. booleanString = this->FALSE_STRING;
  80. }
  81. return booleanString;
  82. }