Boolean.hpp 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  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. #ifndef BOOLEAN_HPP
  10. #define BOOLEAN_HPP
  11. #include "../base/Class.hpp"
  12. #include "IBoxing.hpp"
  13. namespace ls_std {
  14. class Boolean : public Class, IBoxing {
  15. public:
  16. explicit Boolean(bool _value);
  17. Boolean();
  18. ~Boolean() = default;
  19. // conversion operator
  20. operator bool() const;
  21. // assignment operators
  22. Boolean& operator=(int _value);
  23. Boolean& operator=(bool _value);
  24. // stream operators
  25. friend std::ostream& operator<<(std::ostream& _outputStream, const Boolean& _boolean) {
  26. _outputStream << _boolean._toString();
  27. return _outputStream;
  28. }
  29. // logical operators
  30. friend bool operator!(const Boolean& _boolean) {
  31. return !_boolean.value;
  32. }
  33. bool operator&&(const Boolean& _boolean) const;
  34. bool operator&&(bool _value) const;
  35. bool operator&&(int _value) const;
  36. bool operator||(const Boolean& _boolean) const;
  37. bool operator||(bool _value) const;
  38. bool operator||(int _value) const;
  39. // INFO: operator ^ can not be taken for XOR, since it's not possible to implement it respecting commutative law
  40. // implementation
  41. void parse(std::string _parseText) override;
  42. std::string toString() override;
  43. // additional functionality
  44. bool getValue();
  45. static bool XOR(const Boolean& _leftExpression, const Boolean& _rightExpression);
  46. static bool XOR(const Boolean& _leftExpression, bool _rightExpression);
  47. static bool XOR(bool _leftExpression, const Boolean& _rightExpression);
  48. static bool XOR(bool _leftExpression, bool _rightExpression);
  49. private:
  50. bool value {};
  51. const std::string TRUE_STRING = "true";
  52. const std::string FALSE_STRING = "false";
  53. std::string _toString() const;
  54. };
  55. }
  56. #endif