Boolean.hpp 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. /*
  2. * Author: Patrick-Christopher Mattulat
  3. * Company: Lynar Studios
  4. * E-Mail: webmaster@lynarstudios.com
  5. * Created: 2020-08-09
  6. * Changed: 2021-07-08
  7. *
  8. * */
  9. #ifndef LS_STD_BOOLEAN_HPP
  10. #define LS_STD_BOOLEAN_HPP
  11. #include <memory>
  12. #include <ls_std/base/Class.hpp>
  13. #include "IBoxing.hpp"
  14. namespace ls_std
  15. {
  16. class Boolean : public ls_std::Class, public ls_std::IBoxing
  17. {
  18. public:
  19. explicit Boolean(bool _value);
  20. Boolean();
  21. ~Boolean() override = default;
  22. // conversion operator
  23. operator bool() const;
  24. // assignment operators
  25. ls_std::Boolean &operator=(int _value);
  26. ls_std::Boolean &operator=(bool _value);
  27. // stream operators
  28. friend std::ostream &operator<<(std::ostream &_outputStream, const ls_std::Boolean &_boolean)
  29. {
  30. _outputStream << _boolean._toString();
  31. return _outputStream;
  32. }
  33. // logical operators
  34. friend bool operator!(const ls_std::Boolean &_boolean)
  35. {
  36. return !_boolean.value;
  37. }
  38. bool operator&&(const ls_std::Boolean &_boolean) const;
  39. bool operator&&(bool _value) const;
  40. bool operator&&(int _value) const;
  41. bool operator||(const ls_std::Boolean &_boolean) const;
  42. bool operator||(bool _value) const;
  43. bool operator||(int _value) const;
  44. // INFO: operator ^ can not be taken for XOR, since it's not possible to implement it respecting commutative law
  45. // implementation
  46. void parse(std::string _parseText) override;
  47. std::string toString() override;
  48. // additional functionality
  49. bool getValue() const;
  50. static bool XOR(const ls_std::Boolean &_leftExpression, const ls_std::Boolean &_rightExpression);
  51. static bool XOR(const ls_std::Boolean &_leftExpression, bool _rightExpression);
  52. static bool XOR(bool _leftExpression, const ls_std::Boolean &_rightExpression);
  53. static bool XOR(bool _leftExpression, bool _rightExpression);
  54. private:
  55. bool value{};
  56. const std::string FALSE_STRING = "false";
  57. const std::string TRUE_STRING = "true";
  58. std::string _toString() const;
  59. };
  60. }
  61. #endif