Boolean.cpp 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  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. void ls_std::Boolean::parse(std::string parseText)
  22. {
  23. std::transform(parseText.begin(), parseText.end(), parseText.begin(), ::tolower);
  24. if(parseText != this->TRUE_STRING && parseText != this->FALSE_STRING) {
  25. throw ls_std::IllegalArgumentException {};
  26. } else {
  27. if(parseText == this->TRUE_STRING) {
  28. this->value = true;
  29. }
  30. if(parseText == this->FALSE_STRING) {
  31. this->value = false;
  32. }
  33. }
  34. }
  35. std::string ls_std::Boolean::toString()
  36. {
  37. return this->_toString();
  38. }
  39. std::string ls_std::Boolean::_toString() const
  40. {
  41. std::string booleanString {};
  42. if(this->value) {
  43. booleanString = this->TRUE_STRING;
  44. } else {
  45. booleanString = this->FALSE_STRING;
  46. }
  47. return booleanString;
  48. }